Skip to content

Commit 55e608d

Browse files
core/vm: fixed nil panics in accessListTracer
1 parent f22ae38 commit 55e608d

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

core/vm/access_list_tracer.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,21 @@ import (
2222

2323
"github.com/ethereum/go-ethereum/common"
2424
"github.com/ethereum/go-ethereum/core/types"
25+
"github.com/ethereum/go-ethereum/log"
2526
)
2627

2728
type accessList struct {
2829
addresses map[common.Address]int
2930
slots []map[common.Hash]struct{}
3031
}
3132

33+
// newAccessList creates a new accessList.
34+
func newAccessList() *accessList {
35+
return &accessList{
36+
addresses: make(map[common.Address]int),
37+
}
38+
}
39+
3240
func (al *accessList) AddAddress(address common.Address) {
3341
// Set address if not previously present
3442
if _, present := al.addresses[address]; !present {
@@ -61,7 +69,7 @@ func (al *accessList) DeleteAddressIfNoSlotSet(address common.Address) {
6169

6270
// Copy creates an independent copy of an accessList.
6371
func (a *accessList) Copy() *accessList {
64-
cp := new(accessList)
72+
cp := newAccessList()
6573
for k, v := range a.addresses {
6674
cp.addresses[k] = v
6775
}
@@ -82,7 +90,7 @@ func (a *accessList) ToAccessList() *types.AccessList {
8290
var tuple types.AccessTuple
8391
tuple.Address = addr
8492
// addresses without slots are saved as -1
85-
if idx > 0 {
93+
if idx >= 0 {
8694
keys := make([]common.Hash, 0, len(a.slots[idx]))
8795
for key := range a.slots[idx] {
8896
keys = append(keys, key)
@@ -96,14 +104,15 @@ func (a *accessList) ToAccessList() *types.AccessList {
96104
}
97105

98106
type AccessListTracer struct {
99-
list accessList
100-
err error
107+
list *accessList
101108
}
102109

103110
func (a *AccessListTracer) CaptureStart(env *EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
111+
a.list = newAccessList()
104112
}
105113

106114
func (a *AccessListTracer) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, scope *ScopeContext, rData []byte, depth int, err error) {
115+
log.Trace("Capturing State", "op", op)
107116
stack := scope.Stack
108117
if (op == SLOAD || op == SSTORE) && stack.len() >= 1 {
109118
slot := common.Hash(stack.data[stack.len()-1].Bytes32())

eth/api_backend.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/ethereum/go-ethereum/ethdb"
3737
"github.com/ethereum/go-ethereum/event"
3838
"github.com/ethereum/go-ethereum/internal/ethapi"
39+
"github.com/ethereum/go-ethereum/log"
3940
"github.com/ethereum/go-ethereum/miner"
4041
"github.com/ethereum/go-ethereum/params"
4142
"github.com/ethereum/go-ethereum/rpc"
@@ -355,13 +356,16 @@ func (b *EthAPIBackend) AccessList(ctx context.Context, block *types.Block, reex
355356
if err != nil {
356357
return nil, err
357358
}
358-
args.SetDefaults(ctx, b)
359+
if err := args.SetDefaults(ctx, b); err != nil {
360+
return nil, err
361+
}
359362
var (
360363
gas uint64
361364
accessList = args.AccessList
362365
msg types.Message
363366
)
364367
for i := 0; i < 10; i++ {
368+
log.Trace("Creating Access list", "accesslist", accessList)
365369
// Copy the original db so we don't modify it
366370
statedb := db.Copy()
367371
// If we have an accesslist, use it
@@ -373,7 +377,7 @@ func (b *EthAPIBackend) AccessList(ctx context.Context, block *types.Block, reex
373377
// Apply the transaction
374378
context := core.NewEVMBlockContext(block.Header(), b.eth.blockchain, nil)
375379
tracer := new(vm.AccessListTracer)
376-
config := vm.Config{Tracer: tracer}
380+
config := vm.Config{Tracer: tracer, Debug: true}
377381
vmenv := vm.NewEVM(context, core.NewEVMTxContext(msg), statedb, b.eth.blockchain.Config(), config)
378382
res, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas()))
379383
if err != nil {

0 commit comments

Comments
 (0)