From 612d2819bbedddac567be056f5ab2ebbfe94d028 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Wed, 2 Oct 2024 21:32:05 +0700 Subject: [PATCH 1/6] internal/ethapi: set dynamic fee fields to 0 in access list so that setting NoBaseFee will disable subsequent validation --- internal/ethapi/api.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index a50295289340..8f3f378ce16a 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1631,6 +1631,12 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH if err := args.setDefaults(ctx, b, true); err != nil { return nil, 0, nil, err } + + // Set dynamic fee fields to 0 to avoid validation checks during execution. + // These are irrelevant to calculation of access lists and gas cost. + args.MaxFeePerGas = new(hexutil.Big) + args.MaxPriorityFeePerGas = new(hexutil.Big) + var to common.Address if args.To != nil { to = *args.To From 5fce58e5b2b4427e2a0785b90d5edef0ef4413c3 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Wed, 2 Oct 2024 22:09:07 +0700 Subject: [PATCH 2/6] try using CallDefaults instead of setDefaults (AccessList is an eth_call-like operation) --- internal/ethapi/api.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 8f3f378ce16a..2025d47b8861 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1627,15 +1627,8 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH return nil, 0, nil, err } - // Ensure any missing fields are filled, extract the recipient and input data - if err := args.setDefaults(ctx, b, true); err != nil { - return nil, 0, nil, err - } - - // Set dynamic fee fields to 0 to avoid validation checks during execution. - // These are irrelevant to calculation of access lists and gas cost. - args.MaxFeePerGas = new(hexutil.Big) - args.MaxPriorityFeePerGas = new(hexutil.Big) + blockCtx := core.NewEVMBlockContext(header, NewChainContext(ctx, b), nil) + args.CallDefaults(b.RPCGasCap(), blockCtx.BaseFee, b.ChainConfig().ChainID) var to common.Address if args.To != nil { From 6d3b00013a889b763836072a6613420fea09c7f4 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 8 Oct 2024 16:30:00 +0700 Subject: [PATCH 3/6] check error from CallDefaults. if tx nonce was not provided, fill it from the db --- internal/ethapi/api.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 2025d47b8861..0630fe1f03bb 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1627,8 +1627,14 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH return nil, 0, nil, err } + if args.Nonce == nil { + nonce := hexutil.Uint64(db.GetNonce(args.from())) + args.Nonce = &nonce + } blockCtx := core.NewEVMBlockContext(header, NewChainContext(ctx, b), nil) - args.CallDefaults(b.RPCGasCap(), blockCtx.BaseFee, b.ChainConfig().ChainID) + if err := args.CallDefaults(b.RPCGasCap(), blockCtx.BaseFee, b.ChainConfig().ChainID); err != nil { + return types.AccessList{}, 0, nil, err + } var to common.Address if args.To != nil { @@ -1636,6 +1642,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH } else { to = crypto.CreateAddress(args.from(), uint64(*args.Nonce)) } + fmt.Printf("nonce %d\nto %x\n", *args.Nonce, to) isPostMerge := header.Difficulty.Sign() == 0 // Retrieve the precompiles since they don't need to be added to the access list precompiles := vm.ActivePrecompiles(b.ChainConfig().Rules(header.Number, isPostMerge, header.Time)) From 5b243e4b42bf100d3b71d19868d5bc6a7107ae24 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 8 Oct 2024 19:17:26 +0700 Subject: [PATCH 4/6] remove print statement --- internal/ethapi/api.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 0630fe1f03bb..e5b36fdd711c 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1642,7 +1642,6 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH } else { to = crypto.CreateAddress(args.from(), uint64(*args.Nonce)) } - fmt.Printf("nonce %d\nto %x\n", *args.Nonce, to) isPostMerge := header.Difficulty.Sign() == 0 // Retrieve the precompiles since they don't need to be added to the access list precompiles := vm.ActivePrecompiles(b.ChainConfig().Rules(header.Number, isPostMerge, header.Time)) From 599fdedadc88acece83df507dfead81858456b3d Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 8 Oct 2024 19:25:26 +0700 Subject: [PATCH 5/6] docs --- internal/ethapi/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index e5b36fdd711c..791bc40191e6 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1627,6 +1627,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH return nil, 0, nil, err } + // fill in missing fields based on the state at the specified block if args.Nonce == nil { nonce := hexutil.Uint64(db.GetNonce(args.from())) args.Nonce = &nonce @@ -1635,7 +1636,6 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH if err := args.CallDefaults(b.RPCGasCap(), blockCtx.BaseFee, b.ChainConfig().ChainID); err != nil { return types.AccessList{}, 0, nil, err } - var to common.Address if args.To != nil { to = *args.To From 78897ffaf0636e393d1ad0ff4ac4a412c5408186 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Wed, 9 Oct 2024 18:01:50 +0700 Subject: [PATCH 6/6] ensure AccessList calls setFeeDefaults so that fee fields are filled with proper values. modify setFeeDefaults to take a historical header value (doesn't work if EIP-1559 is disabled. everything other than AccessLists, which were introduced after/same-time (?) as 1559, calls setFeeDefaults with current block header. --- internal/ethapi/api.go | 10 +++++++--- internal/ethapi/transaction_args.go | 5 ++--- internal/ethapi/transaction_args_test.go | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 791bc40191e6..dc4a2c6f0915 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1627,15 +1627,19 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH return nil, 0, nil, err } - // fill in missing fields based on the state at the specified block + // Ensure any missing fields are filled, extract the recipient and input data + if err = args.setFeeDefaults(ctx, b, header); err != nil { + return nil, 0, nil, err + } if args.Nonce == nil { nonce := hexutil.Uint64(db.GetNonce(args.from())) args.Nonce = &nonce } blockCtx := core.NewEVMBlockContext(header, NewChainContext(ctx, b), nil) - if err := args.CallDefaults(b.RPCGasCap(), blockCtx.BaseFee, b.ChainConfig().ChainID); err != nil { - return types.AccessList{}, 0, nil, err + if err = args.CallDefaults(b.RPCGasCap(), blockCtx.BaseFee, b.ChainConfig().ChainID); err != nil { + return nil, 0, nil, err } + var to common.Address if args.To != nil { to = *args.To diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index f9835a96dabf..56d887c1e307 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -100,7 +100,7 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, skipGas if err := args.setBlobTxSidecar(ctx); err != nil { return err } - if err := args.setFeeDefaults(ctx, b); err != nil { + if err := args.setFeeDefaults(ctx, b, b.CurrentHeader()); err != nil { return err } @@ -183,8 +183,7 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, skipGas } // setFeeDefaults fills in default fee values for unspecified tx fields. -func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) error { - head := b.CurrentHeader() +func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend, head *types.Header) error { // Sanity check the EIP-4844 fee parameters. if args.BlobFeeCap != nil && args.BlobFeeCap.ToInt().Sign() == 0 { return errors.New("maxFeePerBlobGas, if specified, must be non-zero") diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index 531782817328..78fe22185cc5 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -238,7 +238,7 @@ func TestSetFeeDefaults(t *testing.T) { t.Fatalf("failed to set fork: %v", err) } got := test.in - err := got.setFeeDefaults(ctx, b) + err := got.setFeeDefaults(ctx, b, b.CurrentHeader()) if err != nil { if test.err == nil { t.Fatalf("test %d (%s): unexpected error: %s", i, test.name, err)