Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(protocol): propose a batch blocks conditionally #18570

Merged
merged 12 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions packages/protocol/contracts/layer1/provers/ProverSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ interface IHasRecipient {
}

/// @title ProverSet
/// @notice A contract that holds TKO token and acts as a Taiko prover. This contract will simply
/// relay `proveBlock` calls to TaikoL1 so msg.sender doesn't need to hold any TKO.
/// @notice A contract that holds TAIKO token and acts as a Taiko prover. This contract will simply
/// relay `proveBlock` calls to TaikoL1 so msg.sender doesn't need to hold any TAIKO.
/// @custom:security-contact [email protected]
contract ProverSet is EssentialContract, IERC1271 {
bytes4 private constant _EIP1271_MAGICVALUE = 0x1626ba7e;
Expand Down Expand Up @@ -94,18 +94,19 @@ contract ProverSet is EssentialContract, IERC1271 {
LibAddress.sendEtherAndVerify(admin, _amount);
}

/// @notice Proposes a block only when it is the first block proposal in the current L1 block.
function proposeBlockV2Conditionally(
bytes calldata _params,
bytes calldata _txList
/// @notice Proposes a batch blocks only when it is the first batch blocks proposal in the
/// current L1 block.
function proposeBlocksV2Conditionally(
bytes[] calldata _params,
bytes[] calldata _txList
)
external
onlyProver
{
ITaikoL1 taiko = ITaikoL1(taikoL1());
// Ensure this block is the first block proposed in the current L1 block.
require(taiko.lastProposedIn() != block.number, NOT_FIRST_PROPOSAL());
taiko.proposeBlockV2(_params, _txList);
taiko.proposeBlocksV2(_params, _txList);
}

/// @notice Propose a Taiko block.
Expand Down
2 changes: 1 addition & 1 deletion packages/taiko-client/bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5b4b0cd271534aa72d865afa5fc55e0ee4b16b73
ab50d406172e879e7436c70a41bda674bfc6e441
44 changes: 22 additions & 22 deletions packages/taiko-client/bindings/gen_prover_set.go

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions packages/taiko-client/cmd/flags/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ var (
Value: false,
EnvVars: []string{"L1_BLOB_ALLOWED"},
}
RevertProtectionEnabled = &cli.BoolFlag{
Name: "revertProtection",
Usage: "Enable revert protection with the support of endpoint and contract",
Value: false,
Category: proposerCategory,
EnvVars: []string{"REVERT_PROTECTION"},
}
)

// ProposerFlags All proposer flags.
Expand All @@ -134,4 +141,5 @@ var ProposerFlags = MergeFlags(CommonFlags, []cli.Flag{
MaxProposedTxListsPerEpoch,
ProposeBlockIncludeParentMetaHash,
BlobAllowed,
RevertProtectionEnabled,
}, TxmgrFlags)
2 changes: 2 additions & 0 deletions packages/taiko-client/proposer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Config struct {
ProposeBlockTxGasLimit uint64
IncludeParentMetaHash bool
BlobAllowed bool
RevertProtectionEnabled bool
TxmgrConfigs *txmgr.CLIConfig
PrivateTxmgrConfigs *txmgr.CLIConfig
}
Expand Down Expand Up @@ -105,6 +106,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
ProposeBlockTxGasLimit: c.Uint64(flags.TxGasLimit.Name),
IncludeParentMetaHash: c.Bool(flags.ProposeBlockIncludeParentMetaHash.Name),
BlobAllowed: c.Bool(flags.BlobAllowed.Name),
RevertProtectionEnabled: c.Bool(flags.RevertProtectionEnabled.Name),
TxmgrConfigs: pkgFlags.InitTxmgrConfigsFromCli(
c.String(flags.L1WSEndpoint.Name),
l1ProposerPrivKey,
Expand Down
2 changes: 2 additions & 0 deletions packages/taiko-client/proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (p *Proposer) InitFromConfig(
cfg.ProposeBlockTxGasLimit,
cfg.ExtraData,
chainConfig,
cfg.RevertProtectionEnabled,
)
} else {
p.txBuilder = builder.NewCalldataTransactionBuilder(
Expand All @@ -140,6 +141,7 @@ func (p *Proposer) InitFromConfig(
cfg.ProposeBlockTxGasLimit,
cfg.ExtraData,
chainConfig,
cfg.RevertProtectionEnabled,
)
}

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 @@ -258,6 +258,7 @@ func (s *ProposerTestSuite) TestProposeTxLists() {
cfg.ProposeBlockTxGasLimit,
cfg.ExtraData,
config.NewChainConfig(s.p.protocolConfigs),
false,
)

emptyTxListBytes, err := rlp.EncodeToBytes(types.Transactions{})
Expand Down
9 changes: 8 additions & 1 deletion packages/taiko-client/proposer/transaction_builder/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type BlobTransactionBuilder struct {
gasLimit uint64
extraData string
chainConfig *config.ChainConfig
revertProtectionEnabled bool
}

// NewBlobTransactionBuilder creates a new BlobTransactionBuilder instance based on giving configurations.
Expand All @@ -42,6 +43,7 @@ func NewBlobTransactionBuilder(
gasLimit uint64,
extraData string,
chainConfig *config.ChainConfig,
revertProtectionEnabled bool,
) *BlobTransactionBuilder {
return &BlobTransactionBuilder{
rpc,
Expand All @@ -52,6 +54,7 @@ func NewBlobTransactionBuilder(
gasLimit,
extraData,
chainConfig,
revertProtectionEnabled,
}
}

Expand Down Expand Up @@ -190,7 +193,11 @@ func (b *BlobTransactionBuilder) BuildOntake(
}
txListArray := make([][]byte, len(encodedParamsArray))
if b.proverSetAddress != rpc.ZeroAddress {
data, err = encoding.ProverSetABI.Pack("proposeBlocksV2", encodedParamsArray, txListArray)
if b.revertProtectionEnabled {
data, err = encoding.ProverSetABI.Pack("proposeBlocksV2Conditionally", encodedParamsArray, txListArray)
} else {
data, err = encoding.ProverSetABI.Pack("proposeBlocksV2", encodedParamsArray, txListArray)
}
if err != nil {
return nil, err
}
Expand Down
10 changes: 8 additions & 2 deletions packages/taiko-client/proposer/transaction_builder/calldata.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type CalldataTransactionBuilder struct {
gasLimit uint64
extraData string
chainConfig *config.ChainConfig
revertProtectionEnabled bool
}

// NewCalldataTransactionBuilder creates a new CalldataTransactionBuilder instance based on giving configurations.
Expand All @@ -39,6 +40,7 @@ func NewCalldataTransactionBuilder(
gasLimit uint64,
extraData string,
chainConfig *config.ChainConfig,
revertProtectionEnabled bool,
) *CalldataTransactionBuilder {
return &CalldataTransactionBuilder{
rpc,
Expand All @@ -49,6 +51,7 @@ func NewCalldataTransactionBuilder(
gasLimit,
extraData,
chainConfig,
revertProtectionEnabled,
}
}

Expand Down Expand Up @@ -157,8 +160,11 @@ func (b *CalldataTransactionBuilder) BuildOntake(

if b.proverSetAddress != rpc.ZeroAddress {
to = &b.proverSetAddress

data, err = encoding.ProverSetABI.Pack("proposeBlocksV2", encodedParamsArray, txListBytesArray)
if b.revertProtectionEnabled {
data, err = encoding.ProverSetABI.Pack("proposeBlocksV2Conditionally", encodedParamsArray, txListBytesArray)
} else {
data, err = encoding.ProverSetABI.Pack("proposeBlocksV2", encodedParamsArray, txListBytesArray)
}
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (s *TransactionBuilderTestSuite) SetupTest() {
0,
"test",
chainConfig,
false,
)
s.blobTxBuiler = NewBlobTransactionBuilder(
s.RPCClient,
Expand All @@ -51,6 +52,7 @@ func (s *TransactionBuilderTestSuite) SetupTest() {
10_000_000,
"test",
chainConfig,
false,
)
}

Expand Down
Loading