From 8fa55e19cec3945e4da25acd0e3c23906ba0fe77 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 28 Jul 2021 14:21:35 +0200 Subject: [PATCH] internal/ethapi: fix panic in accesslist creation (#23225) * internal/ethapi: revert + fix properly in al tracer * internal/ethapi: use toMessage instead of creating new message * internal/ethapi: remove ineffassign * core: fix invalid unmarshalling, fix test Co-authored-by: Martin Holst Swende --- core/vm/access_list_tracer.go | 2 +- ethclient/gethclient/gethclient_test.go | 2 +- internal/ethapi/api.go | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/vm/access_list_tracer.go b/core/vm/access_list_tracer.go index b5bc961c84376..cc5461d1c3104 100644 --- a/core/vm/access_list_tracer.go +++ b/core/vm/access_list_tracer.go @@ -96,7 +96,7 @@ func (al accessList) equal(other accessList) bool { func (al accessList) accessList() types.AccessList { acl := make(types.AccessList, 0, len(al)) for addr, slots := range al { - tuple := types.AccessTuple{Address: addr} + tuple := types.AccessTuple{Address: addr, StorageKeys: []common.Hash{}} for slot := range slots { tuple.StorageKeys = append(tuple.StorageKeys, slot) } diff --git a/ethclient/gethclient/gethclient_test.go b/ethclient/gethclient/gethclient_test.go index 3c408c22593e8..c0b9d0c2d0993 100644 --- a/ethclient/gethclient/gethclient_test.go +++ b/ethclient/gethclient/gethclient_test.go @@ -138,7 +138,7 @@ func testAccessList(t *testing.T, client *rpc.Client) { From: testAddr, To: &common.Address{}, Gas: 21000, - GasPrice: big.NewInt(1), + GasPrice: big.NewInt(765625000), Value: big.NewInt(1), } al, gas, vmErr, err := ec.CreateAccessList(context.Background(), msg) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 59555ea463072..826934a9c1bde 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1441,7 +1441,12 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH } // Copy the original db so we don't modify it statedb := db.Copy() - msg := types.NewMessage(args.from(), args.To, uint64(*args.Nonce), args.Value.ToInt(), uint64(*args.Gas), args.GasPrice.ToInt(), big.NewInt(0), big.NewInt(0), args.data(), accessList, false) + // Set the accesslist to the last al + args.AccessList = &accessList + msg, err := args.ToMessage(b.RPCGasCap(), header.BaseFee) + if err != nil { + return nil, 0, nil, err + } // Apply the transaction with the access list tracer tracer := vm.NewAccessListTracer(accessList, args.from(), to, precompiles)