From 31a168d8aecccf81bcfa35af7548f9219f85f3b1 Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Tue, 2 Jul 2024 17:29:30 +0530 Subject: [PATCH 1/2] Add test for gas estimation with RPC gas limit --- system_tests/estimation_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/system_tests/estimation_test.go b/system_tests/estimation_test.go index e7f00ca94e..0e0b329708 100644 --- a/system_tests/estimation_test.go +++ b/system_tests/estimation_test.go @@ -324,3 +324,33 @@ func TestDisableL1Charging(t *testing.T) { _, err = builder.L2.Client.CallContract(ctx, ethereum.CallMsg{To: &addr, Gas: gasWithoutL1Charging, SkipL1Charging: true}, nil) Require(t, err) } + +func TestGasEstimationWithRPCGasLimit(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, true) + cleanup := builder.Build(t) + defer cleanup() + + execConfigA := builder.execConfig + execConfigA.RPC.RPCGasCap = params.TxGas + testClientA, cleanupA := builder.Build2ndNode(t, &SecondNodeParams{execConfig: execConfigA}) + defer cleanupA() + addr := common.HexToAddress("0x12345678") + estimateGas, err := testClientA.Client.EstimateGas(ctx, ethereum.CallMsg{To: &addr}) + Require(t, err) + if estimateGas <= params.TxGas { + Fatal(t, "Incorrect gas estimate") + } + + _, err = testClientA.Client.CallContract(ctx, ethereum.CallMsg{To: &addr}, nil) + Require(t, err) + + execConfigB := builder.execConfig + execConfigB.RPC.RPCGasCap = params.TxGas - 1 + testClientB, cleanupB := builder.Build2ndNode(t, &SecondNodeParams{execConfig: execConfigB}) + defer cleanupB() + _, err = testClientB.Client.EstimateGas(ctx, ethereum.CallMsg{To: &addr}) + Require(t, err) +} From 8b0424b6307bbc4b1974d5492431c6813929bb17 Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Wed, 3 Jul 2024 17:48:27 +0530 Subject: [PATCH 2/2] fix --- execution/nodeInterface/virtual-contracts.go | 3 ++- system_tests/estimation_test.go | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/execution/nodeInterface/virtual-contracts.go b/execution/nodeInterface/virtual-contracts.go index d72ad0da8e..d04be10857 100644 --- a/execution/nodeInterface/virtual-contracts.go +++ b/execution/nodeInterface/virtual-contracts.go @@ -141,7 +141,8 @@ func init() { return } posterCost, _ := state.L1PricingState().PosterDataCost(msg, l1pricing.BatchPosterAddress, brotliCompressionLevel) - posterCostInL2Gas := arbos.GetPosterGas(state, header.BaseFee, msg.TxRunMode, posterCost) + // Use estimate mode because this is used to raise the gas cap, so we don't want to underestimate. + posterCostInL2Gas := arbos.GetPosterGas(state, header.BaseFee, core.MessageGasEstimationMode, posterCost) *gascap = arbmath.SaturatingUAdd(*gascap, posterCostInL2Gas) } diff --git a/system_tests/estimation_test.go b/system_tests/estimation_test.go index 0e0b329708..284c709fad 100644 --- a/system_tests/estimation_test.go +++ b/system_tests/estimation_test.go @@ -352,5 +352,7 @@ func TestGasEstimationWithRPCGasLimit(t *testing.T) { testClientB, cleanupB := builder.Build2ndNode(t, &SecondNodeParams{execConfig: execConfigB}) defer cleanupB() _, err = testClientB.Client.EstimateGas(ctx, ethereum.CallMsg{To: &addr}) - Require(t, err) + if err == nil { + Fatal(t, "EstimateGas passed with insufficient gas") + } }