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 Sep 1, 2023
1 parent b89e298 commit 6de389a
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 @@ -1397,3 +1397,26 @@ TEST(eof_validation, callf_stack_validation)
"E3000100 5FE30002E4 50E4"),
EOFValidationError::stack_underflow);
}

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 6de389a

Please sign in to comment.