mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
eth/tracers/native: guard agains stack underflow in keccak256PreimageTracer
This commit is contained in:
parent
4520ec0e71
commit
cf80c3754a
2 changed files with 10 additions and 6 deletions
|
|
@ -55,8 +55,14 @@ func newKeccak256preimageTracer(ctx *tracers.Context, cfg json.RawMessage, chain
|
|||
|
||||
func (t *keccak256preimageTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
|
||||
if op == byte(vm.KECCAK256) {
|
||||
dataOffset := peepStack(scope.StackData(), 0).Uint64()
|
||||
dataLength := peepStack(scope.StackData(), 1).Uint64()
|
||||
sd := scope.StackData()
|
||||
// it turns out that sometimes the stack is empty, evm will fail in this case, but we should not panic here
|
||||
if len(sd) < 2 {
|
||||
return
|
||||
}
|
||||
|
||||
dataOffset := peepStack(sd, 0).Uint64()
|
||||
dataLength := peepStack(sd, 1).Uint64()
|
||||
preimage, err := internal.GetMemoryCopyPadded(scope.MemoryData(), int64(dataOffset), int64(dataLength))
|
||||
if err != nil {
|
||||
log.Warn("erc7562Tracer: failed to copy keccak preimage from memory", "err", err)
|
||||
|
|
|
|||
|
|
@ -397,10 +397,8 @@ func TestKeccak256PreimageTracerInsufficientStack(t *testing.T) {
|
|||
stack: stack,
|
||||
}
|
||||
|
||||
// This should panic due to insufficient stack, but we're testing it doesn't crash the test
|
||||
require.Panics(t, func() {
|
||||
// This should not panic due to insufficient stack
|
||||
tracer.OnOpcode(0, byte(vm.KECCAK256), 0, 0, mockScope, nil, 0, nil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestKeccak256PreimageTracerLargeData(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue