Skip to content

Commit

Permalink
feat(taiko-client): allow hooks to be empty if prover and proposer ar…
Browse files Browse the repository at this point in the history
…e the same address (#17520)
  • Loading branch information
davidtaikocha authored Jun 8, 2024
1 parent 9133eca commit 2db6d2c
Show file tree
Hide file tree
Showing 21 changed files with 214 additions and 214 deletions.
2 changes: 1 addition & 1 deletion packages/taiko-client/bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3ae25fdfc1452c0088afd2711dfbdbbefb670efc
13c3701bcc30e60f37856a0c837ffd58d284e9a2
30 changes: 30 additions & 0 deletions packages/taiko-client/bindings/gen_assignment_hook.go

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

2 changes: 1 addition & 1 deletion packages/taiko-client/bindings/gen_lib_proposing.go

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

197 changes: 43 additions & 154 deletions packages/taiko-client/bindings/gen_prover_set.go

Large diffs are not rendered by default.

39 changes: 5 additions & 34 deletions packages/taiko-client/bindings/gen_taiko_l1.go

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions packages/taiko-client/cmd/flags/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/cenkalti/backoff/v4"
"github.com/urfave/cli/v2"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/rpc"
)

var (
Expand Down Expand Up @@ -153,6 +155,13 @@ var (
Category: commonCategory,
EnvVars: []string{"ASSIGNMENT_HOOK_ADDRESS"},
}
ProverSetAddress = &cli.StringFlag{
Name: "proverSet",
Usage: "ProverSet contract `address`",
Value: rpc.ZeroAddress.Hex(),
Category: commonCategory,
EnvVars: []string{"PROVER_SET"},
}
)

// CommonFlags All common flags.
Expand All @@ -162,6 +171,7 @@ var CommonFlags = []cli.Flag{
TaikoL1Address,
TaikoL2Address,
// Optional
ProverSetAddress,
Verbosity,
LogJSON,
MetricsEnabled,
Expand Down
8 changes: 0 additions & 8 deletions packages/taiko-client/cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ var (

// Optional flags used by prover.
var (
ProverSetAddress = &cli.StringFlag{
Name: "proverSet",
Usage: "ProverSet contract `address`",
Value: rpc.ZeroAddress.Hex(),
Category: proverCategory,
EnvVars: []string{"PROVER_SET"},
}
RaikoHostEndpoint = &cli.StringFlag{
Name: "raiko.host",
Usage: "RPC endpoint of a Raiko host service",
Expand Down Expand Up @@ -215,7 +208,6 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
L1HTTPEndpoint,
L2WSEndpoint,
L2HTTPEndpoint,
ProverSetAddress,
RaikoHostEndpoint,
RaikoJWTPath,
L1ProverPrivKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (s *BlobSyncerTestSuite) initProposer() {
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
ProverSetAddress: common.HexToAddress(os.Getenv("PROVER_SET_ADDRESS")),
},
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
Expand Down
1 change: 1 addition & 0 deletions packages/taiko-client/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func (s *DriverTestSuite) InitProposer() {
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
ProverSetAddress: common.HexToAddress(os.Getenv("PROVER_SET_ADDRESS")),
},
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
Expand Down
45 changes: 45 additions & 0 deletions packages/taiko-client/internal/testutils/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (s *ClientTestSuite) SetupTest() {
// Increase allowance for AssignmentHook and TaikoL1
s.setAllowance(l1ProverPrivKey)
s.setAllowance(ownerPrivKey)
s.setAllowanceForProverSet(ownerPrivKey)

t, err := txmgr.NewSimpleTxManager(
"enableProver",
Expand Down Expand Up @@ -199,6 +200,50 @@ func (s *ClientTestSuite) setAllowance(key *ecdsa.PrivateKey) {
s.Nil(err)
}

func (s *ClientTestSuite) setAllowanceForProverSet(key *ecdsa.PrivateKey) {
t, err := txmgr.NewSimpleTxManager(
"setAllowanceForProverSet",
log.Root(),
new(metrics.NoopTxMetrics),
txmgr.CLIConfig{
L1RPCURL: os.Getenv("L1_NODE_WS_ENDPOINT"),
NumConfirmations: 0,
SafeAbortNonceTooLowCount: txmgr.DefaultBatcherFlagValues.SafeAbortNonceTooLowCount,
PrivateKey: common.Bytes2Hex(crypto.FromECDSA(key)),
FeeLimitMultiplier: txmgr.DefaultBatcherFlagValues.FeeLimitMultiplier,
FeeLimitThresholdGwei: txmgr.DefaultBatcherFlagValues.FeeLimitThresholdGwei,
MinBaseFeeGwei: txmgr.DefaultBatcherFlagValues.MinBaseFeeGwei,
MinTipCapGwei: txmgr.DefaultBatcherFlagValues.MinTipCapGwei,
ResubmissionTimeout: txmgr.DefaultBatcherFlagValues.ResubmissionTimeout,
ReceiptQueryInterval: 1 * time.Second,
NetworkTimeout: txmgr.DefaultBatcherFlagValues.NetworkTimeout,
TxSendTimeout: txmgr.DefaultBatcherFlagValues.TxSendTimeout,
TxNotInMempoolTimeout: txmgr.DefaultBatcherFlagValues.TxNotInMempoolTimeout,
},
)
s.Nil(err)

decimal, err := s.RPCClient.TaikoToken.Decimals(nil)
s.Nil(err)

var (
bigInt = new(big.Int).Exp(big.NewInt(1_000_000_000), new(big.Int).SetUint64(uint64(decimal)), nil)
proverSetAddress = common.HexToAddress(os.Getenv("PROVER_SET_ADDRESS"))
)

data, err := encoding.ProverSetABI.Pack(
"approveAllowance",
common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
bigInt,
)
s.Nil(err)
_, err = t.Send(context.Background(), txmgr.TxCandidate{
TxData: data,
To: &proverSetAddress,
})
s.Nil(err)
}

func (s *ClientTestSuite) TearDownTest() {
s.RevertL1Snapshot(s.testnetL1SnapshotID)

Expand Down
2 changes: 1 addition & 1 deletion packages/taiko-client/pkg/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func CheckProverBalance(
}

log.Info(
"Prover allowance for TaikoL1 contract",
"Prover allowance for the contract",
"allowance", utils.WeiToEther(allowance),
"address", prover.Hex(),
"bond", utils.WeiToEther(bond),
Expand Down
2 changes: 2 additions & 0 deletions packages/taiko-client/proposer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
type Config struct {
*rpc.ClientConfig
AssignmentHookAddress common.Address
ProverSetAddress common.Address
L1ProposerPrivKey *ecdsa.PrivateKey
L2SuggestedFeeRecipient common.Address
ExtraData string
Expand Down Expand Up @@ -106,6 +107,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
Timeout: c.Duration(flags.RPCTimeout.Name),
},
AssignmentHookAddress: common.HexToAddress(c.String(flags.AssignmentHookAddress.Name)),
ProverSetAddress: common.HexToAddress(c.String(flags.ProverSetAddress.Name)),
L1ProposerPrivKey: l1ProposerPrivKey,
L2SuggestedFeeRecipient: common.HexToAddress(l2SuggestedFeeRecipient),
ExtraData: c.String(flags.ExtraData.Name),
Expand Down
3 changes: 3 additions & 0 deletions packages/taiko-client/proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (p *Proposer) InitFromConfig(ctx context.Context, cfg *Config) (err error)
p.rpc,
p.proposerAddress,
cfg.TaikoL1Address,
cfg.ProverSetAddress,
cfg.AssignmentHookAddress,
p.tierFees,
cfg.TierFeePriceBump,
Expand All @@ -135,6 +136,7 @@ func (p *Proposer) InitFromConfig(ctx context.Context, cfg *Config) (err error)
p.proverSelector,
p.Config.L1BlockBuilderTip,
cfg.TaikoL1Address,
cfg.ProverSetAddress,
cfg.L2SuggestedFeeRecipient,
cfg.AssignmentHookAddress,
cfg.ProposeBlockTxGasLimit,
Expand All @@ -148,6 +150,7 @@ func (p *Proposer) InitFromConfig(ctx context.Context, cfg *Config) (err error)
p.Config.L1BlockBuilderTip,
cfg.L2SuggestedFeeRecipient,
cfg.TaikoL1Address,
cfg.ProverSetAddress,
cfg.AssignmentHookAddress,
cfg.ProposeBlockTxGasLimit,
cfg.ExtraData,
Expand Down
1 change: 1 addition & 0 deletions packages/taiko-client/proposer/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (s *ProposerTestSuite) TestProposeTxLists() {
p.proverSelector,
p.Config.L1BlockBuilderTip,
cfg.TaikoL1Address,
cfg.ProverSetAddress,
cfg.L2SuggestedFeeRecipient,
cfg.AssignmentHookAddress,
cfg.ProposeBlockTxGasLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ETHFeeEOASelector struct {
rpc *rpc.Client
proposerAddress common.Address
taikoL1Address common.Address
proverSetAddress common.Address
assignmentHookAddress common.Address
tiersFee []encoding.TierFee
tierFeePriceBump *big.Int
Expand All @@ -48,6 +49,7 @@ func NewETHFeeEOASelector(
rpc *rpc.Client,
proposerAddress common.Address,
taikoL1Address common.Address,
proverSetAddress common.Address,
assignmentHookAddress common.Address,
tiersFee []encoding.TierFee,
tierFeePriceBump *big.Int,
Expand All @@ -71,6 +73,7 @@ func NewETHFeeEOASelector(
rpc,
proposerAddress,
taikoL1Address,
proverSetAddress,
assignmentHookAddress,
tiersFee,
tierFeePriceBump,
Expand Down Expand Up @@ -137,11 +140,16 @@ func (s *ETHFeeEOASelector) AssignProver(
continue
}

spender := s.assignmentHookAddress
if s.proverSetAddress != rpc.ZeroAddress && s.proposerAddress == proverAddress {
spender = s.taikoL1Address
}

ok, err := rpc.CheckProverBalance(
ctx,
s.rpc,
proverAddress,
s.assignmentHookAddress,
spender,
s.protocolConfigs.LivenessBond,
)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (s *ProverSelectorTestSuite) SetupTest() {
crypto.PubkeyToAddress(l1ProposerPrivKey.PublicKey),
common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
common.HexToAddress(os.Getenv("PROVER_SET_ADDRESS")),
[]encoding.TierFee{},
common.Big2,
[]*url.URL{s.ProverEndpoints[0]},
Expand Down
31 changes: 25 additions & 6 deletions packages/taiko-client/proposer/transaction_builder/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type BlobTransactionBuilder struct {
proverSelector selector.ProverSelector
l1BlockBuilderTip *big.Int
taikoL1Address common.Address
proverSetAddress common.Address
l2SuggestedFeeRecipient common.Address
assignmentHookAddress common.Address
gasLimit uint64
Expand All @@ -38,6 +39,7 @@ func NewBlobTransactionBuilder(
proverSelector selector.ProverSelector,
l1BlockBuilderTip *big.Int,
taikoL1Address common.Address,
proverSetAddress common.Address,
l2SuggestedFeeRecipient common.Address,
assignmentHookAddress common.Address,
gasLimit uint64,
Expand All @@ -49,6 +51,7 @@ func NewBlobTransactionBuilder(
proverSelector,
l1BlockBuilderTip,
taikoL1Address,
proverSetAddress,
l2SuggestedFeeRecipient,
assignmentHookAddress,
gasLimit,
Expand Down Expand Up @@ -113,29 +116,45 @@ func (b *BlobTransactionBuilder) Build(
}
signature[64] = uint8(uint(signature[64])) + 27

var (
to = &b.taikoL1Address
hookCalls = []encoding.HookCall{{Hook: b.assignmentHookAddress, Data: hookInputData}}
data []byte
)
if b.proverSetAddress != rpc.ZeroAddress && b.assignmentHookAddress == rpc.ZeroAddress {
to = &b.proverSetAddress
hookCalls = []encoding.HookCall{}
}

// 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}},
HookCalls: hookCalls,
Signature: signature,
})
if err != nil {
return nil, err
}

// Send the transaction to the L1 node.
data, err := encoding.TaikoL1ABI.Pack("proposeBlock", encodedParams, []byte{})
if err != nil {
return nil, err
if b.proverSetAddress != rpc.ZeroAddress && b.assignmentHookAddress == rpc.ZeroAddress {
data, err = encoding.ProverSetABI.Pack("proposeBlock", encodedParams, []byte{})
if err != nil {
return nil, err
}
} else {
data, err = encoding.TaikoL1ABI.Pack("proposeBlock", encodedParams, []byte{})
if err != nil {
return nil, err
}
}

return &txmgr.TxCandidate{
TxData: data,
Blobs: []*eth.Blob{blob},
To: &b.taikoL1Address,
To: to,
GasLimit: b.gasLimit,
Value: maxFee,
}, nil
Expand Down
Loading

0 comments on commit 2db6d2c

Please sign in to comment.