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): allow resetting genesis hash on L1 before 1st block is proposed #17078

Merged
merged 11 commits into from
May 10, 2024
4 changes: 4 additions & 0 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
state.__reserve1 = 0;
}

function init3(bytes32 _genesisBlockHash) external onlyOwner reinitializer(3) {
LibVerifying.resetGenesisHash(state, _genesisBlockHash);
}

/// @inheritdoc ITaikoL1
function proposeBlock(
bytes calldata _params,
Expand Down
20 changes: 20 additions & 0 deletions packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ library LibVerifying {
});
}

function resetGenesisHash(TaikoData.State storage _state, bytes32 _genesisBlockHash) internal {
dantaik marked this conversation as resolved.
Show resolved Hide resolved
if (_genesisBlockHash == 0 || _state.slotB.numBlocks != 1) return;

// Init the first state transition
TaikoData.TransitionState storage ts = _state.transitions[0][1];

if (ts.blockHash == _genesisBlockHash) return;

ts.blockHash = _genesisBlockHash;
ts.timestamp = uint64(block.timestamp);

emit BlockVerified({
blockId: 0,
prover: address(0),
blockHash: _genesisBlockHash,
stateRoot: 0,
tier: 0
});
}

/// @dev Verifies up to N blocks.
function verifyBlocks(
TaikoData.State storage _state,
Expand Down