Skip to content

Commit

Permalink
evm: check JUMPDEST only before real jump in JUMPI
Browse files Browse the repository at this point in the history
  • Loading branch information
cdump committed Dec 19, 2023
1 parent 81c6b1f commit 231c994
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions evmole/evm/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ def _exec_opcode(self, op: OpCode) -> tuple[int, *tuple[Any, ...]]:

case op if op in {Op.JUMP, Op.JUMPI}:
s0 = self.stack.pop_uint()
if s0 >= len(self.code) or self.code[s0] != Op.JUMPDEST:
raise BadJumpDestError(f'pos {s0}')
if op == Op.JUMPI:
s1 = self.stack.pop_uint()
if s1 == 0:
self.pc += 1
return (10,)
if s0 >= len(self.code) or self.code[s0] != Op.JUMPDEST:
raise BadJumpDestError(f'pos {s0}')
self.pc = s0
return (8 if op == Op.JUMP else 10,)

Expand Down
8 changes: 4 additions & 4 deletions js/src/evm/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ export class Vm {
case Op.JUMP:
case Op.JUMPI: {
const s0 = Number(this.stack.pop_uint())
if (s0 >= this.code.length || this.code[s0] != Op.JUMPDEST) {
throw new BadJumpDestError(`pos ${s0}`)
}
if (op == Op.JUMPI) {
const s1 = this.stack.pop_uint()
if (s1 == 0n) {
this.pc += 1
return [10]
}
}
this.pc = Number(s0)
if (s0 >= this.code.length || this.code[s0] != Op.JUMPDEST) {
throw new BadJumpDestError(`pos ${s0}`)
}
this.pc = s0
return [op === Op.JUMP ? 8 : 10]
}

Expand Down

0 comments on commit 231c994

Please sign in to comment.