Skip to content

Commit

Permalink
Add tests for stack validation with non-constant stack
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Aug 11, 2023
1 parent 5136e2f commit cd39111
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/unittests/eof_validation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,3 +1303,26 @@ TEST(eof_validation, dataloadn)
"00000000000000001111111111111111222222222222222233333333333333"),
EOFValidationError::invalid_dataloadn_index);
}

TEST(eof_validation, non_constant_stack_height)
{
// Final "OP_PUSH0 + OP_PUSH0 + OP_REVERT" can be reached with stack heights: 0, 2 or 1
auto code = eof1_bytecode(rjumpi(7, OP_PUSH0) + OP_PUSH0 + OP_PUSH0 + rjumpi(1, OP_PUSH0) +
OP_POP + OP_PUSH0 + OP_PUSH0 + OP_REVERT,
4);
EXPECT_EQ(validate_eof(code), EOFValidationError::success);

// Final "OP_POP + OP_PUSH0 + OP_PUSH0 + OP_REVERT" can be reached with stack heights: 1, 3 or 2
code = eof1_bytecode(OP_PUSH0 + rjumpi(7, OP_PUSH0) + OP_PUSH0 + OP_PUSH0 +
rjumpi(1, OP_PUSH0) + OP_POP + OP_PUSH0 + OP_PUSH0 + OP_REVERT,
5);

EXPECT_EQ(validate_eof(code), EOFValidationError::success);

// Final "OP_POP + OP_POP + OP_PUSH0 + OP_PUSH0 + OP_REVERT" can be reached with stack heights:
// 0, 2 or 1. Stack underflow when height is 0.
code = eof1_bytecode(rjumpi(7, OP_PUSH0) + OP_PUSH0 + OP_PUSH0 + rjumpi(1, OP_PUSH0) + OP_POP +
OP_POP + OP_PUSH0 + OP_PUSH0 + OP_REVERT,
4);
EXPECT_EQ(validate_eof(code), EOFValidationError::stack_underflow);
}

0 comments on commit cd39111

Please sign in to comment.