From 8c7491ae1e2dbaaa9564b588729256e4fb70e1ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Mon, 3 Jun 2024 10:30:59 +0200 Subject: [PATCH 1/2] feat: update gas-oracle contract bytecode (#792) * feat: update gas-oracle contract bytecode * remove leading 0x --- params/version.go | 2 +- rollup/rcfg/config.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/params/version.go b/params/version.go index c2763fa62c1f..26ff900c37d7 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 3 // Minor version component of the current release - VersionPatch = 32 // Patch version component of the current release + VersionPatch = 33 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string ) diff --git a/rollup/rcfg/config.go b/rollup/rcfg/config.go index 005ca7d08833..8f7931b74585 100644 --- a/rollup/rcfg/config.go +++ b/rollup/rcfg/config.go @@ -42,10 +42,10 @@ var ( // CurieL1GasPriceOracleBytecode is the new (blob-enabled) gas price oracle after // the Curie hard fork. Run these commands in the monorepo to verify this bytecode: // - // git checkout 7059ad0ed465201287e06625dd4058c8ae9682b8 + // git checkout f12e8e3bafc09bb1c38065dfb57ae1f0fbe24915 // cd contracts // yarn // FOUNDRY_EVM_VERSION="cancun" forge build // cat artifacts/src/L1GasPriceOracle.sol/L1GasPriceOracle.json | jq -r .deployedBytecode.object - CurieL1GasPriceOracleBytecode = common.Hex2Bytes("608060405234801561000f575f80fd5b5060043610610132575f3560e01c8063715018a6116100b4578063a911d77f11610079578063a911d77f1461024c578063bede39b514610254578063de26c4a114610267578063e88a60ad1461027a578063f2fde38b1461028d578063f45e65d8146102a0575f80fd5b8063715018a6146101eb57806384189161146101f35780638da5cb5b146101fc57806393e59dc114610226578063944b247f14610239575f80fd5b80633d0f963e116100fa5780633d0f963e146101a057806349948e0e146101b3578063519b4bd3146101c65780636a5e67e5146101cf57806370465597146101d8575f80fd5b80630c18c1621461013657806313dad5be1461015257806323e524ac1461016f5780633577afc51461017857806339455d3a1461018d575b5f80fd5b61013f60025481565b6040519081526020015b60405180910390f35b60085461015f9060ff1681565b6040519015158152602001610149565b61013f60065481565b61018b6101863660046109c3565b6102a9565b005b61018b61019b3660046109da565b61033b565b61018b6101ae3660046109fa565b610438565b61013f6101c1366004610a3b565b6104bb565b61013f60015481565b61013f60075481565b61018b6101e63660046109c3565b6104e0565b61018b61056e565b61013f60055481565b5f5461020e906001600160a01b031681565b6040516001600160a01b039091168152602001610149565b60045461020e906001600160a01b031681565b61018b6102473660046109c3565b6105a2565b61018b610636565b61018b6102623660046109c3565b610692565b61013f610275366004610a3b565b61074f565b61018b6102883660046109c3565b61076c565b61018b61029b3660046109fa565b610800565b61013f60035481565b5f546001600160a01b031633146102db5760405162461bcd60e51b81526004016102d290610ae6565b60405180910390fd5b621c9c388111156102ff57604051635742c80560e11b815260040160405180910390fd5b60028190556040518181527f32740b35c0ea213650f60d44366b4fb211c9033b50714e4a1d34e65d5beb9bb4906020015b60405180910390a150565b6004805460405163efc7840160e01b815233928101929092526001600160a01b03169063efc7840190602401602060405180830381865afa158015610382573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103a69190610b1d565b6103c3576040516326b3506d60e11b815260040160405180910390fd5b600182905560058190556040518281527f351fb23757bb5ea0546c85b7996ddd7155f96b939ebaa5ff7bc49c75f27f2c449060200160405180910390a16040518181527f9a14bfb5d18c4c3cf14cae19c23d7cf1bcede357ea40ca1f75cd49542c71c214906020015b60405180910390a15050565b5f546001600160a01b031633146104615760405162461bcd60e51b81526004016102d290610ae6565b600480546001600160a01b038381166001600160a01b031983168117909355604080519190921680825260208201939093527f22d1c35fe072d2e42c3c8f9bd4a0d34aa84a0101d020a62517b33fdb3174e5f7910161042c565b6008545f9060ff16156104d7576104d18261088b565b92915050565b6104d1826108d1565b5f546001600160a01b031633146105095760405162461bcd60e51b81526004016102d290610ae6565b610519633b9aca006103e8610b50565b81111561053957604051631e44fdeb60e11b815260040160405180910390fd5b60038190556040518181527f3336cd9708eaf2769a0f0dc0679f30e80f15dcd88d1921b5a16858e8b85c591a90602001610330565b5f546001600160a01b031633146105975760405162461bcd60e51b81526004016102d290610ae6565b6105a05f610914565b565b5f546001600160a01b031633146105cb5760405162461bcd60e51b81526004016102d290610ae6565b6105e1633b9aca00670de0b6b3a7640000610b50565b8111156106015760405163874f603160e01b815260040160405180910390fd5b60068190556040518181527f2ab3f5a4ebbcbf3c24f62f5454f52f10e1a8c9dcc5acac8f19199ce881a6a10890602001610330565b5f546001600160a01b0316331461065f5760405162461bcd60e51b81526004016102d290610ae6565b60085460ff1615610683576040516379f9c57560e01b815260040160405180910390fd5b6008805460ff19166001179055565b6004805460405163efc7840160e01b815233928101929092526001600160a01b03169063efc7840190602401602060405180830381865afa1580156106d9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106fd9190610b1d565b61071a576040516326b3506d60e11b815260040160405180910390fd5b60018190556040518181527f351fb23757bb5ea0546c85b7996ddd7155f96b939ebaa5ff7bc49c75f27f2c4490602001610330565b6008545f9060ff161561076357505f919050565b6104d182610963565b5f546001600160a01b031633146107955760405162461bcd60e51b81526004016102d290610ae6565b6107ab633b9aca00670de0b6b3a7640000610b50565b8111156107cb5760405163f37ec21560e01b815260040160405180910390fd5b60078190556040518181527f6b332a036d8c3ead57dcb06c87243bd7a2aed015ddf2d0528c2501dae56331aa90602001610330565b5f546001600160a01b031633146108295760405162461bcd60e51b81526004016102d290610ae6565b6001600160a01b03811661087f5760405162461bcd60e51b815260206004820152601d60248201527f6e6577206f776e657220697320746865207a65726f206164647265737300000060448201526064016102d2565b61088881610914565b50565b5f633b9aca0060055483516007546108a39190610b50565b6108ad9190610b50565b6001546006546108bd9190610b50565b6108c79190610b67565b6104d19190610b7a565b5f806108dc83610963565b90505f600154826108ed9190610b50565b9050633b9aca00600354826109029190610b50565b61090c9190610b7a565b949350505050565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80515f908190815b818110156109b45784818151811061098557610985610b99565b01602001516001600160f81b0319165f036109a5576004830192506109ac565b6010830192505b60010161096b565b50506002540160400192915050565b5f602082840312156109d3575f80fd5b5035919050565b5f80604083850312156109eb575f80fd5b50508035926020909101359150565b5f60208284031215610a0a575f80fd5b81356001600160a01b0381168114610a20575f80fd5b9392505050565b634e487b7160e01b5f52604160045260245ffd5b5f60208284031215610a4b575f80fd5b813567ffffffffffffffff80821115610a62575f80fd5b818401915084601f830112610a75575f80fd5b813581811115610a8757610a87610a27565b604051601f8201601f19908116603f01168101908382118183101715610aaf57610aaf610a27565b81604052828152876020848701011115610ac7575f80fd5b826020860160208301375f928101602001929092525095945050505050565b60208082526017908201527f63616c6c6572206973206e6f7420746865206f776e6572000000000000000000604082015260600190565b5f60208284031215610b2d575f80fd5b81518015158114610a20575f80fd5b634e487b7160e01b5f52601160045260245ffd5b80820281158282048414176104d1576104d1610b3c565b808201808211156104d1576104d1610b3c565b5f82610b9457634e487b7160e01b5f52601260045260245ffd5b500490565b634e487b7160e01b5f52603260045260245ffdfea26469706673582212206579d545ea4839464c2fd4ba9a7e6a4f4fee1cc1b51182da675c0f0c05fc161964736f6c63430008180033") + CurieL1GasPriceOracleBytecode = common.Hex2Bytes("608060405234801561000f575f80fd5b5060043610610132575f3560e01c8063715018a6116100b4578063a911d77f11610079578063a911d77f1461024c578063bede39b514610254578063de26c4a114610267578063e88a60ad1461027a578063f2fde38b1461028d578063f45e65d8146102a0575f80fd5b8063715018a6146101eb57806384189161146101f35780638da5cb5b146101fc57806393e59dc114610226578063944b247f14610239575f80fd5b80633d0f963e116100fa5780633d0f963e146101a057806349948e0e146101b3578063519b4bd3146101c65780636a5e67e5146101cf57806370465597146101d8575f80fd5b80630c18c1621461013657806313dad5be1461015257806323e524ac1461016f5780633577afc51461017857806339455d3a1461018d575b5f80fd5b61013f60025481565b6040519081526020015b60405180910390f35b60085461015f9060ff1681565b6040519015158152602001610149565b61013f60065481565b61018b6101863660046109b3565b6102a9565b005b61018b61019b3660046109ca565b61033b565b61018b6101ae3660046109ea565b610438565b61013f6101c1366004610a2b565b6104bb565b61013f60015481565b61013f60075481565b61018b6101e63660046109b3565b6104e0565b61018b61056e565b61013f60055481565b5f5461020e906001600160a01b031681565b6040516001600160a01b039091168152602001610149565b60045461020e906001600160a01b031681565b61018b6102473660046109b3565b6105a2565b61018b61062e565b61018b6102623660046109b3565b61068a565b61013f610275366004610a2b565b610747565b61018b6102883660046109b3565b610764565b61018b61029b3660046109ea565b6107f0565b61013f60035481565b5f546001600160a01b031633146102db5760405162461bcd60e51b81526004016102d290610ad6565b60405180910390fd5b621c9c388111156102ff57604051635742c80560e11b815260040160405180910390fd5b60028190556040518181527f32740b35c0ea213650f60d44366b4fb211c9033b50714e4a1d34e65d5beb9bb4906020015b60405180910390a150565b6004805460405163efc7840160e01b815233928101929092526001600160a01b03169063efc7840190602401602060405180830381865afa158015610382573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103a69190610b0d565b6103c3576040516326b3506d60e11b815260040160405180910390fd5b600182905560058190556040518281527f351fb23757bb5ea0546c85b7996ddd7155f96b939ebaa5ff7bc49c75f27f2c449060200160405180910390a16040518181527f9a14bfb5d18c4c3cf14cae19c23d7cf1bcede357ea40ca1f75cd49542c71c214906020015b60405180910390a15050565b5f546001600160a01b031633146104615760405162461bcd60e51b81526004016102d290610ad6565b600480546001600160a01b038381166001600160a01b031983168117909355604080519190921680825260208201939093527f22d1c35fe072d2e42c3c8f9bd4a0d34aa84a0101d020a62517b33fdb3174e5f7910161042c565b6008545f9060ff16156104d7576104d18261087b565b92915050565b6104d1826108c1565b5f546001600160a01b031633146105095760405162461bcd60e51b81526004016102d290610ad6565b610519633b9aca006103e8610b40565b81111561053957604051631e44fdeb60e11b815260040160405180910390fd5b60038190556040518181527f3336cd9708eaf2769a0f0dc0679f30e80f15dcd88d1921b5a16858e8b85c591a90602001610330565b5f546001600160a01b031633146105975760405162461bcd60e51b81526004016102d290610ad6565b6105a05f610904565b565b5f546001600160a01b031633146105cb5760405162461bcd60e51b81526004016102d290610ad6565b6105d9633b9aca0080610b40565b8111156105f95760405163874f603160e01b815260040160405180910390fd5b60068190556040518181527f2ab3f5a4ebbcbf3c24f62f5454f52f10e1a8c9dcc5acac8f19199ce881a6a10890602001610330565b5f546001600160a01b031633146106575760405162461bcd60e51b81526004016102d290610ad6565b60085460ff161561067b576040516379f9c57560e01b815260040160405180910390fd5b6008805460ff19166001179055565b6004805460405163efc7840160e01b815233928101929092526001600160a01b03169063efc7840190602401602060405180830381865afa1580156106d1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106f59190610b0d565b610712576040516326b3506d60e11b815260040160405180910390fd5b60018190556040518181527f351fb23757bb5ea0546c85b7996ddd7155f96b939ebaa5ff7bc49c75f27f2c4490602001610330565b6008545f9060ff161561075b57505f919050565b6104d182610953565b5f546001600160a01b0316331461078d5760405162461bcd60e51b81526004016102d290610ad6565b61079b633b9aca0080610b40565b8111156107bb5760405163f37ec21560e01b815260040160405180910390fd5b60078190556040518181527f6b332a036d8c3ead57dcb06c87243bd7a2aed015ddf2d0528c2501dae56331aa90602001610330565b5f546001600160a01b031633146108195760405162461bcd60e51b81526004016102d290610ad6565b6001600160a01b03811661086f5760405162461bcd60e51b815260206004820152601d60248201527f6e6577206f776e657220697320746865207a65726f206164647265737300000060448201526064016102d2565b61087881610904565b50565b5f633b9aca0060055483516007546108939190610b40565b61089d9190610b40565b6001546006546108ad9190610b40565b6108b79190610b57565b6104d19190610b6a565b5f806108cc83610953565b90505f600154826108dd9190610b40565b9050633b9aca00600354826108f29190610b40565b6108fc9190610b6a565b949350505050565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80515f908190815b818110156109a45784818151811061097557610975610b89565b01602001516001600160f81b0319165f036109955760048301925061099c565b6010830192505b60010161095b565b50506002540160400192915050565b5f602082840312156109c3575f80fd5b5035919050565b5f80604083850312156109db575f80fd5b50508035926020909101359150565b5f602082840312156109fa575f80fd5b81356001600160a01b0381168114610a10575f80fd5b9392505050565b634e487b7160e01b5f52604160045260245ffd5b5f60208284031215610a3b575f80fd5b813567ffffffffffffffff80821115610a52575f80fd5b818401915084601f830112610a65575f80fd5b813581811115610a7757610a77610a17565b604051601f8201601f19908116603f01168101908382118183101715610a9f57610a9f610a17565b81604052828152876020848701011115610ab7575f80fd5b826020860160208301375f928101602001929092525095945050505050565b60208082526017908201527f63616c6c6572206973206e6f7420746865206f776e6572000000000000000000604082015260600190565b5f60208284031215610b1d575f80fd5b81518015158114610a10575f80fd5b634e487b7160e01b5f52601160045260245ffd5b80820281158282048414176104d1576104d1610b2c565b808201808211156104d1576104d1610b2c565b5f82610b8457634e487b7160e01b5f52601260045260245ffd5b500490565b634e487b7160e01b5f52603260045260245ffdfea26469706673582212200c2ac583f18be4f94ab169ae6f2ea3a708a7c0d4424746b120b177adb39e626064736f6c63430008180033") ) From 9ec83a509ac7f6dd2d0beb054eb14c19f3e67a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Mon, 3 Jun 2024 16:24:03 +0200 Subject: [PATCH 2/2] fix: use correct encoding for L1 data fee of EIP2718 transactions (#793) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: use correct encoding for L1 data fee of EIP2718 transactions * add tests * lint * Update rollup/fees/rollup_fee.go Co-authored-by: Ömer Faruk Irmak --------- Co-authored-by: Ömer Faruk Irmak --- core/types/transaction.go | 1 - core/types/transaction_test.go | 38 ++++++++++++++++++++++++++++++++-- params/version.go | 2 +- rollup/fees/rollup_fee.go | 22 ++++++++------------ 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/core/types/transaction.go b/core/types/transaction.go index 12b6ecc47f44..875ed8e622db 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -40,7 +40,6 @@ var ( ErrInvalidTxType = errors.New("transaction type not valid in this context") ErrTxTypeNotSupported = errors.New("transaction type not supported") ErrGasFeeCapTooLow = errors.New("fee cap less than base fee") - errEmptyTypedTx = errors.New("empty typed transaction bytes") errShortTypedTx = errors.New("typed transaction too short") errInvalidYParity = errors.New("'yParity' field must be 0 or 1") errVYParityMismatch = errors.New("'v' and 'yParity' fields do not match") diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go index 417bc546f70b..60ef48aa4608 100644 --- a/core/types/transaction_test.go +++ b/core/types/transaction_test.go @@ -78,7 +78,7 @@ func TestDecodeEmptyTypedTx(t *testing.T) { input := []byte{0x80} var tx Transaction err := rlp.DecodeBytes(input, &tx) - if err != errEmptyTypedTx { + if err != errShortTypedTx { t.Fatal("wrong error:", err) } } @@ -94,11 +94,33 @@ func TestTransactionSigHash(t *testing.T) { } func TestTransactionEncode(t *testing.T) { + should := common.FromHex("f86103018207d094b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a8255441ca098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa08887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3") + + // EncodeToBytes txb, err := rlp.EncodeToBytes(rightvrsTx) if err != nil { t.Fatalf("encode error: %v", err) } - should := common.FromHex("f86103018207d094b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a8255441ca098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa08887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3") + if !bytes.Equal(txb, should) { + t.Errorf("encoded RLP mismatch, got %x", txb) + } + + // tx.EncodeRLP + raw := new(bytes.Buffer) + err = rightvrsTx.EncodeRLP(raw) + if err != nil { + t.Fatalf("encode error: %v", err) + } + txb = raw.Bytes() + if !bytes.Equal(txb, should) { + t.Errorf("encoded RLP mismatch, got %x", txb) + } + + // tx.MarshalBinary + txb, err = rightvrsTx.MarshalBinary() + if err != nil { + t.Fatalf("encode error: %v", err) + } if !bytes.Equal(txb, should) { t.Errorf("encoded RLP mismatch, got %x", txb) } @@ -194,6 +216,7 @@ func TestEIP2930Signer(t *testing.T) { func TestEIP2718TransactionEncode(t *testing.T) { // RLP representation { + // rlp.EncodeToBytes have, err := rlp.EncodeToBytes(signedEip2718Tx) if err != nil { t.Fatalf("encode error: %v", err) @@ -202,6 +225,17 @@ func TestEIP2718TransactionEncode(t *testing.T) { if !bytes.Equal(have, want) { t.Errorf("encoded RLP mismatch, got %x", have) } + + // tx.EncodeRLP + raw := new(bytes.Buffer) + err = signedEip2718Tx.EncodeRLP(raw) + if err != nil { + t.Fatalf("encode error: %v", err) + } + have = raw.Bytes() + if !bytes.Equal(have, want) { + t.Errorf("encoded RLP mismatch, got %x", have) + } } // Binary representation { diff --git a/params/version.go b/params/version.go index 26ff900c37d7..766652cc48c3 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 3 // Minor version component of the current release - VersionPatch = 33 // Patch version component of the current release + VersionPatch = 34 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string ) diff --git a/rollup/fees/rollup_fee.go b/rollup/fees/rollup_fee.go index 7eb110939420..9df6c215c5cf 100644 --- a/rollup/fees/rollup_fee.go +++ b/rollup/fees/rollup_fee.go @@ -2,6 +2,7 @@ package fees import ( "bytes" + "math" "math/big" "github.com/scroll-tech/go-ethereum/common" @@ -40,7 +41,6 @@ type Message interface { // required to compute the L1 fee type StateDB interface { GetState(common.Address, common.Hash) common.Hash - GetBalance(addr common.Address) *big.Int } type gpoState struct { @@ -64,7 +64,7 @@ func EstimateL1DataFeeForMessage(msg Message, baseFee *big.Int, config *params.C return nil, err } - raw, err := rlpEncode(tx) + raw, err := tx.MarshalBinary() if err != nil { return nil, err } @@ -133,16 +133,6 @@ func asUnsignedDynamicTx(msg Message, chainID *big.Int) *types.Transaction { }) } -// rlpEncode RLP encodes the transaction into bytes -func rlpEncode(tx *types.Transaction) ([]byte, error) { - raw := new(bytes.Buffer) - if err := tx.EncodeRLP(raw); err != nil { - return nil, err - } - - return raw.Bytes(), nil -} - func readGPOStorageSlots(addr common.Address, state StateDB) gpoState { var gpoState gpoState gpoState.l1BaseFee = state.GetState(addr, rcfg.L1BaseFeeSlot).Big() @@ -216,7 +206,7 @@ func CalculateL1DataFee(tx *types.Transaction, state StateDB, config *params.Cha return big.NewInt(0), nil } - raw, err := rlpEncode(tx) + raw, err := tx.MarshalBinary() if err != nil { return nil, err } @@ -231,6 +221,12 @@ func CalculateL1DataFee(tx *types.Transaction, state StateDB, config *params.Cha l1DataFee = calculateEncodedL1DataFeeCurie(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.commitScalar, gpoState.blobScalar) } + // ensure l1DataFee fits into uint64 for circuit compatibility + // (note: in practice this value should never be this big) + if !l1DataFee.IsUint64() { + l1DataFee.SetUint64(math.MaxUint64) + } + return l1DataFee, nil }