Skip to content

Commit e5291ef

Browse files
fix potential index out of range bugs in opDataHash (#16)
1 parent fce14ba commit e5291ef

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

core/vm/eips.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ func enableSharding(jt *JumpTable) {
206206

207207
// opDataHash implements DATAHASH opcode
208208
func opDataHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
209-
idx := scope.Stack.pop()
210-
if uint64(len(interpreter.evm.TxContext.DataHashes)) < idx.Uint64() {
211-
scope.Stack.push(uint256.NewInt(0))
212-
} else {
209+
idx := scope.Stack.peek()
210+
if idx.LtUint64(uint64(len(interpreter.evm.TxContext.DataHashes))) {
213211
hash := interpreter.evm.TxContext.DataHashes[idx.Uint64()]
214-
scope.Stack.push(new(uint256.Int).SetBytes(hash.Bytes()))
212+
idx.SetBytes(hash.Bytes())
213+
} else {
214+
idx.Clear()
215215
}
216216
return nil, nil
217217
}

0 commit comments

Comments
 (0)