Skip to content

Commit 35fb2e8

Browse files
authored
Move the MaxTxGas limit enforcement (#3557)
* Revert "Enable ArbOS 50 in system tests (#3550)" This reverts commit e167107. * Correctly implement EIP-7825 * Fix tests that need to set max block gas limit
1 parent 7578f2d commit 35fb2e8

File tree

10 files changed

+31
-81
lines changed

10 files changed

+31
-81
lines changed

arbos/block_processor.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,11 @@ func ProduceBlockAdvanced(
348348

349349
computeGas := tx.Gas() - dataGas
350350
// Implements EIP-7825. Check activated after arbos_50
351-
if arbState.ArbOSVersion() >= params.ArbosVersion_50 &&
352-
computeGas > maxPerTxGasLimit && isUserTx {
353-
return nil, nil, fmt.Errorf("%w (cap: %d, tx l2Gas: %d)", core.ErrGasLimitTooHigh, maxPerTxGasLimit, computeGas)
351+
if arbState.ArbOSVersion() >= params.ArbosVersion_50 && computeGas > maxPerTxGasLimit && isUserTx {
352+
// Cap the compute gas to the maximum per-transaction gas limit
353+
// and attempt to apply the transaction, if it runs out, there
354+
// will be an error during execution.
355+
computeGas = maxPerTxGasLimit
354356
}
355357
if computeGas < params.TxGas {
356358
if hooks.DiscardInvalidTxsEarly {

cmd/chaininfo/arbitrum_chain_info.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@
263263
"chain-name": "stylus-testnet",
264264
"sequencer-url": "https://stylus-testnet-sequencer.arbitrum.io/rpc",
265265
"feed-url": "wss://stylus-testnet.arbitrum.io/feed",
266-
"chain-config": {
266+
"chain-config":
267+
{
267268
"chainId": 23011913,
268269
"homesteadBlock": 0,
269270
"daoForkBlock": null,
@@ -279,11 +280,13 @@
279280
"muirGlacierBlock": 0,
280281
"berlinBlock": 0,
281282
"londonBlock": 0,
282-
"clique": {
283+
"clique":
284+
{
283285
"period": 0,
284286
"epoch": 0
285287
},
286-
"arbitrum": {
288+
"arbitrum":
289+
{
287290
"EnableArbOS": true,
288291
"AllowDebugPrecompiles": false,
289292
"DataAvailabilityCommittee": false,
@@ -292,7 +295,8 @@
292295
"GenesisBlockNum": 0
293296
}
294297
},
295-
"rollup": {
298+
"rollup":
299+
{
296300
"bridge": "0x35aa95ac4747D928E2Cd42FE4461F6D9d1826346",
297301
"inbox": "0xe1e3b1CBaCC870cb6e5F4Bdf246feB6eB5cD351B",
298302
"sequencer-inbox": "0x00A0F15b79d1D3e5991929FaAbCF2AA65623530c",
@@ -302,4 +306,4 @@
302306
"deployed-at": 1847
303307
}
304308
}
305-
]
309+
]

system_tests/batch_poster_test.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/offchainlabs/nitro/arbnode/dataposter"
2626
"github.com/offchainlabs/nitro/arbnode/dataposter/externalsignertest"
2727
"github.com/offchainlabs/nitro/solgen/go/bridgegen"
28-
pgen "github.com/offchainlabs/nitro/solgen/go/precompilesgen"
2928
"github.com/offchainlabs/nitro/solgen/go/upgrade_executorgen"
3029
"github.com/offchainlabs/nitro/util/redisutil"
3130
)
@@ -367,7 +366,6 @@ func TestBatchPosterLargeTx(t *testing.T) {
367366
defer cancel()
368367

369368
builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
370-
builder.takeOwnership = true
371369
builder.execConfig.Sequencer.MaxTxDataSize = 110000
372370
cleanup := builder.Build(t)
373371
defer cleanup()
@@ -378,18 +376,9 @@ func TestBatchPosterLargeTx(t *testing.T) {
378376
data := make([]byte, 100000)
379377
_, err := rand.Read(data)
380378
Require(t, err)
381-
gas := builder.L2Info.TransferGas + 2000*uint64(len(data))
382-
383-
auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx)
384-
arbOwner, err := pgen.NewArbOwner(types.ArbOwnerAddress, builder.L2.Client)
385-
Require(t, err)
386-
tx, err := arbOwner.SetMaxTxGasLimit(&auth, gas)
387-
Require(t, err)
388-
_, err = EnsureTxSucceeded(ctx, builder.L2.Client, tx)
389-
Require(t, err)
390-
391379
faucetAddr := builder.L2Info.GetAddress("Faucet")
392-
tx = builder.L2Info.PrepareTxToCustomGas("Faucet", &faucetAddr, gas, common.Big0, data)
380+
gas := builder.L2Info.TransferGas + 20000*uint64(len(data))
381+
tx := builder.L2Info.PrepareTxTo("Faucet", &faucetAddr, gas, common.Big0, data)
393382
err = builder.L2.Client.SendTransaction(ctx, tx)
394383
Require(t, err)
395384
receiptA, err := builder.L2.EnsureTxSucceeded(tx)

system_tests/common_test.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -764,10 +764,6 @@ func (b *NodeBuilder) BuildL2OnL1(t *testing.T) func() {
764764
b.addresses,
765765
)
766766

767-
if b.takeOwnership {
768-
becomeChainOwner(t, b.ctx, b.L2Info.GetDefaultTransactOpts("Owner", b.ctx), b.L2.Client)
769-
}
770-
771767
return func() {
772768
b.L2.cleanup()
773769
if b.L1 != nil && b.L1.cleanup != nil {
@@ -822,7 +818,17 @@ func (b *NodeBuilder) BuildL2(t *testing.T) func() {
822818
b.L2.Client = ClientForStack(t, b.L2.Stack)
823819

824820
if b.takeOwnership {
825-
becomeChainOwner(t, b.ctx, b.L2Info.GetDefaultTransactOpts("Owner", b.ctx), b.L2.Client)
821+
debugAuth := b.L2Info.GetDefaultTransactOpts("Owner", b.ctx)
822+
823+
// make auth a chain owner
824+
arbdebug, err := precompilesgen.NewArbDebug(common.HexToAddress("0xff"), b.L2.Client)
825+
Require(t, err, "failed to deploy ArbDebug")
826+
827+
tx, err := arbdebug.BecomeChainOwner(&debugAuth)
828+
Require(t, err, "failed to deploy ArbDebug")
829+
830+
_, err = EnsureTxSucceeded(b.ctx, b.L2.Client, tx)
831+
Require(t, err)
826832
}
827833

828834
StartWatchChanErr(t, b.ctx, fatalErrChan, b.L2.ConsensusNode)
@@ -2119,13 +2125,3 @@ func populateMachineDir(t *testing.T, cr *github.ConsensusRelease) string {
21192125
Require(t, err)
21202126
return machineDir
21212127
}
2122-
2123-
func becomeChainOwner(t *testing.T, ctx context.Context, opts bind.TransactOpts, client *ethclient.Client) {
2124-
t.Helper()
2125-
arbdebug, err := precompilesgen.NewArbDebug(types.ArbDebugAddress, client)
2126-
Require(t, err, "failed to deploy ArbDebug")
2127-
tx, err := arbdebug.BecomeChainOwner(&opts)
2128-
Require(t, err, "failed to deploy ArbDebug")
2129-
_, err = EnsureTxSucceeded(ctx, client, tx)
2130-
Require(t, err)
2131-
}

system_tests/precompile_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ import (
99
"math/big"
1010
"slices"
1111
"sort"
12-
"strings"
1312
"testing"
1413
"time"
1514

1615
"github.com/google/go-cmp/cmp"
1716

1817
"github.com/ethereum/go-ethereum/accounts/abi/bind"
1918
"github.com/ethereum/go-ethereum/common"
20-
"github.com/ethereum/go-ethereum/core"
2119
"github.com/ethereum/go-ethereum/core/types"
2220
"github.com/ethereum/go-ethereum/crypto"
2321
"github.com/ethereum/go-ethereum/params"
@@ -513,13 +511,6 @@ func TestArbOwnerMaxTxAndBlockGasLimit(t *testing.T) {
513511
if haveBlockGasLimitArbGasInfo.Uint64() != wantBlockGasLimit {
514512
t.Fatalf("arbGasInfo blockGasLimit mismatch. have: %d want: %d", haveBlockGasLimitArbGasInfo.Uint64(), wantBlockGasLimit)
515513
}
516-
517-
gas := wantTxGasLimit + 1500000 // as txGasLimit is only on computeGas we need to add more for datagas
518-
tx := builder.L2Info.PrepareTx("Owner", "Faucet", gas, big.NewInt(1e10), nil)
519-
err = builder.L2.Client.SendTransaction(ctx, tx)
520-
if err == nil || !strings.Contains(err.Error(), core.ErrGasLimitTooHigh.Error()) {
521-
t.Fatalf("expected ErrGasLimitTooHigh error but got: %v", err)
522-
}
523514
}
524515

525516
func TestArbNativeTokenManagerThroughSolidityContract(t *testing.T) {

system_tests/program_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ func testMemory(t *testing.T, jit bool) {
10931093
args := argsForMulticall(vm.CALL, memoryAddr, nil, []byte{126, 50})
10941094
args = multicallAppend(args, vm.CALL, memoryAddr, []byte{126, 80})
10951095

1096-
tx := l2info.PrepareTxToCustomGas("Owner", &multiAddr, 33000000, nil, args)
1096+
tx := l2info.PrepareTxTo("Owner", &multiAddr, 1e9, nil, args)
10971097
receipt := ensure(tx, l2client.SendTransaction(ctx, tx))
10981098
gasCost := receipt.GasUsedForL2()
10991099
memCost := model.GasCost(128, 0, 0) + model.GasCost(126, 2, 128)

system_tests/retryable_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ func TestSubmitManyRetryableFailThenRetry(t *testing.T) {
581581
}
582582

583583
l2FaucetTxOpts := builder.L2Info.GetDefaultTransactOpts("Faucet", ctx)
584-
l2FaucetTxOpts.GasLimit = l2pricing.InitialPerTxGasLimitV50
584+
l2FaucetTxOpts.GasLimit = uint64(1e8)
585585
l2FaucetAddress := builder.L2Info.GetAddress("Faucet")
586586
colors.PrintBlue("L2 Faucet ", l2FaucetAddress)
587587
var addressesToCreate []common.Address

system_tests/storage_trie_test.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/ethereum/go-ethereum/core/rawdb"
14-
"github.com/ethereum/go-ethereum/core/types"
1514

16-
pgen "github.com/offchainlabs/nitro/solgen/go/precompilesgen"
1715
"github.com/offchainlabs/nitro/util/arbmath"
1816
"github.com/offchainlabs/nitro/validator/valnode"
1917
)
@@ -24,7 +22,6 @@ func TestStorageTrie(t *testing.T) {
2422

2523
var withL1 = true
2624
builder := NewNodeBuilder(ctx).DefaultConfig(t, withL1)
27-
builder.takeOwnership = true
2825

2926
// This test tests validates blocks at the end.
3027
// For now, validation only works with HashScheme set.
@@ -44,13 +41,6 @@ func TestStorageTrie(t *testing.T) {
4441
defer cleanup()
4542

4643
ownerTxOpts := builder.L2Info.GetDefaultTransactOpts("Owner", ctx)
47-
arbOwner, err := pgen.NewArbOwner(types.ArbOwnerAddress, builder.L2.Client)
48-
Require(t, err)
49-
tx, err := arbOwner.SetMaxTxGasLimit(&ownerTxOpts, 33000000)
50-
Require(t, err)
51-
_, err = EnsureTxSucceeded(ctx, builder.L2.Client, tx)
52-
Require(t, err)
53-
5444
_, bigMap := builder.L2.DeployBigMap(t, ownerTxOpts)
5545

5646
// Store enough values to use just over 32M gas
@@ -59,8 +49,7 @@ func TestStorageTrie(t *testing.T) {
5949
toClear := big.NewInt(0)
6050

6151
userTxOpts := builder.L2Info.GetDefaultTransactOpts("Faucet", ctx)
62-
userTxOpts.GasMargin = 0
63-
tx, err = bigMap.ClearAndAddValues(&userTxOpts, toClear, toAdd)
52+
tx, err := bigMap.ClearAndAddValues(&userTxOpts, toClear, toAdd)
6453
Require(t, err)
6554

6655
receipt, err := builder.L2.EnsureTxSucceeded(tx)

system_tests/test_info.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,6 @@ func (b *BlockchainTestInfo) PrepareTx(from, to string, gas uint64, value *big.I
227227

228228
func (b *BlockchainTestInfo) PrepareTxTo(
229229
from string, to *common.Address, gas uint64, value *big.Int, data []byte,
230-
) *types.Transaction {
231-
// After arbos_50 l2 txs consuming more than 32,000,000 in compute gas are rejected, this makes
232-
// sure our current tests pass and we shouldnt reach compute gas consumption of 32,000,000 anyway
233-
gas = min(gas, l2pricing.InitialPerTxGasLimitV50)
234-
return b.PrepareTxToCustomGas(from, to, gas, value, data)
235-
}
236-
237-
func (b *BlockchainTestInfo) PrepareTxToCustomGas(
238-
from string, to *common.Address, gas uint64, value *big.Int, data []byte,
239230
) *types.Transaction {
240231
b.T.Helper()
241232
info := b.GetInfoWithPrivKey(from)

system_tests/timeboost_test.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
"github.com/offchainlabs/nitro/pubsub"
4242
"github.com/offchainlabs/nitro/solgen/go/express_lane_auctiongen"
4343
"github.com/offchainlabs/nitro/solgen/go/localgen"
44-
pgen "github.com/offchainlabs/nitro/solgen/go/precompilesgen"
4544
"github.com/offchainlabs/nitro/timeboost"
4645
"github.com/offchainlabs/nitro/timeboost/bindings"
4746
"github.com/offchainlabs/nitro/util/arbmath"
@@ -64,16 +63,6 @@ func TestTimeboostTxsTimeoutByBlock(t *testing.T) {
6463
seqClient, seqInfo := builderSeq.L2.Client, builderSeq.L2Info
6564
defer cleanupSeq()
6665
seqInfo.GenerateAccount("User2")
67-
builderSeq.L2.TransferBalance(t, "Owner", "User2", big.NewInt(1e18), seqInfo)
68-
69-
user2Opts := seqInfo.GetDefaultTransactOpts("User2", ctx)
70-
becomeChainOwner(t, ctx, user2Opts, seqClient)
71-
arbOwner, err := pgen.NewArbOwner(types.ArbOwnerAddress, seqClient)
72-
Require(t, err)
73-
tx, err := arbOwner.SetMaxTxGasLimit(&user2Opts, 700000000)
74-
Require(t, err)
75-
_, err = EnsureTxSucceeded(ctx, seqClient, tx)
76-
Require(t, err)
7766

7867
auctionContract, err := express_lane_auctiongen.NewExpressLaneAuction(auctionContractAddr, seqClient)
7968
Require(t, err)
@@ -108,8 +97,7 @@ func TestTimeboostTxsTimeoutByBlock(t *testing.T) {
10897

10998
var txs types.Transactions
11099
for i := uint64(0); i < numTxs; i++ {
111-
user2 := seqInfo.GetAddress("User2")
112-
txs = append(txs, seqInfo.PrepareTxToCustomGas("Owner", &user2, 700000000, big.NewInt(1e8), data)) // this tx should consume one block
100+
txs = append(txs, seqInfo.PrepareTx("Owner", "User2", 700000000, big.NewInt(1e8), data)) // this tx should consume one block
113101
}
114102
// Buffer future sequence numbered txs
115103
for seq := uint64(1); seq < numTxs; seq++ {

0 commit comments

Comments
 (0)