Skip to content

Commit

Permalink
feat(protocol): allow msg.sender to customize block proposer addresses (
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Sep 9, 2024
1 parent a1ff620 commit 22055cc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ library TaikoData {
}

struct BlockParamsV2 {
address proposer;
address coinbase;
bytes32 parentMetaHash;
uint64 anchorBlockId; // NEW
Expand Down
3 changes: 0 additions & 3 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents {
)
external
payable
onlyFromOptionalNamed(LibStrings.B_BLOCK_PROPOSER)
whenNotPaused
nonReentrant
emitEventForClient
Expand All @@ -88,7 +87,6 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents {
bytes calldata _txList
)
external
onlyFromOptionalNamed(LibStrings.B_BLOCK_PROPOSER)
whenNotPaused
nonReentrant
emitEventForClient
Expand All @@ -105,7 +103,6 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents {
bytes[] calldata _txListArr
)
external
onlyFromOptionalNamed(LibStrings.B_BLOCK_PROPOSER)
whenNotPaused
nonReentrant
emitEventForClient
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/contracts/L1/libs/LibData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ library LibData {
returns (TaikoData.BlockParamsV2 memory)
{
return TaikoData.BlockParamsV2({
proposer: address(0),
coinbase: _v1.coinbase,
parentMetaHash: _v1.parentMetaHash,
anchorBlockId: 0,
Expand Down
26 changes: 21 additions & 5 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ library LibProposing {
ITierProvider tierProvider;
bytes32 parentMetaHash;
bool postFork;
bool allowCustomProposer;
bytes32 extraData;
}

Expand Down Expand Up @@ -51,6 +52,7 @@ library LibProposing {
error L1_BLOB_NOT_AVAILABLE();
error L1_BLOB_NOT_FOUND();
error L1_INVALID_ANCHOR_BLOCK();
error L1_INVALID_CUSTOM_PROPOSER();
error L1_INVALID_PARAMS();
error L1_INVALID_PROPOSER();
error L1_INVALID_TIMESTAMP();
Expand Down Expand Up @@ -148,19 +150,33 @@ library LibProposing {
revert L1_TOO_MANY_BLOCKS();
}

address permittedProposer = _resolver.resolve(LibStrings.B_BLOCK_PROPOSER, true);
if (permittedProposer != address(0)) {
require(permittedProposer == msg.sender, L1_INVALID_PROPOSER());
local.allowCustomProposer = true;
}

if (local.postFork) {
if (_params.length != 0) {
local.params = abi.decode(_params, (TaikoData.BlockParamsV2));
// otherwise use a default BlockParamsV2 with 0 values
}
} else {
TaikoData.BlockParams memory paramsV1 = abi.decode(_params, (TaikoData.BlockParams));
local.params = LibData.blockParamsV1ToV2(paramsV1);
local.extraData = paramsV1.extraData;
}

if (local.params.proposer == address(0)) {
local.params.proposer = msg.sender;
} else {
require(
local.params.proposer == msg.sender || local.allowCustomProposer,
L1_INVALID_CUSTOM_PROPOSER()
);
}

if (local.params.coinbase == address(0)) {
local.params.coinbase = msg.sender;
local.params.coinbase = local.params.proposer;
}

if (!local.postFork || local.params.anchorBlockId == 0) {
Expand Down Expand Up @@ -232,7 +248,7 @@ library LibProposing {
minTier: 0, // to be initialized below
blobUsed: _txList.length == 0,
parentMetaHash: local.params.parentMetaHash,
proposer: msg.sender,
proposer: local.params.proposer,
livenessBond: _config.livenessBond,
proposedAt: uint64(block.timestamp),
proposedIn: uint64(block.number),
Expand Down Expand Up @@ -294,7 +310,7 @@ library LibProposing {
++_state.slotB.numBlocks;
}

LibBonds.debitBond(_state, _resolver, msg.sender, _config.livenessBond);
LibBonds.debitBond(_state, _resolver, local.params.proposer, _config.livenessBond);

// Bribe the block builder. Unlike 1559-tips, this tip is only made
// if this transaction succeeds.
Expand All @@ -307,7 +323,7 @@ library LibProposing {
} else {
emit BlockProposed({
blockId: metaV1_.id,
assignedProver: msg.sender,
assignedProver: local.params.proposer,
livenessBond: _config.livenessBond,
meta: metaV1_,
depositsProcessed: new TaikoData.EthDeposit[](0)
Expand Down
4 changes: 3 additions & 1 deletion packages/protocol/test/L1/TaikoL1testGroupA2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract TaikoL1TestGroupA2 is TaikoL1TestGroupBase {

bytes32 parentHash = GENESIS_BLOCK_HASH;

proposeBlock(Alice, TaikoL1.L1_FORK_ERROR.selector);
proposeBlock(Alice, LibProposing.L1_INVALID_CUSTOM_PROPOSER.selector);

TaikoData.BlockParamsV2 memory params;
for (uint64 i = 1; i <= 5; ++i) {
Expand Down Expand Up @@ -102,6 +102,7 @@ contract TaikoL1TestGroupA2 is TaikoL1TestGroupBase {

// Propose the first block with default parameters
TaikoData.BlockParamsV2 memory params = TaikoData.BlockParamsV2({
proposer: address(0),
coinbase: address(0),
parentMetaHash: 0,
anchorBlockId: 0,
Expand Down Expand Up @@ -141,6 +142,7 @@ contract TaikoL1TestGroupA2 is TaikoL1TestGroupBase {
// Propose the second block with custom parameters

params = TaikoData.BlockParamsV2({
proposer: address(0),
coinbase: Bob,
parentMetaHash: 0,
anchorBlockId: 90,
Expand Down

0 comments on commit 22055cc

Please sign in to comment.