Skip to content

Commit

Permalink
feat(taiko-client): introduce AccessList (#17676)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoGhurt111 committed Jun 26, 2024
1 parent fbeb4e4 commit 3c95477
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/taiko-client/proposer/transaction_builder/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -127,12 +128,27 @@ 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,
Blobs: []*eth.Blob{blob},
To: to,
GasLimit: b.gasLimit,
Value: maxFee,
AccessList: types.AccessList{
{
Address: b.taikoL1Address,
StorageKeys: slotHashes,
},
},
}, nil
}
17 changes: 17 additions & 0 deletions packages/taiko-client/proposer/transaction_builder/calldata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}

0 comments on commit 3c95477

Please sign in to comment.