Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-5450 test vectors #1114

Open
gumb0 opened this issue Dec 9, 2022 · 0 comments
Open

EIP-5450 test vectors #1114

gumb0 opened this issue Dec 9, 2022 · 0 comments

Comments

@gumb0
Copy link
Member

gumb0 commented Dec 9, 2022

Validation

Valid cases

  • Branches having same stack height
    • PUSH1 0 RJUMPI label_true PUSH1 1 PUSH1 2 RJUMP exit label_true: PUSH1 3 PUSH1 4 exit: STOP
    • Calls returning same output numbers
      • function types are [(0, 0), (0, 1), (0, 1)]
        PUSH1 0 RJUMPI label_true label_false: CALLF 1 RJUMP exit label_true: CALLF 2 exit: STOP
    • Infinite loop
      • start: PUSH1 0 PUSH1 1 POP POP RJUMP start
    • Jump table
      • PUSH1 0 RJUMPV 2 case1 case2 PUSH1 01 PUSH1 02 RJUMP exit case1: PUSH1 03 PUSH1 04 RJUMP exit case2: PUSH1 05 PUSH1 06 exit: STOP
  • Check that all instructions pass validation with the right number of input stack items
    • PUSH1 0 PUSH1 0 ADD STOP
    • PUSH1 0 PUSH1 MUL STOP
    • All other instructions taking inputs from stack
    • CALLF
      • function types are [(0, 0), (1, 0), (2, 0), (255, 0)]
      • CALLF 0 STOP
      • PUSH1 0 CALLF 1 STOP
      • PUSH1 2 CALLF 2 STOP
      • PUSH1 0 * 255 + CALLF 3 STOP
    • JUMPF
      • function types are [(0, 0), (1, 0), (2, 0), (255, 0)]
      • JUMPF 0
      • PUSH1 0 JUMPF 1
      • PUSH1 0 PUSH1 0 PUSH1 0 JUMPF 1 # 2 extra items
      • PUSH1 0 PUSH1 0 JUMPF 2
      • PUSH1 0 PUSH1 0 PUSH1 0 PUSH1 0 JUMPF 2 # 2 extra items
      • PUSH1 0 * 255 + JUMPF 3 STOP
      • PUSH1 0 * 512 + JUMPF 3 STOP
      • PUSH1 0 * 1024 + JUMPF 3 STOP
  • Terminating instruction
    • PUSH1 0 POP STOP
    • other terminating instructions
    • loop ending with unconditional jump
      • start: RJUMP start
      • PUSH1 10 start: PUSH1 1 SWAP1 SUB RJUMPI end STOP end: RJUMP start
    • function types are [(0, 0), (1, 1), (0, 2)]
      • function 0: PUSH1 0 JUMPF 1
      • function 1: RETF
      • function 2: PUSH1 0 PUSH2 0 RETF
  • Stack not required to be clean on terminating instruction
    • PUSH1 0 PUSH1 0 PUSH1 0 STOP
    • other terminating instruction
    • function types are [(0, 0), (1, 1), (0, 2)]
      • function 0: PUSH1 0 PUSH1 0 JUMPF 1
      • function 1: PUSH1 0 PUSH1 0 PUSH1 0 RETF
      • function 2: PUSH1 0 PUSH2 0 PUSH1 0 PUSH1 0 RETF
    • function types are [(0, 0), (0, 255)]
      • function 1: PUSH1 0 * 512 + RETF

Invalid cases

  • Stack height mismatch for different paths
    • Branches pushing different number of items
      • PUSH1 0 RJUMPI label_true PUSH1 1 label_true: PUSH1 2 STOP
      • PUSH1 0 RJUMPI label_true label_false: PUSH1 1 RJUMP exit label_true: PUSH1 2 PUSH1 3 exit: STOP
      • Calls returning different output numbers
        • function types are [(0, 0), (0, 1), (0, 2)]
          PUSH1 0 RJUMPI label_true label_false: CALLF 1 RJUMP exit label_true: CALLF 2 exit: STOP
    • Pushing loop
      • start: PUSH1 0 RJUMP start
    • Popping loop
      -PUSH1 0 PUSH1 0 PUSH1 0 start: POP RJUMP start
    • Jump table with different stack heights
      • PUSH1 0 RJUMPV 2 case1 case2 PUSH1 01 RJUMP exit case1: PUSH1 02 PUSH1 03 RJUMP exit case2: PUSH1 03 PUSH1 04 PUSH1 05 exit: STOP
  • Stack underflow
    • ADD STOP
    • PUSH1 0 ADD STOP
    • Check all other isntructions handle underflow correctly
    • CALLF
      • function types are [(0, 0), (1, 0), (2, 0)]
        • CALLF 1 STOP
        • PUSH1 0 CALLF 2 STOP
    • JUMPF
      • function types are [(0, 0), (1, 0), (2, 0)]
        • JUMPF 1
        • PUSH1 0 JUMPF 2
  • Stack overflow
    • Function pushing 1024 values
  • No terminating instruction
    • PUSH1 0
    • PUSH1 0 RJUMPI exit STOP exit: NOP
    • PUSH1 0 RJUMPV 2 case1 case2 INVALID case1: STOP case2: NOP
  • Unreachable code
    • STOP PUSH1 0 STOP
    • STOP STOP
    • INVALID STOP
    • starting with other terminating instructions
    • RJUMP start PUSH1 0 start: PUSH1 0 STOP
    • start: RJUMP start STOP

Execution

  • Check that CALLF fails if callee's max_stack_height overflows the stack
    • function types are [(0, 0), (1, 0)]
      • function 0: PUSH1 0 CALLF 1 STOP
      • function 1: POP + PUSH1 0 * 1024 + POP * 1024 + RETF # should be valid by itself, but make function 0 invalid
    • function types are [(0, 0), (0, 0)]
      • function 0: PUSH1 0 * 1024 CALLF 1 STOP` # should be valid by itself, but but invalid if function 1 pushes
      • function 1: PUSH1 0 RETF
    • a case when callee has some branch that wouldn't overflow stack by itself
      function types are [(0, 0), (2, 0)]
      • function 0: PUSH1 0 PUSH1 0 CALLF 1 STOP
      • function 1: POP RJUMPI exit + PUSH1 0* 1024 +POP* 1024 +exit: RETF` # should be valid by itself, but make function 0 invalid
  • Check gas price of JUMPF
  • Check that stack handling is correct around JUMPF
    • function types are [(0, 0), (1, 0), (1, 0)]
      • function 0: PUSH1 1 PUSH1 2 PUSH1 3 CALLF 1 ADD PUSH1 0 SSTORE STOP, check that sstored result is 3
      • function 1: POP PUSH1 11 PUSH1 12 PUSH1 13 JUMPF 2 # extra items left on stack
      • function 2: POP RETF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant