Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat: changes based on protocol PR 16641
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Apr 4, 2024
1 parent 7e99d21 commit 70f9b48
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2c311e1aea456bca815f8cbbe42b2f5810d0db9f
b853c08eb82cf93bba81b51169c1add8b42f4b09
4 changes: 4 additions & 0 deletions bindings/encoding/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ var (
},
},
},
{
Name: "signature",
Type: "bytes",
},
}
proverAssignmentComponents = []abi.ArgumentMarshaling{
{
Expand Down
1 change: 1 addition & 0 deletions bindings/encoding/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type BlockParams struct {
ExtraData [32]byte
ParentMetaHash [32]byte
HookCalls []HookCall
Signature []byte
}

// TierFee should be same with TaikoData.TierFee.
Expand Down
2 changes: 1 addition & 1 deletion bindings/gen_lib_proposing.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bindings/gen_taiko_l1.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func (p *Proposer) InitFromConfig(ctx context.Context, cfg *Config) (err error)
if cfg.BlobAllowed {
p.txBuilder = builder.NewBlobTransactionBuilder(
p.rpc,
p.L1ProposerPrivKey,
p.proverSelector,
p.Config.L1BlockBuilderTip,
cfg.TaikoL1Address,
Expand All @@ -143,6 +144,7 @@ func (p *Proposer) InitFromConfig(ctx context.Context, cfg *Config) (err error)
} else {
p.txBuilder = builder.NewCalldataTransactionBuilder(
p.rpc,
p.L1ProposerPrivKey,
p.proverSelector,
p.Config.L1BlockBuilderTip,
cfg.L2SuggestedFeeRecipient,
Expand Down
20 changes: 20 additions & 0 deletions proposer/transaction_builder/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package builder

import (
"context"
"crypto/ecdsa"
"crypto/sha256"
"math/big"

"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/crypto"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/taikoxyz/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-client/pkg/rpc"
selector "github.com/taikoxyz/taiko-client/proposer/prover_selector"
Expand All @@ -16,6 +20,7 @@ import (
// bytes saved in blob.
type BlobTransactionBuilder struct {
rpc *rpc.Client
proposerPrivateKey *ecdsa.PrivateKey
proverSelector selector.ProverSelector
l1BlockBuilderTip *big.Int
taikoL1Address common.Address
Expand All @@ -28,6 +33,7 @@ type BlobTransactionBuilder struct {
// NewBlobTransactionBuilder creates a new BlobTransactionBuilder instance based on giving configurations.
func NewBlobTransactionBuilder(
rpc *rpc.Client,
proposerPrivateKey *ecdsa.PrivateKey,
proverSelector selector.ProverSelector,
l1BlockBuilderTip *big.Int,
taikoL1Address common.Address,
Expand All @@ -38,6 +44,7 @@ func NewBlobTransactionBuilder(
) *BlobTransactionBuilder {
return &BlobTransactionBuilder{
rpc,
proposerPrivateKey,
proverSelector,
l1BlockBuilderTip,
taikoL1Address,
Expand Down Expand Up @@ -93,13 +100,26 @@ func (b *BlobTransactionBuilder) Build(
return nil, err
}

commitment, err := blob.ComputeKZGCommitment()
if err != nil {
return nil, err
}
blobHash := kzg4844.CalcBlobHashV1(sha256.New(), &commitment)

signature, err := crypto.Sign(blobHash[:], b.proposerPrivateKey)
if err != nil {
return nil, err
}
signature[64] = uint8(uint(signature[64])) + 27

// ABI encode the TaikoL1.proposeBlock parameters.
encodedParams, err := encoding.EncodeBlockParams(&encoding.BlockParams{
AssignedProver: assignedProver,
ExtraData: rpc.StringToBytes32(b.extraData),
Coinbase: b.l2SuggestedFeeRecipient,
ParentMetaHash: parentMetaHash,
HookCalls: []encoding.HookCall{{Hook: b.assignmentHookAddress, Data: hookInputData}},
Signature: signature,
})
if err != nil {
return nil, err
Expand Down
11 changes: 11 additions & 0 deletions proposer/transaction_builder/calldata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package builder

import (
"context"
"crypto/ecdsa"
"math/big"

"github.com/ethereum-optimism/optimism/op-service/txmgr"
Expand All @@ -17,6 +18,7 @@ import (
// bytes saved in calldata.
type CalldataTransactionBuilder struct {
rpc *rpc.Client
proposerPrivateKey *ecdsa.PrivateKey
proverSelector selector.ProverSelector
l1BlockBuilderTip *big.Int
l2SuggestedFeeRecipient common.Address
Expand All @@ -29,6 +31,7 @@ type CalldataTransactionBuilder struct {
// NewCalldataTransactionBuilder creates a new CalldataTransactionBuilder instance based on giving configurations.
func NewCalldataTransactionBuilder(
rpc *rpc.Client,
proposerPrivateKey *ecdsa.PrivateKey,
proverSelector selector.ProverSelector,
l1BlockBuilderTip *big.Int,
l2SuggestedFeeRecipient common.Address,
Expand All @@ -39,6 +42,7 @@ func NewCalldataTransactionBuilder(
) *CalldataTransactionBuilder {
return &CalldataTransactionBuilder{
rpc,
proposerPrivateKey,
proverSelector,
l1BlockBuilderTip,
l2SuggestedFeeRecipient,
Expand Down Expand Up @@ -83,13 +87,20 @@ func (b *CalldataTransactionBuilder) Build(
return nil, err
}

signature, err := crypto.Sign(crypto.Keccak256(txListBytes), b.proposerPrivateKey)
if err != nil {
return nil, err
}
signature[64] = uint8(uint(signature[64])) + 27

// ABI encode the TaikoL1.proposeBlock parameters.
encodedParams, err := encoding.EncodeBlockParams(&encoding.BlockParams{
AssignedProver: assignedProver,
Coinbase: b.l2SuggestedFeeRecipient,
ExtraData: rpc.StringToBytes32(b.extraData),
ParentMetaHash: parentMetaHash,
HookCalls: []encoding.HookCall{{Hook: b.assignmentHookAddress, Data: hookInputData}},
Signature: signature,
})
if err != nil {
return nil, err
Expand Down
6 changes: 6 additions & 0 deletions proposer/transaction_builder/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/suite"

"github.com/taikoxyz/taiko-client/bindings/encoding"
Expand All @@ -27,6 +28,9 @@ func (s *TransactionBuilderTestSuite) SetupTest() {
protocolConfigs, err := s.RPCClient.TaikoL1.GetConfig(nil)
s.Nil(err)

l1ProposerPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROPOSER_PRIVATE_KEY")))
s.Nil(err)

proverSelector, err := selector.NewETHFeeEOASelector(
&protocolConfigs,
s.RPCClient,
Expand All @@ -42,6 +46,7 @@ func (s *TransactionBuilderTestSuite) SetupTest() {
s.Nil(err)
s.calldataTxBuilder = NewCalldataTransactionBuilder(
s.RPCClient,
l1ProposerPrivKey,
proverSelector,
common.Big0,
common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
Expand All @@ -52,6 +57,7 @@ func (s *TransactionBuilderTestSuite) SetupTest() {
)
s.blobTxBuiler = NewBlobTransactionBuilder(
s.RPCClient,
l1ProposerPrivKey,
proverSelector,
common.Big0,
common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
Expand Down

0 comments on commit 70f9b48

Please sign in to comment.