From 3c95477a284ac94c7e3ce85c9cefdadc1aaacd06 Mon Sep 17 00:00:00 2001 From: Gavin Yu Date: Wed, 26 Jun 2024 10:03:15 +0800 Subject: [PATCH] feat(taiko-client): introduce `AccessList` (#17676) --- .../proposer/transaction_builder/blob.go | 16 ++++++++++++++++ .../proposer/transaction_builder/calldata.go | 17 +++++++++++++++++ .../proof_submitter/transaction/builder.go | 19 +++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/packages/taiko-client/proposer/transaction_builder/blob.go b/packages/taiko-client/proposer/transaction_builder/blob.go index 2dda18194d6..6a4e83f5ffe 100644 --- a/packages/taiko-client/proposer/transaction_builder/blob.go +++ b/packages/taiko-client/proposer/transaction_builder/blob.go @@ -9,6 +9,7 @@ import ( "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/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto/kzg4844" @@ -127,6 +128,15 @@ func (b *BlobTransactionBuilder) Build( return nil, err } } + // Calculate TaikoData.State slot hash (includes slot 0-6 currently) + var slotHashes []common.Hash + for i := 0; i < 7; i++ { + packedData := append( + common.LeftPadBytes(b.taikoL1Address.Bytes(), 32), + common.LeftPadBytes(big.NewInt(int64(i)).Bytes(), 32)..., + ) + slotHashes = append(slotHashes, crypto.Keccak256Hash(packedData)) + } return &txmgr.TxCandidate{ TxData: data, @@ -134,5 +144,11 @@ func (b *BlobTransactionBuilder) Build( To: to, GasLimit: b.gasLimit, Value: maxFee, + AccessList: types.AccessList{ + { + Address: b.taikoL1Address, + StorageKeys: slotHashes, + }, + }, }, nil } diff --git a/packages/taiko-client/proposer/transaction_builder/calldata.go b/packages/taiko-client/proposer/transaction_builder/calldata.go index 5fef780f53a..71686463105 100644 --- a/packages/taiko-client/proposer/transaction_builder/calldata.go +++ b/packages/taiko-client/proposer/transaction_builder/calldata.go @@ -7,6 +7,7 @@ import ( "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/encoding" @@ -114,11 +115,27 @@ func (b *CalldataTransactionBuilder) Build( } } + // Calculate TaikoData.State slot hash (includes slot 0-6 currently) + var slotHashes []common.Hash + for i := 0; i < 7; i++ { + packedData := append( + common.LeftPadBytes(b.taikoL1Address.Bytes(), 32), + common.LeftPadBytes(big.NewInt(int64(i)).Bytes(), 32)..., + ) + slotHashes = append(slotHashes, crypto.Keccak256Hash(packedData)) + } + return &txmgr.TxCandidate{ TxData: data, Blobs: nil, To: to, GasLimit: b.gasLimit, Value: maxFee, + AccessList: types.AccessList{ + { + Address: b.taikoL1Address, + StorageKeys: slotHashes, + }, + }, }, nil } diff --git a/packages/taiko-client/prover/proof_submitter/transaction/builder.go b/packages/taiko-client/prover/proof_submitter/transaction/builder.go index 86b2104e90c..33ea11d9681 100644 --- a/packages/taiko-client/prover/proof_submitter/transaction/builder.go +++ b/packages/taiko-client/prover/proof_submitter/transaction/builder.go @@ -5,9 +5,12 @@ import ( "fmt" "math/big" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" "github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings" @@ -102,12 +105,28 @@ func (a *ProveBlockTxBuilder) Build( } } + // Calculate TaikoData.State slot hash (includes slot 0-6 currently) + var slotHashes []common.Hash + for i := 0; i < 7; i++ { + packedData := append( + common.LeftPadBytes(a.taikoL1Address.Bytes(), 32), + common.LeftPadBytes(big.NewInt(int64(i)).Bytes(), 32)..., + ) + slotHashes = append(slotHashes, crypto.Keccak256Hash(packedData)) + } + return &txmgr.TxCandidate{ TxData: data, To: &to, Blobs: nil, GasLimit: txOpts.GasLimit, Value: txOpts.Value, + AccessList: types.AccessList{ + { + Address: a.taikoL1Address, + StorageKeys: slotHashes, + }, + }, }, nil } }