From a71ccdd621407a79ebc1a037fa1c56711883838b Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Mon, 29 Apr 2024 14:08:50 +0800 Subject: [PATCH 1/6] remove proposer permission check --- .../protocol/contracts/L1/TaikoErrors.sol | 1 - .../contracts/L1/libs/LibProposing.sol | 22 ------------------- .../protocol/contracts/common/LibStrings.sol | 2 -- 3 files changed, 25 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoErrors.sol b/packages/protocol/contracts/L1/TaikoErrors.sol index 62eb158da66..9a5d9ea3f75 100644 --- a/packages/protocol/contracts/L1/TaikoErrors.sol +++ b/packages/protocol/contracts/L1/TaikoErrors.sol @@ -32,7 +32,6 @@ abstract contract TaikoErrors { error L1_TOO_MANY_BLOCKS(); error L1_TRANSITION_ID_ZERO(); error L1_TRANSITION_NOT_FOUND(); - error L1_UNAUTHORIZED(); error L1_UNEXPECTED_PARENT(); error L1_UNEXPECTED_TRANSITION_ID(); } diff --git a/packages/protocol/contracts/L1/libs/LibProposing.sol b/packages/protocol/contracts/L1/libs/LibProposing.sol index 9496cf0a14c..dd36f1797aa 100644 --- a/packages/protocol/contracts/L1/libs/LibProposing.sol +++ b/packages/protocol/contracts/L1/libs/LibProposing.sol @@ -44,7 +44,6 @@ library LibProposing { error L1_INVALID_SIG(); error L1_LIVENESS_BOND_NOT_RECEIVED(); error L1_TOO_MANY_BLOCKS(); - error L1_UNAUTHORIZED(); error L1_UNEXPECTED_PARENT(); /// @dev Proposes a Taiko L2 block. @@ -81,7 +80,6 @@ library LibProposing { // ensure that only that specific address has the authority to propose // blocks. TaikoData.SlotB memory b = _state.slotB; - if (!_isProposerPermitted(b, _resolver)) revert L1_UNAUTHORIZED(); // It's essential to ensure that the ring buffer for proposed blocks // still has space for at least one more block. @@ -229,24 +227,4 @@ library LibProposing { depositsProcessed: deposits_ }); } - - function _isProposerPermitted( - TaikoData.SlotB memory _slotB, - IAddressResolver _resolver - ) - private - view - returns (bool) - { - if (_slotB.numBlocks == 1) { - // Only proposer_one can propose the first block after genesis - address proposerOne = _resolver.resolve(LibStrings.B_PROPOSER_ONE, true); - if (proposerOne != address(0)) { - return msg.sender == proposerOne; - } - } - - address proposer = _resolver.resolve(LibStrings.B_PROPOSER, true); - return proposer == address(0) || msg.sender == proposer; - } } diff --git a/packages/protocol/contracts/common/LibStrings.sol b/packages/protocol/contracts/common/LibStrings.sol index a5fb5b3b388..fa4a2469fd9 100644 --- a/packages/protocol/contracts/common/LibStrings.sol +++ b/packages/protocol/contracts/common/LibStrings.sol @@ -6,8 +6,6 @@ pragma solidity 0.8.24; library LibStrings { bytes32 internal constant B_CHAIN_WATCHDOG = bytes32("chain_watchdog"); bytes32 internal constant B_WITHDRAWER = bytes32("withdrawer"); - bytes32 internal constant B_PROPOSER = bytes32("proposer"); - bytes32 internal constant B_PROPOSER_ONE = bytes32("proposer_one"); bytes32 internal constant B_SIGNAL_SERVICE = bytes32("signal_service"); bytes32 internal constant B_TAIKO_TOKEN = bytes32("taiko_token"); bytes32 internal constant B_TAIKO = bytes32("taiko"); From 94b7f36549b4e555feb12e434298fcc9cc986362 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Mon, 29 Apr 2024 14:09:22 +0800 Subject: [PATCH 2/6] Update LibProposing.sol --- packages/protocol/contracts/L1/libs/LibProposing.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/contracts/L1/libs/LibProposing.sol b/packages/protocol/contracts/L1/libs/LibProposing.sol index dd36f1797aa..3a19aa2d894 100644 --- a/packages/protocol/contracts/L1/libs/LibProposing.sol +++ b/packages/protocol/contracts/L1/libs/LibProposing.sol @@ -138,7 +138,7 @@ library LibProposing { // We cannot rely on `msg.sender != tx.origin` for EOA check, as it will break after EIP // 7645: Alias ORIGIN to SENDER if ( - _checkEOAForCalldataDA && meta_.id != 1 + _checkEOAForCalldataDA && ECDSA.recover(meta_.blobHash, params.signature) != msg.sender ) { revert L1_INVALID_SIG(); From eb1de6238ca8a1874ca7c615fcb3f715555af33e Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Mon, 6 May 2024 16:54:49 +0800 Subject: [PATCH 3/6] Update LibStrings.sol --- packages/protocol/contracts/common/LibStrings.sol | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/protocol/contracts/common/LibStrings.sol b/packages/protocol/contracts/common/LibStrings.sol index b84aaac8794..6d7e738d092 100644 --- a/packages/protocol/contracts/common/LibStrings.sol +++ b/packages/protocol/contracts/common/LibStrings.sol @@ -4,13 +4,13 @@ pragma solidity 0.8.24; /// @title LibStrings /// @custom:security-contact security@taiko.xyz library LibStrings { + bytes32 internal constant B_AUTOMATA_DCAP_ATTESTATION = bytes32("automata_dcap_attestation"); bytes32 internal constant B_BRIDGE = bytes32("bridge"); bytes32 internal constant B_BRIDGE_WATCHDOG = bytes32("bridge_watchdog"); bytes32 internal constant B_BRIDGED_ERC1155 = bytes32("bridged_erc1155"); bytes32 internal constant B_BRIDGED_ERC20 = bytes32("bridged_erc20"); bytes32 internal constant B_BRIDGED_ERC721 = bytes32("bridged_erc721"); bytes32 internal constant B_CHAIN_WATCHDOG = bytes32("chain_watchdog"); - bytes32 internal constant B_CHAIN_WATCHDOG = bytes32("chain_watchdog"); bytes32 internal constant B_ERC1155_VAULT = bytes32("erc1155_vault"); bytes32 internal constant B_ERC20_VAULT = bytes32("erc20_vault"); bytes32 internal constant B_ERC721_VAULT = bytes32("erc721_vault"); @@ -20,18 +20,14 @@ library LibStrings { bytes32 internal constant B_QUOTA_MANAGER = bytes32("quota_manager"); bytes32 internal constant B_SGX_WATCHDOG = bytes32("sgx_watchdog"); bytes32 internal constant B_SIGNAL_SERVICE = bytes32("signal_service"); - bytes32 internal constant B_SIGNAL_SERVICE = bytes32("signal_service"); - bytes32 internal constant B_TAIKO = bytes32("taiko"); bytes32 internal constant B_TAIKO = bytes32("taiko"); bytes32 internal constant B_TAIKO_TOKEN = bytes32("taiko_token"); - bytes32 internal constant B_TAIKO_TOKEN = bytes32("taiko_token"); bytes32 internal constant B_TIER_GUARDIAN = bytes32("tier_guardian"); bytes32 internal constant B_TIER_GUARDIAN_MINORITY = bytes32("tier_guardian_minority"); bytes32 internal constant B_TIER_PROVIDER = bytes32("tier_provider"); bytes32 internal constant B_TIER_SGX = bytes32("tier_sgx"); bytes32 internal constant B_TIER_SGX_ZKVM = bytes32("tier_sgx_zkvm"); bytes32 internal constant B_WITHDRAWER = bytes32("withdrawer"); - bytes32 internal constant B_WITHDRAWER = bytes32("withdrawer"); bytes32 internal constant H_RETURN_LIVENESS_BOND = keccak256("RETURN_LIVENESS_BOND"); bytes32 internal constant H_SIGNAL_ROOT = keccak256("SIGNAL_ROOT"); bytes32 internal constant H_STATE_ROOT = keccak256("STATE_ROOT"); From a8095a6bd046835404fb02e112eaa16529d4b27b Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Mon, 6 May 2024 22:40:07 +0800 Subject: [PATCH 4/6] Update LibStrings.sol --- packages/protocol/contracts/common/LibStrings.sol | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/protocol/contracts/common/LibStrings.sol b/packages/protocol/contracts/common/LibStrings.sol index 6d7e738d092..9dee7077eba 100644 --- a/packages/protocol/contracts/common/LibStrings.sol +++ b/packages/protocol/contracts/common/LibStrings.sol @@ -14,8 +14,6 @@ library LibStrings { bytes32 internal constant B_ERC1155_VAULT = bytes32("erc1155_vault"); bytes32 internal constant B_ERC20_VAULT = bytes32("erc20_vault"); bytes32 internal constant B_ERC721_VAULT = bytes32("erc721_vault"); - bytes32 internal constant B_PROPOSER = bytes32("proposer"); - bytes32 internal constant B_PROPOSER_ONE = bytes32("proposer_one"); bytes32 internal constant B_PROVER_ASSIGNMENT = bytes32("PROVER_ASSIGNMENT"); bytes32 internal constant B_QUOTA_MANAGER = bytes32("quota_manager"); bytes32 internal constant B_SGX_WATCHDOG = bytes32("sgx_watchdog"); From eeede040e56762cb6abf888b2d43c7d7997dbf2f Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Sat, 11 May 2024 10:44:52 +0800 Subject: [PATCH 5/6] Revert "feat(protocol): allow resetting genesis hash on L1 before 1st block is proposed (#17078)" This reverts commit 2b4816e972da313235559489b6588480af9e45a4. --- .../protocol/contracts/L1/TaikoErrors.sol | 1 - packages/protocol/contracts/L1/TaikoL1.sol | 4 -- .../contracts/L1/libs/LibVerifying.sol | 64 +++++++------------ 3 files changed, 24 insertions(+), 45 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoErrors.sol b/packages/protocol/contracts/L1/TaikoErrors.sol index c661609ea7e..9a5d9ea3f75 100644 --- a/packages/protocol/contracts/L1/TaikoErrors.sol +++ b/packages/protocol/contracts/L1/TaikoErrors.sol @@ -29,7 +29,6 @@ abstract contract TaikoErrors { error L1_NOT_ASSIGNED_PROVER(); error L1_PROVING_PAUSED(); error L1_RECEIVE_DISABLED(); - error L1_TOO_LATE(); error L1_TOO_MANY_BLOCKS(); error L1_TRANSITION_ID_ZERO(); error L1_TRANSITION_NOT_FOUND(); diff --git a/packages/protocol/contracts/L1/TaikoL1.sol b/packages/protocol/contracts/L1/TaikoL1.sol index d5074c2c428..bfa78a7baf2 100644 --- a/packages/protocol/contracts/L1/TaikoL1.sol +++ b/packages/protocol/contracts/L1/TaikoL1.sol @@ -66,10 +66,6 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors { state.__reserve1 = 0; } - function resetGenesisHash(bytes32 _genesisBlockHash) external onlyOwner { - LibVerifying.resetGenesisHash(state, _genesisBlockHash); - } - /// @inheritdoc ITaikoL1 function proposeBlock( bytes calldata _params, diff --git a/packages/protocol/contracts/L1/libs/LibVerifying.sol b/packages/protocol/contracts/L1/libs/LibVerifying.sol index 1f6f2e557db..160b064abf6 100644 --- a/packages/protocol/contracts/L1/libs/LibVerifying.sol +++ b/packages/protocol/contracts/L1/libs/LibVerifying.sol @@ -41,7 +41,6 @@ library LibVerifying { error L1_INVALID_CONFIG(); error L1_INVALID_GENESIS_HASH(); error L1_TRANSITION_ID_ZERO(); - error L1_TOO_LATE(); /// @notice Initializes the Taiko protocol state. /// @param _state The state to initialize. @@ -55,14 +54,33 @@ library LibVerifying { internal { if (!_isConfigValid(_config)) revert L1_INVALID_CONFIG(); + if (_genesisBlockHash == 0) revert L1_INVALID_GENESIS_HASH(); - _setupGenesisBlock(_state, _genesisBlockHash); - } + // Init state + _state.slotA.genesisHeight = uint64(block.number); + _state.slotA.genesisTimestamp = uint64(block.timestamp); + _state.slotB.numBlocks = 1; - function resetGenesisHash(TaikoData.State storage _state, bytes32 _genesisBlockHash) internal { - if (_state.slotB.numBlocks != 1) revert L1_TOO_LATE(); + // Init the genesis block + TaikoData.Block storage blk = _state.blocks[0]; + blk.nextTransitionId = 2; + blk.proposedAt = uint64(block.timestamp); + blk.verifiedTransitionId = 1; + blk.metaHash = bytes32(uint256(1)); // Give the genesis metahash a non-zero value. - _setupGenesisBlock(_state, _genesisBlockHash); + // Init the first state transition + TaikoData.TransitionState storage ts = _state.transitions[0][1]; + ts.blockHash = _genesisBlockHash; + ts.prover = address(0); + ts.timestamp = uint64(block.timestamp); + + emit BlockVerified({ + blockId: 0, + prover: address(0), + blockHash: _genesisBlockHash, + stateRoot: 0, + tier: 0 + }); } /// @dev Verifies up to N blocks. @@ -193,40 +211,6 @@ library LibVerifying { emit StateVariablesUpdated({ slotB: _state.slotB }); } - function _setupGenesisBlock( - TaikoData.State storage _state, - bytes32 _genesisBlockHash - ) - private - { - if (_genesisBlockHash == 0) revert L1_INVALID_GENESIS_HASH(); - // Init state - _state.slotA.genesisHeight = uint64(block.number); - _state.slotA.genesisTimestamp = uint64(block.timestamp); - _state.slotB.numBlocks = 1; - - // Init the genesis block - TaikoData.Block storage blk = _state.blocks[0]; - blk.nextTransitionId = 2; - blk.proposedAt = uint64(block.timestamp); - blk.verifiedTransitionId = 1; - blk.metaHash = bytes32(uint256(1)); // Give the genesis metahash a non-zero value. - - // Init the first state transition - TaikoData.TransitionState storage ts = _state.transitions[0][1]; - ts.blockHash = _genesisBlockHash; - ts.prover = address(0); - ts.timestamp = uint64(block.timestamp); - - emit BlockVerified({ - blockId: 0, - prover: address(0), - blockHash: _genesisBlockHash, - stateRoot: 0, - tier: 0 - }); - } - function _syncChainData( TaikoData.State storage _state, TaikoData.Config memory _config, From 98f0acc3702c77f01be0ca764c3313126a117598 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Wed, 22 May 2024 01:17:42 +0800 Subject: [PATCH 6/6] Update L1RollupAddressManager.sol --- packages/protocol/contracts/mainnet/L1RollupAddressManager.sol | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/protocol/contracts/mainnet/L1RollupAddressManager.sol b/packages/protocol/contracts/mainnet/L1RollupAddressManager.sol index 4a36e7f0116..472d0a3f1b0 100644 --- a/packages/protocol/contracts/mainnet/L1RollupAddressManager.sol +++ b/packages/protocol/contracts/mainnet/L1RollupAddressManager.sol @@ -13,8 +13,6 @@ contract L1RollupAddressManager is AddressManager { /// @notice Gets the address mapped to a specific chainId-name pair. /// @dev Sub-contracts can override this method to avoid reading from storage. /// The following names are not cached: - /// - B_PROPOSER - /// - B_PROPOSER_ONE /// - B_TIER_PROVIDER function _getOverride( uint64 _chainId,