diff --git a/packages/protocol/contract_layout_layer1.md b/packages/protocol/contract_layout_layer1.md index 6425548d0e5..557437dc19e 100644 --- a/packages/protocol/contract_layout_layer1.md +++ b/packages/protocol/contract_layout_layer1.md @@ -611,44 +611,40 @@ ╰-----------------------------------------------------+---------------------------------------------------------------+------+--------+-------+--------------------------------------------------╯ -## ComposeVerifier - -╭-----------------------------+-------------+------+--------+-------+------------------------------------------------------------------------╮ -| Name | Type | Slot | Offset | Bytes | Contract | -+============================================================================================================================================+ -| _initialized | uint8 | 0 | 0 | 1 | ComposeVerifier | -|-----------------------------+-------------+------+--------+-------+------------------------------------------------------------------------| -| _initializing | bool | 0 | 1 | 1 | ComposeVerifier | -|-----------------------------+-------------+------+--------+-------+------------------------------------------------------------------------| -| __gap | uint256[50] | 1 | 0 | 1600 | ComposeVerifier | -|-----------------------------+-------------+------+--------+-------+------------------------------------------------------------------------| -| _owner | address | 51 | 0 | 20 | ComposeVerifier | -|-----------------------------+-------------+------+--------+-------+------------------------------------------------------------------------| -| __gap | uint256[49] | 52 | 0 | 1568 | ComposeVerifier | -|-----------------------------+-------------+------+--------+-------+------------------------------------------------------------------------| -| _pendingOwner | address | 101 | 0 | 20 | ComposeVerifier | -|-----------------------------+-------------+------+--------+-------+------------------------------------------------------------------------| -| __gap | uint256[49] | 102 | 0 | 1568 | ComposeVerifier | -|-----------------------------+-------------+------+--------+-------+------------------------------------------------------------------------| -| __resolver | address | 151 | 0 | 20 | ComposeVerifier | -|-----------------------------+-------------+------+--------+-------+------------------------------------------------------------------------| -| __gapFromOldAddressResolver | uint256[49] | 152 | 0 | 1568 | ComposeVerifier | -|-----------------------------+-------------+------+--------+-------+------------------------------------------------------------------------| -| __reentry | uint8 | 201 | 0 | 1 | ComposeVerifier | -|-----------------------------+-------------+------+--------+-------+------------------------------------------------------------------------| -| __paused | uint8 | 201 | 1 | 1 | ComposeVerifier | -|-----------------------------+-------------+------+--------+-------+------------------------------------------------------------------------| -| __gap | uint256[49] | 202 | 0 | 1568 | ComposeVerifier | -|-----------------------------+-------------+------+--------+-------+------------------------------------------------------------------------| -| __gap | uint256[50] | 251 | 0 | 1600 | ComposeVerifier | -╰-----------------------------+-------------+------+--------+-------+------------------------------------------------------------------------╯ - - -## TeeAnyVerifier - -## ZkAndTeeVerifier - -## ZkAnyVerifier +## SgxAndZkVerifier + +╭-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------╮ +| Name | Type | Slot | Offset | Bytes | Contract | ++==============================================================================================================================================+ +| _initialized | uint8 | 0 | 0 | 1 | SgxAndZkVerifier | +|-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------| +| _initializing | bool | 0 | 1 | 1 | SgxAndZkVerifier | +|-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------| +| __gap | uint256[50] | 1 | 0 | 1600 | SgxAndZkVerifier | +|-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------| +| _owner | address | 51 | 0 | 20 | SgxAndZkVerifier | +|-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------| +| __gap | uint256[49] | 52 | 0 | 1568 | SgxAndZkVerifier | +|-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------| +| _pendingOwner | address | 101 | 0 | 20 | SgxAndZkVerifier | +|-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------| +| __gap | uint256[49] | 102 | 0 | 1568 | SgxAndZkVerifier | +|-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------| +| __resolver | address | 151 | 0 | 20 | SgxAndZkVerifier | +|-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------| +| __gapFromOldAddressResolver | uint256[49] | 152 | 0 | 1568 | SgxAndZkVerifier | +|-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------| +| __reentry | uint8 | 201 | 0 | 1 | SgxAndZkVerifier | +|-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------| +| __paused | uint8 | 201 | 1 | 1 | SgxAndZkVerifier | +|-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------| +| __gap | uint256[49] | 202 | 0 | 1568 | SgxAndZkVerifier | +|-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------| +| __gap | uint256[50] | 251 | 0 | 1600 | SgxAndZkVerifier | +|-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------| +| __gap | uint256[50] | 301 | 0 | 1600 | SgxAndZkVerifier | +╰-----------------------------+-------------+------+--------+-------+--------------------------------------------------------------------------╯ + ## Risc0Verifier diff --git a/packages/protocol/contract_layout_layer2.md b/packages/protocol/contract_layout_layer2.md index 22e1f3cde8d..59081f77533 100644 --- a/packages/protocol/contract_layout_layer2.md +++ b/packages/protocol/contract_layout_layer2.md @@ -695,7 +695,9 @@ |-----------------------------+-----------------------------+------+--------+-------+--------------------------------------------| | l1ChainId | uint64 | 254 | 0 | 8 | TaikoL2 | |-----------------------------+-----------------------------+------+--------+-------+--------------------------------------------| -| __gap | uint256[46] | 255 | 0 | 1472 | TaikoL2 | +| anchorInput | bytes32 | 255 | 0 | 32 | TaikoL2 | +|-----------------------------+-----------------------------+------+--------+-------+--------------------------------------------| +| __gap | uint256[45] | 256 | 0 | 1440 | TaikoL2 | ╰-----------------------------+-----------------------------+------+--------+-------+--------------------------------------------╯ @@ -742,7 +744,9 @@ |-----------------------------+-----------------------------+------+--------+-------+------------------------------------------------------| | l1ChainId | uint64 | 254 | 0 | 8 | HeklaTaikoL2 | |-----------------------------+-----------------------------+------+--------+-------+------------------------------------------------------| -| __gap | uint256[46] | 255 | 0 | 1472 | HeklaTaikoL2 | +| anchorInput | bytes32 | 255 | 0 | 32 | HeklaTaikoL2 | +|-----------------------------+-----------------------------+------+--------+-------+------------------------------------------------------| +| __gap | uint256[45] | 256 | 0 | 1440 | HeklaTaikoL2 | ╰-----------------------------+-----------------------------+------+--------+-------+------------------------------------------------------╯ @@ -789,7 +793,9 @@ |-----------------------------+-----------------------------+------+--------+-------+------------------------------------------------------------| | l1ChainId | uint64 | 254 | 0 | 8 | MainnetTaikoL2 | |-----------------------------+-----------------------------+------+--------+-------+------------------------------------------------------------| -| __gap | uint256[46] | 255 | 0 | 1472 | MainnetTaikoL2 | +| anchorInput | bytes32 | 255 | 0 | 32 | MainnetTaikoL2 | +|-----------------------------+-----------------------------+------+--------+-------+------------------------------------------------------------| +| __gap | uint256[45] | 256 | 0 | 1440 | MainnetTaikoL2 | ╰-----------------------------+-----------------------------+------+--------+-------+------------------------------------------------------------╯ diff --git a/packages/protocol/contracts/layer1/based/ITaikoL1.sol b/packages/protocol/contracts/layer1/based/ITaikoL1.sol index 5c4456e463b..2d8ba244476 100644 --- a/packages/protocol/contracts/layer1/based/ITaikoL1.sol +++ b/packages/protocol/contracts/layer1/based/ITaikoL1.sol @@ -9,6 +9,7 @@ interface ITaikoL1 { struct BlockParamsV3 { bytes32 parentMetaHash; uint64 anchorBlockId; + bytes32 anchorInput; uint64 timestamp; uint32 txListOffset; uint32 txListSize; @@ -33,6 +34,7 @@ interface ITaikoL1 { uint8 blobIndex; uint64 anchorBlockId; bytes32 anchorBlockHash; + bytes32 anchorInput; LibSharedData.BaseFeeConfig baseFeeConfig; } diff --git a/packages/protocol/contracts/layer1/based/TaikoL1.sol b/packages/protocol/contracts/layer1/based/TaikoL1.sol index 1d481f74b0f..2214a59beae 100644 --- a/packages/protocol/contracts/layer1/based/TaikoL1.sol +++ b/packages/protocol/contracts/layer1/based/TaikoL1.sol @@ -105,19 +105,18 @@ abstract contract TaikoL1 is EssentialContract, ITaikoL1 { metas_ = new BlockMetadataV3[](_paramsArray.length); bool calldataUsed = _txList.length != 0; + UpdatedParams memory updatedParams; for (uint256 i; i < _paramsArray.length; ++i) { require(calldataUsed || _paramsArray[i].blobIndex != 0, BlobIndexZero()); - UpdatedParams memory updatedParams = + updatedParams = _validateBlockParams(_paramsArray[i], config.maxAnchorHeightOffset, lastBlock); // This section constructs the metadata for the proposed block, which is crucial for - // nodes/clients - // to process the block. The metadata itself is not stored on-chain; instead, only its - // hash is kept. + // nodes/clients to process the block. The metadata itself is not stored on-chain; + // instead, only its hash is kept. // The metadata must be supplied as calldata prior to proving the block, enabling the - // computation - // and verification of its integrity through the comparison of the metahash. + // computation and verification of its integrity through the comparison of the metahash. unchecked { metas_[i] = BlockMetadataV3({ difficulty: keccak256(abi.encode("TAIKO_DIFFICULTY", stats2.numBlocks)), @@ -139,6 +138,7 @@ abstract contract TaikoL1 is EssentialContract, ITaikoL1 { blobIndex: calldataUsed ? 0 : _paramsArray[i].blobIndex, anchorBlockId: updatedParams.anchorBlockId, anchorBlockHash: blockhash(updatedParams.anchorBlockId), + anchorInput: _paramsArray[i].anchorInput, baseFeeConfig: config.baseFeeConfig }); } diff --git a/packages/protocol/contracts/layer2/based/TaikoL2.sol b/packages/protocol/contracts/layer2/based/TaikoL2.sol index c30732f10d4..5af7c9be9e7 100644 --- a/packages/protocol/contracts/layer2/based/TaikoL2.sol +++ b/packages/protocol/contracts/layer2/based/TaikoL2.sol @@ -53,7 +53,10 @@ contract TaikoL2 is EssentialContract, IBlockHash, TaikoL2Deprecated { /// @notice The L1's chain ID. uint64 public l1ChainId; - uint256[46] private __gap; + /// @notice The arbitrary bytes32 input chosen by the block proposer. + bytes32 public anchorInput; + + uint256[45] private __gap; /// @notice Emitted when the latest L1 block details are anchored to L2. /// @param parentHash The hash of the parent block. @@ -131,11 +134,13 @@ contract TaikoL2 is EssentialContract, IBlockHash, TaikoL2Deprecated { /// transaction, and any subsequent calls will revert with L2_PUBLIC_INPUT_HASH_MISMATCH. /// @param _anchorBlockId The `anchorBlockId` value in this block's metadata. /// @param _anchorStateRoot The state root for the L1 block with id equals `_anchorBlockId`. + /// @param _anchorInput An arbitrary bytes32 input chosen by the block proposer. /// @param _parentGasUsed The gas used in the parent block. /// @param _baseFeeConfig The base fee configuration. - function anchorV2( + function anchorV3( uint64 _anchorBlockId, bytes32 _anchorStateRoot, + bytes32 _anchorInput, uint32 _parentGasUsed, LibSharedData.BaseFeeConfig calldata _baseFeeConfig ) @@ -149,6 +154,8 @@ contract TaikoL2 is EssentialContract, IBlockHash, TaikoL2Deprecated { { require(block.number >= pacayaForkHeight(), L2_FORK_ERROR()); + anchorInput = _anchorInput; + uint256 parentId = block.number - 1; _verifyAndUpdatePublicInputHash(parentId); _verifyBaseFeeAndUpdateGasExcess(_parentGasUsed, _baseFeeConfig); diff --git a/packages/protocol/script/gen-layouts.sh b/packages/protocol/script/gen-layouts.sh index 324567c3f75..df669730bf4 100755 --- a/packages/protocol/script/gen-layouts.sh +++ b/packages/protocol/script/gen-layouts.sh @@ -21,10 +21,7 @@ contracts_shared=( # Layer 1 contracts contracts_layer1=( "contracts/layer1/token/TaikoToken.sol:TaikoToken" -"contracts/layer1/verifiers/compose/ComposeVerifier.sol:ComposeVerifier" -"contracts/layer1/verifiers/compose/TeeAnyVerifier.sol:TeeAnyVerifier" -"contracts/layer1/verifiers/compose/ZkAndTeeVerifier.sol:ZkAndTeeVerifier" -"contracts/layer1/verifiers/compose/ZkAnyVerifier.sol:ZkAnyVerifier" +"contracts/layer1/verifiers/compose/SgxAndZkVerifier.sol:SgxAndZkVerifier" "contracts/layer1/verifiers/Risc0Verifier.sol:Risc0Verifier" "contracts/layer1/verifiers/SP1Verifier.sol:SP1Verifier" "contracts/layer1/verifiers/SgxVerifier.sol:SgxVerifier" @@ -75,7 +72,7 @@ for contract in "${contracts[@]}"; do echo "inspect ${contract}" echo "## ${contract}" >> $output_file - FOUNDRY_PROFILE=${profile} forge inspect -C ./contracts/${profile} -o ./out/${profile} ${contract} storagelayout --pretty >> $output_file + FOUNDRY_PROFILE=${profile} forge inspect -C ./contracts/${profile} -o ./out/${profile} ${contract} storagelayout --color never --pretty >> $output_file echo "" >> $output_file done diff --git a/packages/protocol/snapshots/TaikoL1Test_Suite1.json b/packages/protocol/snapshots/TaikoL1Test_Suite1.json index dddd3b6818b..c5a40884749 100644 --- a/packages/protocol/snapshots/TaikoL1Test_Suite1.json +++ b/packages/protocol/snapshots/TaikoL1Test_Suite1.json @@ -1,4 +1,4 @@ { - "proposeBlocksV3": "84387", - "proveBlocksV3": "133463" + "proposeBlocksV3": "84973", + "proveBlocksV3": "133553" } \ No newline at end of file diff --git a/packages/protocol/test/layer2/TaikoL2.t.sol b/packages/protocol/test/layer2/TaikoL2.t.sol index 4c127306d79..c8105534792 100644 --- a/packages/protocol/test/layer2/TaikoL2.t.sol +++ b/packages/protocol/test/layer2/TaikoL2.t.sol @@ -131,7 +131,7 @@ contract TestTaikoL2 is Layer2Test { bytes32 anchorStateRoot = bytes32(uint256(1)); vm.prank(taikoL2.GOLDEN_TOUCH_ADDRESS()); - taikoL2.anchorV2(++anchorBlockId, anchorStateRoot, _parentGasUsed, baseFeeConfig); + taikoL2.anchorV3(++anchorBlockId, anchorStateRoot, 0x0, _parentGasUsed, baseFeeConfig); (uint256 basefee, uint64 newGasTarget,) = taikoL2.getBasefeeV2(_parentGasUsed, baseFeeConfig); @@ -157,6 +157,6 @@ contract TestTaikoL2 is Layer2Test { minGasExcess: 1_340_000_000, maxGasIssuancePerBlock: 600_000_000 // two minutes }); - taikoL2.anchorV2(++anchorBlockId, anchorStateRoot, parentGasUsed, baseFeeConfig); + taikoL2.anchorV3(++anchorBlockId, anchorStateRoot, 0x0, parentGasUsed, baseFeeConfig); } }