Skip to content

Commit

Permalink
fix(protocol): check ontake for height in _proposeBlock (#18329)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Oct 28, 2024
1 parent 290a9f9 commit eb47f88
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/protocol/contracts/layer1/based/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ library LibProposing {

error L1_BLOB_NOT_AVAILABLE();
error L1_BLOB_NOT_FOUND();
error L1_FORK_HEIGHT_ERROR();
error L1_INVALID_ANCHOR_BLOCK();
error L1_INVALID_CUSTOM_PROPOSER();
error L1_INVALID_PARAMS();
Expand Down Expand Up @@ -130,9 +131,11 @@ library LibProposing {
// It's essential to ensure that the ring buffer for proposed blocks still has space for at
// least one more block.
unchecked {
if (local.b.numBlocks >= local.b.lastVerifiedBlockId + _config.blockMaxProposals + 1) {
revert L1_TOO_MANY_BLOCKS();
}
require(local.b.numBlocks >= _config.ontakeForkHeight, L1_FORK_HEIGHT_ERROR());
require(
local.b.numBlocks < local.b.lastVerifiedBlockId + _config.blockMaxProposals + 1,
L1_TOO_MANY_BLOCKS()
);
}

address preconfTaskManager = _resolver.resolve(LibStrings.B_PRECONF_TASK_MANAGER, true);
Expand Down
6 changes: 6 additions & 0 deletions packages/protocol/contracts/layer1/based/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents {

uint256[50] private __gap;

error L1_FORK_HEIGHT_ERROR();

modifier whenProvingNotPaused() {
if (state.slotB.provingPaused) revert LibProving.L1_PROVING_PAUSED();
_;
Expand Down Expand Up @@ -179,12 +181,16 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents {
/// @param _blockId Index of the block.
/// @return blk_ The block.
function getBlock(uint64 _blockId) external view returns (TaikoData.Block memory blk_) {
require(_blockId < getConfig().ontakeForkHeight, L1_FORK_HEIGHT_ERROR());

(TaikoData.BlockV2 memory blk,) = LibUtils.getBlock(state, getConfig(), _blockId);
blk_ = LibData.blockV2ToV1(blk);
}

/// @inheritdoc ITaikoL1
function getBlockV2(uint64 _blockId) external view returns (TaikoData.BlockV2 memory blk_) {
require(_blockId >= getConfig().ontakeForkHeight, L1_FORK_HEIGHT_ERROR());

(blk_,) = LibUtils.getBlock(state, getConfig(), _blockId);
}

Expand Down
1 change: 1 addition & 0 deletions packages/protocol/test/layer1/based/TaikoL1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ contract TaikoL1_NoCooldown is TaikoL1 {
config.blockMaxProposals = 10;
config.blockRingBufferSize = 12;
config.livenessBond = 1e18; // 1 Taiko token
config.ontakeForkHeight = 0;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ contract TaikoL1Tiers is TaikoL1 {
config.blockMaxProposals = 10;
config.blockRingBufferSize = 12;
config.livenessBond = 1e18; // 1 Taiko token
config.ontakeForkHeight = 0;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ contract TaikoL1New is TaikoL1 {
config.blockMaxProposals = 20;
config.blockRingBufferSize = 25;
config.stateRootSyncInternal = 2;
config.ontakeForkHeight = 0;
}
}

Expand Down

0 comments on commit eb47f88

Please sign in to comment.