From 7c3c41c46ec294c72b211a6145a2132c1ea8bd8c Mon Sep 17 00:00:00 2001 From: Krish Date: Thu, 26 Dec 2024 18:02:47 +0800 Subject: [PATCH 1/7] feat: enable eip_7702 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3e5d4a828..35ca94584 100644 --- a/go.mod +++ b/go.mod @@ -277,7 +277,7 @@ require ( rsc.io/tmplfunc v0.0.3 // indirect ) -replace github.com/ethereum/go-ethereum v1.13.15 => github.com/bnb-chain/op-geth v1.101315.2-0.0.20240823030609-c0f12a4e1b05 +replace github.com/ethereum/go-ethereum v1.13.15 => github.com/krish-nr/op-geth v0.2.2-rc.1.0.20241226015808-4d92fe224340 replace github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v1.0.0 diff --git a/go.sum b/go.sum index bf3c1d73c..9e9f5d69a 100644 --- a/go.sum +++ b/go.sum @@ -184,8 +184,6 @@ github.com/bnb-chain/fastssz v0.1.2 h1:vTcXw5SwCtRYnl/BEclujiml7GXiVOZ74tub4GHpv github.com/bnb-chain/fastssz v0.1.2/go.mod h1:KcabV+OEw2QwgyY8Fc88ZG79CKYkFdu0kKWyfA3dI6o= github.com/bnb-chain/greenfield-cometbft v1.0.0 h1:0r6hOJWD/+es0gxP/exKuN/krgXAr3LCn5/XlcgDWr8= github.com/bnb-chain/greenfield-cometbft v1.0.0/go.mod h1:f35mk/r5ab6yvzlqEWZt68LfUje68sYgMpVlt2CUYMk= -github.com/bnb-chain/op-geth v1.101315.2-0.0.20240823030609-c0f12a4e1b05 h1:Tyov2UCjIxxHt6ZX46T09CiKpKDY72AtjHzUQFK3SBA= -github.com/bnb-chain/op-geth v1.101315.2-0.0.20240823030609-c0f12a4e1b05/go.mod h1:hyHrrcHkUe3lRwfJs+JGrbOHp+pRdheRk+ren4TPhF8= github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= @@ -933,6 +931,8 @@ github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/krish-nr/op-geth v0.2.2-rc.1.0.20241226015808-4d92fe224340 h1:ez7r25x9QqapSj3ohHDdm7EqjqJINMR2//tUSZMeP3g= +github.com/krish-nr/op-geth v0.2.2-rc.1.0.20241226015808-4d92fe224340/go.mod h1:hyHrrcHkUe3lRwfJs+JGrbOHp+pRdheRk+ren4TPhF8= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4FW1e6jwpg= From fdc964c8fa47fe8f17d9b9cd74b32f57de73aa02 Mon Sep 17 00:00:00 2001 From: Krish Date: Fri, 27 Dec 2024 12:10:27 +0800 Subject: [PATCH 2/7] feat: support eip_7702 in batcher --- op-batcher/batcher/driver.go | 15 +++---- op-node/rollup/derive/span_batch_tx.go | 52 +++++++++++++++++++++++-- op-node/rollup/derive/span_batch_txs.go | 8 +++- 3 files changed, 63 insertions(+), 12 deletions(-) diff --git a/op-batcher/batcher/driver.go b/op-batcher/batcher/driver.go index b70ffe239..77ee1abe0 100644 --- a/op-batcher/batcher/driver.go +++ b/op-batcher/batcher/driver.go @@ -12,6 +12,13 @@ import ( "sync/atomic" "time" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/consensus/misc/eip4844" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/params" + "github.com/ethereum-optimism/optimism/op-batcher/flags" "github.com/ethereum-optimism/optimism/op-batcher/metrics" "github.com/ethereum-optimism/optimism/op-node/rollup" @@ -20,12 +27,6 @@ import ( "github.com/ethereum-optimism/optimism/op-service/dial" "github.com/ethereum-optimism/optimism/op-service/eth" "github.com/ethereum-optimism/optimism/op-service/txmgr" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/consensus/misc/eip4844" - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/params" ) const LimitLoadBlocksOneTime uint64 = 30 @@ -678,7 +679,7 @@ func (l *BatchSubmitter) sendTransaction(ctx context.Context, txdata txData, que candidate = l.calldataTxCandidate(data) } - intrinsicGas, err := core.IntrinsicGas(candidate.TxData, nil, false, true, true, false) + intrinsicGas, err := core.IntrinsicGas(candidate.TxData, nil, nil, true, true, false, false) if err != nil { // we log instead of return an error here because txmgr can do its own gas estimation l.Log.Error("Failed to calculate intrinsic gas", "err", err) diff --git a/op-node/rollup/derive/span_batch_tx.go b/op-node/rollup/derive/span_batch_tx.go index cd0a471ab..78c7911ae 100644 --- a/op-node/rollup/derive/span_batch_tx.go +++ b/op-node/rollup/derive/span_batch_tx.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rlp" + "github.com/holiman/uint256" ) type spanBatchTxData interface { @@ -45,6 +46,17 @@ type spanBatchDynamicFeeTxData struct { func (txData *spanBatchDynamicFeeTxData) txType() byte { return types.DynamicFeeTxType } +type spanBatchSetCodeTxData struct { + Value *big.Int // wei amount + GasTipCap *big.Int // maxPriorityFeePerGas (EIP-1559) + GasFeeCap *big.Int // maxFeePerGas (EIP-1559) + Data []byte // contract invocation input data + AccessList types.AccessList // EIP-2930 access list + AuthList []types.Authorization // EIP-7702 authorization list +} + +func (txData *spanBatchSetCodeTxData) txType() byte { return types.SetCodeTxType } + // Type returns the transaction type. func (tx *spanBatchTx) Type() uint8 { return tx.inner.txType() @@ -79,7 +91,7 @@ func (tx *spanBatchTx) decodeTyped(b []byte) (spanBatchTxData, error) { return nil, fmt.Errorf("failed to decode span batch: %w", ErrTypedTxTooShort) } switch b[0] { - case types.AccessListTxType: + case types.AccessListTxType: //有了 var inner spanBatchAccessListTxData err := rlp.DecodeBytes(b[1:], &inner) if err != nil { @@ -93,6 +105,13 @@ func (tx *spanBatchTx) decodeTyped(b []byte) (spanBatchTxData, error) { return nil, fmt.Errorf("failed to decode spanBatchDynamicFeeTxData: %w", err) } return &inner, nil + case types.SetCodeTxType: + var inner spanBatchSetCodeTxData + err := rlp.DecodeBytes(b[1:], &inner) + if err != nil { + return nil, fmt.Errorf("failed to decode spanBatchSetCodeTxData: %w", err) + } + return &inner, nil default: return nil, types.ErrTxTypeNotSupported } @@ -137,7 +156,7 @@ func (tx *spanBatchTx) convertToFullTx(nonce, gas uint64, to *common.Address, ch R: R, S: S, } - case types.AccessListTxType: + case types.AccessListTxType: //有了 batchTxInner := tx.inner.(*spanBatchAccessListTxData) inner = &types.AccessListTx{ ChainID: chainID, @@ -168,6 +187,23 @@ func (tx *spanBatchTx) convertToFullTx(nonce, gas uint64, to *common.Address, ch R: R, S: S, } + case types.SetCodeTxType: + batchTxInner := tx.inner.(*spanBatchSetCodeTxData) + inner = &types.SetCodeTx{ + ChainID: chainID.Uint64(), + Nonce: nonce, + GasTipCap: uint256.MustFromBig(batchTxInner.GasTipCap), + GasFeeCap: uint256.MustFromBig(batchTxInner.GasFeeCap), + Gas: gas, + To: *to, + Value: uint256.MustFromBig(batchTxInner.Value), + Data: batchTxInner.Data, + AccessList: batchTxInner.AccessList, + AuthList: batchTxInner.AuthList, + V: uint256.MustFromBig(V), + R: uint256.MustFromBig(R), + S: uint256.MustFromBig(S), + } default: return nil, fmt.Errorf("invalid tx type: %d", tx.Type()) } @@ -184,7 +220,7 @@ func newSpanBatchTx(tx types.Transaction) (*spanBatchTx, error) { Value: tx.Value(), Data: tx.Data(), } - case types.AccessListTxType: + case types.AccessListTxType: //有了 inner = &spanBatchAccessListTxData{ GasPrice: tx.GasPrice(), Value: tx.Value(), @@ -199,6 +235,16 @@ func newSpanBatchTx(tx types.Transaction) (*spanBatchTx, error) { Data: tx.Data(), AccessList: tx.AccessList(), } + case types.SetCodeTxType: + inner = &spanBatchSetCodeTxData{ + GasTipCap: tx.GasTipCap(), + GasFeeCap: tx.GasFeeCap(), + Value: tx.Value(), + Data: tx.Data(), + AccessList: tx.AccessList(), + AuthList: tx.AuthList(), + } + default: return nil, fmt.Errorf("invalid tx type: %d", tx.Type()) } diff --git a/op-node/rollup/derive/span_batch_txs.go b/op-node/rollup/derive/span_batch_txs.go index 305aafefe..bf64ef835 100644 --- a/op-node/rollup/derive/span_batch_txs.go +++ b/op-node/rollup/derive/span_batch_txs.go @@ -267,10 +267,12 @@ func (btx *spanBatchTxs) recoverV(chainID *big.Int) error { // EIP-155 v = chainID.Uint64()*2 + 35 + bit } - case types.AccessListTxType: + case types.AccessListTxType: //有了 v = bit case types.DynamicFeeTxType: v = bit + case types.SetCodeTxType: + v = bit default: return fmt.Errorf("invalid tx type: %d", txType) } @@ -382,10 +384,12 @@ func convertVToYParity(v uint64, txType int) (uint, error) { // unprotected legacy txs must have v = 27 or 28 yParityBit = uint(v - 27) } - case types.AccessListTxType: + case types.AccessListTxType: //有了 yParityBit = uint(v) case types.DynamicFeeTxType: yParityBit = uint(v) + case types.SetCodeTxType: + yParityBit = uint(v) default: return 0, fmt.Errorf("invalid tx type: %d", txType) } From 30945b36477a5d0677c79ac4fdf906b6e764d7e6 Mon Sep 17 00:00:00 2001 From: Krish Date: Thu, 9 Jan 2025 16:57:46 +0800 Subject: [PATCH 3/7] fix: adapt bsc fix --- op-service/sources/eth_client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/op-service/sources/eth_client.go b/op-service/sources/eth_client.go index 5ffa3f07e..e6879047f 100644 --- a/op-service/sources/eth_client.go +++ b/op-service/sources/eth_client.go @@ -285,7 +285,9 @@ func (s *EthClient) InfoByLabel(ctx context.Context, label eth.BlockLabel) (eth. func (s *EthClient) BSCInfoByLabel(ctx context.Context, label eth.BlockLabel) (eth.BlockInfo, error) { // can't hit the cache when querying the head due to reorgs / changes. if label == eth.Finalized { - return s.bscFinalizedHeader(ctx, 21) + // -3 means automatically use the len(validators) of BSC network + // refs: https://github.com/bnb-chain/bsc/pull/2844 + return s.bscFinalizedHeader(ctx, -3) } return s.headerCall(ctx, "eth_getBlockByNumber", label) } From a12cac5b46ab97335045e02f53744a02f3f115ea Mon Sep 17 00:00:00 2001 From: Krish Date: Thu, 6 Feb 2025 10:19:28 +0800 Subject: [PATCH 4/7] update geth dependency --- go.mod | 2 +- go.sum | 4 +-- op-chain-ops/cmd/check-derivation/main.go | 6 ++-- op-e2e/actions/l2_batcher.go | 4 +-- op-e2e/actions/l2_batcher_test.go | 2 +- op-e2e/actions/span_batch_test.go | 4 +-- op-e2e/actions/sync_test.go | 2 +- op-e2e/brotli_batcher_test.go | 2 +- op-e2e/eip4844_test.go | 2 +- op-node/rollup/derive/span_batch_tx.go | 6 ++-- op-node/rollup/derive/span_batch_txs.go | 4 +-- op-program/client/mpt/db.go | 36 +++++++++++++++++++++++ 12 files changed, 55 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index 35ca94584..db9af5276 100644 --- a/go.mod +++ b/go.mod @@ -277,7 +277,7 @@ require ( rsc.io/tmplfunc v0.0.3 // indirect ) -replace github.com/ethereum/go-ethereum v1.13.15 => github.com/krish-nr/op-geth v0.2.2-rc.1.0.20241226015808-4d92fe224340 +replace github.com/ethereum/go-ethereum v1.13.15 => github.com/bnb-chain/op-geth v1.101315.2-0.0.20241227085525-b47710880c69 replace github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v1.0.0 diff --git a/go.sum b/go.sum index 9e9f5d69a..97da4cba7 100644 --- a/go.sum +++ b/go.sum @@ -184,6 +184,8 @@ github.com/bnb-chain/fastssz v0.1.2 h1:vTcXw5SwCtRYnl/BEclujiml7GXiVOZ74tub4GHpv github.com/bnb-chain/fastssz v0.1.2/go.mod h1:KcabV+OEw2QwgyY8Fc88ZG79CKYkFdu0kKWyfA3dI6o= github.com/bnb-chain/greenfield-cometbft v1.0.0 h1:0r6hOJWD/+es0gxP/exKuN/krgXAr3LCn5/XlcgDWr8= github.com/bnb-chain/greenfield-cometbft v1.0.0/go.mod h1:f35mk/r5ab6yvzlqEWZt68LfUje68sYgMpVlt2CUYMk= +github.com/bnb-chain/op-geth v1.101315.2-0.0.20241227085525-b47710880c69 h1:5//2TuCoaoE9Ihp4jW4AuQlZvxU+jJNiY9BiNHse1gA= +github.com/bnb-chain/op-geth v1.101315.2-0.0.20241227085525-b47710880c69/go.mod h1:hyHrrcHkUe3lRwfJs+JGrbOHp+pRdheRk+ren4TPhF8= github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= @@ -931,8 +933,6 @@ github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/krish-nr/op-geth v0.2.2-rc.1.0.20241226015808-4d92fe224340 h1:ez7r25x9QqapSj3ohHDdm7EqjqJINMR2//tUSZMeP3g= -github.com/krish-nr/op-geth v0.2.2-rc.1.0.20241226015808-4d92fe224340/go.mod h1:hyHrrcHkUe3lRwfJs+JGrbOHp+pRdheRk+ren4TPhF8= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4FW1e6jwpg= diff --git a/op-chain-ops/cmd/check-derivation/main.go b/op-chain-ops/cmd/check-derivation/main.go index dd5d63194..62ec2b3e8 100644 --- a/op-chain-ops/cmd/check-derivation/main.go +++ b/op-chain-ops/cmd/check-derivation/main.go @@ -225,7 +225,7 @@ func getRandomSignedTransaction(ctx context.Context, ethClient *ethclient.Client var txData types.TxData switch txType { case types.LegacyTxType: - gasLimit, err := core.IntrinsicGas(data, nil, false, true, true, false) + gasLimit, err := core.IntrinsicGas(data, nil, nil, false, true, true, false) if err != nil { return nil, fmt.Errorf("failed to get intrinsicGas: %w", err) } @@ -242,7 +242,7 @@ func getRandomSignedTransaction(ctx context.Context, ethClient *ethclient.Client Address: randomAddress, StorageKeys: []common.Hash{common.HexToHash("0x1234")}, }} - gasLimit, err := core.IntrinsicGas(data, accessList, false, true, true, false) + gasLimit, err := core.IntrinsicGas(data, accessList, nil, false, true, true, false) if err != nil { return nil, fmt.Errorf("failed to get intrinsicGas: %w", err) } @@ -257,7 +257,7 @@ func getRandomSignedTransaction(ctx context.Context, ethClient *ethclient.Client Data: data, } case types.DynamicFeeTxType: - gasLimit, err := core.IntrinsicGas(data, nil, false, true, true, false) + gasLimit, err := core.IntrinsicGas(data, nil, nil, false, true, true, false) if err != nil { return nil, fmt.Errorf("failed to get intrinsicGas: %w", err) } diff --git a/op-e2e/actions/l2_batcher.go b/op-e2e/actions/l2_batcher.go index 310a6cade..c114424c6 100644 --- a/op-e2e/actions/l2_batcher.go +++ b/op-e2e/actions/l2_batcher.go @@ -277,7 +277,7 @@ func (s *L2Batcher) ActL2BatchSubmit(t Testing, txOpts ...func(tx *types.Dynamic opt(rawTx) } - gas, err := core.IntrinsicGas(rawTx.Data, nil, false, true, true, false) + gas, err := core.IntrinsicGas(rawTx.Data, nil, nil, false, true, true, false) require.NoError(t, err, "need to compute intrinsic gas") rawTx.Gas = gas txData = rawTx @@ -468,7 +468,7 @@ func (s *L2Batcher) ActL2BatchSubmitGarbage(t Testing, kind GarbageKind) { GasFeeCap: gasFeeCap, Data: outputFrame, } - gas, err := core.IntrinsicGas(rawTx.Data, nil, false, true, true, false) + gas, err := core.IntrinsicGas(rawTx.Data, nil, nil, false, true, true, false) require.NoError(t, err, "need to compute intrinsic gas") rawTx.Gas = gas diff --git a/op-e2e/actions/l2_batcher_test.go b/op-e2e/actions/l2_batcher_test.go index 3a137ce99..27f567b32 100644 --- a/op-e2e/actions/l2_batcher_test.go +++ b/op-e2e/actions/l2_batcher_test.go @@ -496,7 +496,7 @@ func BigL2Txs(gt *testing.T, deltaTimeOffset *hexutil.Uint64) { data := make([]byte, 120_000) // very large L2 txs, as large as the tx-pool will accept _, err := rng.Read(data[:]) // fill with random bytes, to make compression ineffective require.NoError(t, err) - gas, err := core.IntrinsicGas(data, nil, false, true, true, false) + gas, err := core.IntrinsicGas(data, nil, nil, false, true, true, false) require.NoError(t, err) if gas > engine.engineApi.RemainingBlockGas() { break diff --git a/op-e2e/actions/span_batch_test.go b/op-e2e/actions/span_batch_test.go index 6ccb76a46..751bbd485 100644 --- a/op-e2e/actions/span_batch_test.go +++ b/op-e2e/actions/span_batch_test.go @@ -524,7 +524,7 @@ func TestSpanBatchLowThroughputChain(gt *testing.T) { data := make([]byte, rand.Intn(100)) _, err := crand.Read(data[:]) // fill with random bytes require.NoError(t, err) - gas, err := core.IntrinsicGas(data, nil, false, true, true, false) + gas, err := core.IntrinsicGas(data, nil, nil, false, true, true, false) require.NoError(t, err) baseFee := seqEngine.l2Chain.CurrentBlock().BaseFee nonce, err := cl.PendingNonceAt(t.Ctx(), addrs[userIdx]) @@ -663,7 +663,7 @@ func TestBatchEquivalence(gt *testing.T) { data := make([]byte, rand.Intn(100)) _, err := crand.Read(data[:]) // fill with random bytes require.NoError(t, err) - gas, err := core.IntrinsicGas(data, nil, false, true, true, false) + gas, err := core.IntrinsicGas(data, nil, nil, false, true, true, false) require.NoError(t, err) baseFee := seqEngine.l2Chain.CurrentBlock().BaseFee nonce, err := seqEngCl.PendingNonceAt(t.Ctx(), addrs[userIdx]) diff --git a/op-e2e/actions/sync_test.go b/op-e2e/actions/sync_test.go index e7521bdd8..8af07f973 100644 --- a/op-e2e/actions/sync_test.go +++ b/op-e2e/actions/sync_test.go @@ -896,7 +896,7 @@ func TestInvalidPayloadInSpanBatch(gt *testing.T) { aliceNonce, err := seqEng.EthClient().PendingNonceAt(t.Ctx(), dp.Addresses.Alice) require.NoError(t, err) data := make([]byte, rand.Intn(100)) - gas, err := core.IntrinsicGas(data, nil, false, true, true, false) + gas, err := core.IntrinsicGas(data, nil, nil, false, true, true, false) require.NoError(t, err) baseFee := seqEng.l2Chain.CurrentBlock().BaseFee tx := types.MustSignNewTx(dp.Secrets.Alice, signer, &types.DynamicFeeTx{ diff --git a/op-e2e/brotli_batcher_test.go b/op-e2e/brotli_batcher_test.go index 97211c471..4b986f30d 100644 --- a/op-e2e/brotli_batcher_test.go +++ b/op-e2e/brotli_batcher_test.go @@ -85,7 +85,7 @@ func TestBrotliBatcherFjord(t *testing.T) { opts.Value = big.NewInt(1_000_000_000) opts.Nonce = 1 // Already have deposit opts.ToAddr = &common.Address{0xff, 0xff} - opts.Gas, err = core.IntrinsicGas(opts.Data, nil, false, true, true, false) + opts.Gas, err = core.IntrinsicGas(opts.Data, nil, nil, false, true, true, false) require.NoError(t, err) opts.VerifyOnClients(l2Verif) }) diff --git a/op-e2e/eip4844_test.go b/op-e2e/eip4844_test.go index 5b5cc1d53..ca6971de5 100644 --- a/op-e2e/eip4844_test.go +++ b/op-e2e/eip4844_test.go @@ -102,7 +102,7 @@ func testSystem4844E2E(t *testing.T, multiBlob bool) { opts.ToAddr = &common.Address{0xff, 0xff} // put some random data in the tx to make it fill up 6 blobs (multi-blob case) opts.Data = testutils.RandomData(rand.New(rand.NewSource(420)), 400) - opts.Gas, err = core.IntrinsicGas(opts.Data, nil, false, true, true, false) + opts.Gas, err = core.IntrinsicGas(opts.Data, nil, nil, false, true, true, false) require.NoError(t, err) opts.VerifyOnClients(l2Verif) }) diff --git a/op-node/rollup/derive/span_batch_tx.go b/op-node/rollup/derive/span_batch_tx.go index 78c7911ae..105c4c380 100644 --- a/op-node/rollup/derive/span_batch_tx.go +++ b/op-node/rollup/derive/span_batch_tx.go @@ -91,7 +91,7 @@ func (tx *spanBatchTx) decodeTyped(b []byte) (spanBatchTxData, error) { return nil, fmt.Errorf("failed to decode span batch: %w", ErrTypedTxTooShort) } switch b[0] { - case types.AccessListTxType: //有了 + case types.AccessListTxType: var inner spanBatchAccessListTxData err := rlp.DecodeBytes(b[1:], &inner) if err != nil { @@ -156,7 +156,7 @@ func (tx *spanBatchTx) convertToFullTx(nonce, gas uint64, to *common.Address, ch R: R, S: S, } - case types.AccessListTxType: //有了 + case types.AccessListTxType: batchTxInner := tx.inner.(*spanBatchAccessListTxData) inner = &types.AccessListTx{ ChainID: chainID, @@ -220,7 +220,7 @@ func newSpanBatchTx(tx types.Transaction) (*spanBatchTx, error) { Value: tx.Value(), Data: tx.Data(), } - case types.AccessListTxType: //有了 + case types.AccessListTxType: inner = &spanBatchAccessListTxData{ GasPrice: tx.GasPrice(), Value: tx.Value(), diff --git a/op-node/rollup/derive/span_batch_txs.go b/op-node/rollup/derive/span_batch_txs.go index bf64ef835..35d2a2f55 100644 --- a/op-node/rollup/derive/span_batch_txs.go +++ b/op-node/rollup/derive/span_batch_txs.go @@ -267,7 +267,7 @@ func (btx *spanBatchTxs) recoverV(chainID *big.Int) error { // EIP-155 v = chainID.Uint64()*2 + 35 + bit } - case types.AccessListTxType: //有了 + case types.AccessListTxType: v = bit case types.DynamicFeeTxType: v = bit @@ -384,7 +384,7 @@ func convertVToYParity(v uint64, txType int) (uint, error) { // unprotected legacy txs must have v = 27 or 28 yParityBit = uint(v - 27) } - case types.AccessListTxType: //有了 + case types.AccessListTxType: yParityBit = uint(v) case types.DynamicFeeTxType: yParityBit = uint(v) diff --git a/op-program/client/mpt/db.go b/op-program/client/mpt/db.go index 6728d4101..e819b1868 100644 --- a/op-program/client/mpt/db.go +++ b/op-program/client/mpt/db.go @@ -13,6 +13,42 @@ type DB struct { db Hooks } +func (p *DB) StateStoreReader() ethdb.Reader { + panic("not supported") +} + +func (p *DB) BlockStoreReader() ethdb.Reader { + panic("not supported") +} + +func (p *DB) BlockStoreWriter() ethdb.Writer { + panic("not supported") +} + +func (p *DB) StateStore() ethdb.Database { + panic("not supported") +} + +func (p *DB) SetStateStore(state ethdb.Database) { + panic("not supported") +} + +func (p *DB) GetStateStore() ethdb.Database { + panic("not supported") +} + +func (p *DB) BlockStore() ethdb.Database { + panic("not supported") +} + +func (p *DB) SetBlockStore(block ethdb.Database) { + panic("not supported") +} + +func (p *DB) HasSeparateBlockStore() bool { + panic("not supported") +} + func (p *DB) Has(key []byte) (bool, error) { panic("not supported") } From 63251081b51e792c087e229fff6e423629d819a5 Mon Sep 17 00:00:00 2001 From: Krish Date: Tue, 11 Feb 2025 21:04:59 +0800 Subject: [PATCH 5/7] update geth dependency --- go.mod | 2 +- go.sum | 4 ++-- op-node/rollup/derive/span_batch_tx.go | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index db9af5276..633e0c261 100644 --- a/go.mod +++ b/go.mod @@ -277,7 +277,7 @@ require ( rsc.io/tmplfunc v0.0.3 // indirect ) -replace github.com/ethereum/go-ethereum v1.13.15 => github.com/bnb-chain/op-geth v1.101315.2-0.0.20241227085525-b47710880c69 +replace github.com/ethereum/go-ethereum v1.13.15 => github.com/bnb-chain/op-geth v1.101315.2-0.0.20250211105604-4938993c410b replace github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v1.0.0 diff --git a/go.sum b/go.sum index 97da4cba7..70ae5ca9c 100644 --- a/go.sum +++ b/go.sum @@ -184,8 +184,8 @@ github.com/bnb-chain/fastssz v0.1.2 h1:vTcXw5SwCtRYnl/BEclujiml7GXiVOZ74tub4GHpv github.com/bnb-chain/fastssz v0.1.2/go.mod h1:KcabV+OEw2QwgyY8Fc88ZG79CKYkFdu0kKWyfA3dI6o= github.com/bnb-chain/greenfield-cometbft v1.0.0 h1:0r6hOJWD/+es0gxP/exKuN/krgXAr3LCn5/XlcgDWr8= github.com/bnb-chain/greenfield-cometbft v1.0.0/go.mod h1:f35mk/r5ab6yvzlqEWZt68LfUje68sYgMpVlt2CUYMk= -github.com/bnb-chain/op-geth v1.101315.2-0.0.20241227085525-b47710880c69 h1:5//2TuCoaoE9Ihp4jW4AuQlZvxU+jJNiY9BiNHse1gA= -github.com/bnb-chain/op-geth v1.101315.2-0.0.20241227085525-b47710880c69/go.mod h1:hyHrrcHkUe3lRwfJs+JGrbOHp+pRdheRk+ren4TPhF8= +github.com/bnb-chain/op-geth v1.101315.2-0.0.20250211105604-4938993c410b h1:41ofqQekH7zhnU8auIg/ylopKCGuPCqXjitFVQhK4rg= +github.com/bnb-chain/op-geth v1.101315.2-0.0.20250211105604-4938993c410b/go.mod h1:hyHrrcHkUe3lRwfJs+JGrbOHp+pRdheRk+ren4TPhF8= github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= diff --git a/op-node/rollup/derive/span_batch_tx.go b/op-node/rollup/derive/span_batch_tx.go index 105c4c380..f489dafed 100644 --- a/op-node/rollup/derive/span_batch_tx.go +++ b/op-node/rollup/derive/span_batch_tx.go @@ -47,12 +47,12 @@ type spanBatchDynamicFeeTxData struct { func (txData *spanBatchDynamicFeeTxData) txType() byte { return types.DynamicFeeTxType } type spanBatchSetCodeTxData struct { - Value *big.Int // wei amount - GasTipCap *big.Int // maxPriorityFeePerGas (EIP-1559) - GasFeeCap *big.Int // maxFeePerGas (EIP-1559) - Data []byte // contract invocation input data - AccessList types.AccessList // EIP-2930 access list - AuthList []types.Authorization // EIP-7702 authorization list + Value *big.Int // wei amount + GasTipCap *big.Int // maxPriorityFeePerGas (EIP-1559) + GasFeeCap *big.Int // maxFeePerGas (EIP-1559) + Data []byte // contract invocation input data + AccessList types.AccessList // EIP-2930 access list + AuthList []types.SetCodeAuthorization // EIP-7702 authorization list } func (txData *spanBatchSetCodeTxData) txType() byte { return types.SetCodeTxType } @@ -190,7 +190,7 @@ func (tx *spanBatchTx) convertToFullTx(nonce, gas uint64, to *common.Address, ch case types.SetCodeTxType: batchTxInner := tx.inner.(*spanBatchSetCodeTxData) inner = &types.SetCodeTx{ - ChainID: chainID.Uint64(), + ChainID: uint256.MustFromBig(chainID), Nonce: nonce, GasTipCap: uint256.MustFromBig(batchTxInner.GasTipCap), GasFeeCap: uint256.MustFromBig(batchTxInner.GasFeeCap), @@ -242,7 +242,7 @@ func newSpanBatchTx(tx types.Transaction) (*spanBatchTx, error) { Value: tx.Value(), Data: tx.Data(), AccessList: tx.AccessList(), - AuthList: tx.AuthList(), + AuthList: tx.SetCodeAuthorizations(), } default: From ca85ea8b7c69d97e0e306891181b5979384b4e8e Mon Sep 17 00:00:00 2001 From: Krish Date: Thu, 13 Feb 2025 22:26:28 +0800 Subject: [PATCH 6/7] feat: adapt BEP-496(EIP-7623) --- go.mod | 2 +- go.sum | 4 ++-- op-batcher/batcher/driver.go | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 633e0c261..77bcf120c 100644 --- a/go.mod +++ b/go.mod @@ -277,7 +277,7 @@ require ( rsc.io/tmplfunc v0.0.3 // indirect ) -replace github.com/ethereum/go-ethereum v1.13.15 => github.com/bnb-chain/op-geth v1.101315.2-0.0.20250211105604-4938993c410b +replace github.com/ethereum/go-ethereum v1.13.15 => github.com/bnb-chain/op-geth v1.101315.2-0.0.20250213114253-fbecb252643d replace github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v1.0.0 diff --git a/go.sum b/go.sum index 70ae5ca9c..dda996ef9 100644 --- a/go.sum +++ b/go.sum @@ -184,8 +184,8 @@ github.com/bnb-chain/fastssz v0.1.2 h1:vTcXw5SwCtRYnl/BEclujiml7GXiVOZ74tub4GHpv github.com/bnb-chain/fastssz v0.1.2/go.mod h1:KcabV+OEw2QwgyY8Fc88ZG79CKYkFdu0kKWyfA3dI6o= github.com/bnb-chain/greenfield-cometbft v1.0.0 h1:0r6hOJWD/+es0gxP/exKuN/krgXAr3LCn5/XlcgDWr8= github.com/bnb-chain/greenfield-cometbft v1.0.0/go.mod h1:f35mk/r5ab6yvzlqEWZt68LfUje68sYgMpVlt2CUYMk= -github.com/bnb-chain/op-geth v1.101315.2-0.0.20250211105604-4938993c410b h1:41ofqQekH7zhnU8auIg/ylopKCGuPCqXjitFVQhK4rg= -github.com/bnb-chain/op-geth v1.101315.2-0.0.20250211105604-4938993c410b/go.mod h1:hyHrrcHkUe3lRwfJs+JGrbOHp+pRdheRk+ren4TPhF8= +github.com/bnb-chain/op-geth v1.101315.2-0.0.20250213114253-fbecb252643d h1:zYSisO6VUWaQzieOnP7NcEXfwbcYa86CipNS+sXHb7Q= +github.com/bnb-chain/op-geth v1.101315.2-0.0.20250213114253-fbecb252643d/go.mod h1:hyHrrcHkUe3lRwfJs+JGrbOHp+pRdheRk+ren4TPhF8= github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= diff --git a/op-batcher/batcher/driver.go b/op-batcher/batcher/driver.go index 77ee1abe0..0df382ac1 100644 --- a/op-batcher/batcher/driver.go +++ b/op-batcher/batcher/driver.go @@ -1,6 +1,7 @@ package batcher import ( + "bytes" "context" "errors" "fmt" @@ -13,6 +14,7 @@ import ( "time" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/consensus/misc/eip4844" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" @@ -683,6 +685,27 @@ func (l *BatchSubmitter) sendTransaction(ctx context.Context, txdata txData, que if err != nil { // we log instead of return an error here because txmgr can do its own gas estimation l.Log.Error("Failed to calculate intrinsic gas", "err", err) + } else if candidate.Blobs == nil { + minimumGasRequired, err := func(data []byte) (uint64, error) { + var ( + z = uint64(bytes.Count(data, []byte{0})) + nz = uint64(len(data)) - z + tokens = nz*params.TxTokenPerNonZeroByte + z + ) + if (math.MaxUint64-params.TxGas)/params.TxCostFloorPerToken < tokens { + return 0, errors.New("intrinsic gas too low") + } + return params.TxGas + tokens*params.TxCostFloorPerToken, nil + }(candidate.TxData) + + if err != nil { + return err + } + // + baseGas := intrinsicGas - params.TxGas + finalGasLimit := max(baseGas, minimumGasRequired) + params.TxGas + + candidate.GasLimit = finalGasLimit } else { candidate.GasLimit = intrinsicGas } From 333f30de73e6e845d6403dcaaa1133ff520d0262 Mon Sep 17 00:00:00 2001 From: Krish Date: Fri, 14 Feb 2025 14:10:44 +0800 Subject: [PATCH 7/7] chore: use specific lint version --- .github/workflows/ci.yml | 16 ++++++++-------- op-chain-ops/cmd/check-derivation/main.go | 6 +++--- op-e2e/actions/l2_batcher.go | 4 ++-- op-e2e/actions/span_batch_test.go | 4 ++-- op-e2e/actions/sync_test.go | 2 +- op-e2e/brotli_batcher_test.go | 2 +- op-e2e/eip4844_test.go | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68ca8f229..81d0d7843 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,8 +23,8 @@ jobs: uses: golangci/golangci-lint-action@v3 with: working-directory: op-node - version: latest - args: -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" + version: v1.63.4 + args: -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 15m -e "errors.As" -e "errors.Is" op-batcher-lint: runs-on: ubuntu-latest @@ -42,8 +42,8 @@ jobs: uses: golangci/golangci-lint-action@v3 with: working-directory: op-batcher - version: latest - args: -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" + version: v1.63.4 + args: -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 15m -e "errors.As" -e "errors.Is" op-proposer-lint: runs-on: ubuntu-latest @@ -61,8 +61,8 @@ jobs: uses: golangci/golangci-lint-action@v3 with: working-directory: op-proposer - version: latest - args: -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" + version: v1.63.4 + args: -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 15m -e "errors.As" -e "errors.Is" op-service-lint: runs-on: ubuntu-latest @@ -80,8 +80,8 @@ jobs: uses: golangci/golangci-lint-action@v3 with: working-directory: op-service - version: latest - args: -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" + version: v1.63.4 + args: -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 15m -e "errors.As" -e "errors.Is" op-node-test: runs-on: ubuntu-latest diff --git a/op-chain-ops/cmd/check-derivation/main.go b/op-chain-ops/cmd/check-derivation/main.go index 62ec2b3e8..b867ea23a 100644 --- a/op-chain-ops/cmd/check-derivation/main.go +++ b/op-chain-ops/cmd/check-derivation/main.go @@ -225,7 +225,7 @@ func getRandomSignedTransaction(ctx context.Context, ethClient *ethclient.Client var txData types.TxData switch txType { case types.LegacyTxType: - gasLimit, err := core.IntrinsicGas(data, nil, nil, false, true, true, false) + gasLimit, err := core.IntrinsicGas(data, nil, nil, false, true, false, false) if err != nil { return nil, fmt.Errorf("failed to get intrinsicGas: %w", err) } @@ -242,7 +242,7 @@ func getRandomSignedTransaction(ctx context.Context, ethClient *ethclient.Client Address: randomAddress, StorageKeys: []common.Hash{common.HexToHash("0x1234")}, }} - gasLimit, err := core.IntrinsicGas(data, accessList, nil, false, true, true, false) + gasLimit, err := core.IntrinsicGas(data, accessList, nil, false, true, false, false) if err != nil { return nil, fmt.Errorf("failed to get intrinsicGas: %w", err) } @@ -257,7 +257,7 @@ func getRandomSignedTransaction(ctx context.Context, ethClient *ethclient.Client Data: data, } case types.DynamicFeeTxType: - gasLimit, err := core.IntrinsicGas(data, nil, nil, false, true, true, false) + gasLimit, err := core.IntrinsicGas(data, nil, nil, false, true, false, false) if err != nil { return nil, fmt.Errorf("failed to get intrinsicGas: %w", err) } diff --git a/op-e2e/actions/l2_batcher.go b/op-e2e/actions/l2_batcher.go index c114424c6..1a955f851 100644 --- a/op-e2e/actions/l2_batcher.go +++ b/op-e2e/actions/l2_batcher.go @@ -277,7 +277,7 @@ func (s *L2Batcher) ActL2BatchSubmit(t Testing, txOpts ...func(tx *types.Dynamic opt(rawTx) } - gas, err := core.IntrinsicGas(rawTx.Data, nil, nil, false, true, true, false) + gas, err := core.IntrinsicGas(rawTx.Data, nil, nil, false, true, false, false) require.NoError(t, err, "need to compute intrinsic gas") rawTx.Gas = gas txData = rawTx @@ -468,7 +468,7 @@ func (s *L2Batcher) ActL2BatchSubmitGarbage(t Testing, kind GarbageKind) { GasFeeCap: gasFeeCap, Data: outputFrame, } - gas, err := core.IntrinsicGas(rawTx.Data, nil, nil, false, true, true, false) + gas, err := core.IntrinsicGas(rawTx.Data, nil, nil, false, true, false, false) require.NoError(t, err, "need to compute intrinsic gas") rawTx.Gas = gas diff --git a/op-e2e/actions/span_batch_test.go b/op-e2e/actions/span_batch_test.go index 751bbd485..b3bc2d0d1 100644 --- a/op-e2e/actions/span_batch_test.go +++ b/op-e2e/actions/span_batch_test.go @@ -524,7 +524,7 @@ func TestSpanBatchLowThroughputChain(gt *testing.T) { data := make([]byte, rand.Intn(100)) _, err := crand.Read(data[:]) // fill with random bytes require.NoError(t, err) - gas, err := core.IntrinsicGas(data, nil, nil, false, true, true, false) + gas, err := core.IntrinsicGas(data, nil, nil, false, true, false, false) require.NoError(t, err) baseFee := seqEngine.l2Chain.CurrentBlock().BaseFee nonce, err := cl.PendingNonceAt(t.Ctx(), addrs[userIdx]) @@ -663,7 +663,7 @@ func TestBatchEquivalence(gt *testing.T) { data := make([]byte, rand.Intn(100)) _, err := crand.Read(data[:]) // fill with random bytes require.NoError(t, err) - gas, err := core.IntrinsicGas(data, nil, nil, false, true, true, false) + gas, err := core.IntrinsicGas(data, nil, nil, false, true, false, false) require.NoError(t, err) baseFee := seqEngine.l2Chain.CurrentBlock().BaseFee nonce, err := seqEngCl.PendingNonceAt(t.Ctx(), addrs[userIdx]) diff --git a/op-e2e/actions/sync_test.go b/op-e2e/actions/sync_test.go index 8af07f973..b856413f3 100644 --- a/op-e2e/actions/sync_test.go +++ b/op-e2e/actions/sync_test.go @@ -896,7 +896,7 @@ func TestInvalidPayloadInSpanBatch(gt *testing.T) { aliceNonce, err := seqEng.EthClient().PendingNonceAt(t.Ctx(), dp.Addresses.Alice) require.NoError(t, err) data := make([]byte, rand.Intn(100)) - gas, err := core.IntrinsicGas(data, nil, nil, false, true, true, false) + gas, err := core.IntrinsicGas(data, nil, nil, false, true, false, false) require.NoError(t, err) baseFee := seqEng.l2Chain.CurrentBlock().BaseFee tx := types.MustSignNewTx(dp.Secrets.Alice, signer, &types.DynamicFeeTx{ diff --git a/op-e2e/brotli_batcher_test.go b/op-e2e/brotli_batcher_test.go index 4b986f30d..c000a6f42 100644 --- a/op-e2e/brotli_batcher_test.go +++ b/op-e2e/brotli_batcher_test.go @@ -85,7 +85,7 @@ func TestBrotliBatcherFjord(t *testing.T) { opts.Value = big.NewInt(1_000_000_000) opts.Nonce = 1 // Already have deposit opts.ToAddr = &common.Address{0xff, 0xff} - opts.Gas, err = core.IntrinsicGas(opts.Data, nil, nil, false, true, true, false) + opts.Gas, err = core.IntrinsicGas(opts.Data, nil, nil, false, true, false, false) require.NoError(t, err) opts.VerifyOnClients(l2Verif) }) diff --git a/op-e2e/eip4844_test.go b/op-e2e/eip4844_test.go index ca6971de5..37b243ffb 100644 --- a/op-e2e/eip4844_test.go +++ b/op-e2e/eip4844_test.go @@ -102,7 +102,7 @@ func testSystem4844E2E(t *testing.T, multiBlob bool) { opts.ToAddr = &common.Address{0xff, 0xff} // put some random data in the tx to make it fill up 6 blobs (multi-blob case) opts.Data = testutils.RandomData(rand.New(rand.NewSource(420)), 400) - opts.Gas, err = core.IntrinsicGas(opts.Data, nil, nil, false, true, true, false) + opts.Gas, err = core.IntrinsicGas(opts.Data, nil, nil, false, true, false, false) require.NoError(t, err) opts.VerifyOnClients(l2Verif) })