Skip to content

Commit 4913c1d

Browse files
committed
Make GetOp take offset inside code and use it for validJumpdest
1 parent 933c304 commit 4913c1d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

core/vm/contract.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ func NewContract(caller ContractRef, object ContractRef, value *big.Int, gas uin
8484
return c
8585
}
8686

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

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

152155
return STOP

core/vm/interpreter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
178178
}
179179
// Get the operation from the jump table and validate the stack to ensure there are
180180
// enough stack items available to perform the operation.
181-
op = contract.GetOp(contract.CodeBeginOffset() + pc)
181+
op = contract.GetOp(pc)
182182
operation := in.cfg.JumpTable[op]
183183
cost = operation.constantGas // For tracing
184184
// Validate stack

0 commit comments

Comments
 (0)