Skip to content

Commit

Permalink
Make GetOp take offset inside code and use it for validJumpdest
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Nov 8, 2022
1 parent 933c304 commit 4913c1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions core/vm/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func NewContract(caller ContractRef, object ContractRef, value *big.Int, gas uin
return c
}

// validJumpdest returns true if destination offset is inside code bounds and is JUMPDEST opcode
// dest is offset inside code section in case of EOF contract
func (c *Contract) validJumpdest(dest *uint256.Int) bool {
udest, overflow := dest.Uint64WithOverflow()
// PC cannot go beyond len(code) and certainly can't be bigger than 63bits.
Expand All @@ -92,7 +94,7 @@ func (c *Contract) validJumpdest(dest *uint256.Int) bool {
return false
}
// Only JUMPDESTs allowed for destinations
if OpCode(c.Code[c.CodeBeginOffset()+udest]) != JUMPDEST {
if c.GetOp(udest) != JUMPDEST {
return false
}
return c.isCode(udest)
Expand Down Expand Up @@ -144,9 +146,10 @@ func (c *Contract) AsDelegate() *Contract {
}

// GetOp returns the n'th element in the contract's byte array
// n is offset inside code section in case of EOF contract
func (c *Contract) GetOp(n uint64) OpCode {
if n < c.CodeEndOffset() {
return OpCode(c.Code[n])
if n < c.CodeSize() {
return OpCode(c.Code[c.CodeBeginOffset()+n])
}

return STOP
Expand Down
2 changes: 1 addition & 1 deletion core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
}
// Get the operation from the jump table and validate the stack to ensure there are
// enough stack items available to perform the operation.
op = contract.GetOp(contract.CodeBeginOffset() + pc)
op = contract.GetOp(pc)
operation := in.cfg.JumpTable[op]
cost = operation.constantGas // For tracing
// Validate stack
Expand Down

0 comments on commit 4913c1d

Please sign in to comment.