Skip to content

Commit

Permalink
feat(protocol): allow block propose to pass a bytes32 input to L2 anc…
Browse files Browse the repository at this point in the history
…hor (#18569)

Co-authored-by: dantaik <[email protected]>
  • Loading branch information
dantaik and dantaik authored Dec 16, 2024
1 parent eec4256 commit 1927a30
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 58 deletions.
72 changes: 34 additions & 38 deletions packages/protocol/contract_layout_layer1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 9 additions & 3 deletions packages/protocol/contract_layout_layer2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
╰-----------------------------+-----------------------------+------+--------+-------+--------------------------------------------╯


Expand Down Expand Up @@ -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 |
╰-----------------------------+-----------------------------+------+--------+-------+------------------------------------------------------╯


Expand Down Expand Up @@ -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 |
╰-----------------------------+-----------------------------+------+--------+-------+------------------------------------------------------------╯


2 changes: 2 additions & 0 deletions packages/protocol/contracts/layer1/based/ITaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface ITaikoL1 {
struct BlockParamsV3 {
bytes32 parentMetaHash;
uint64 anchorBlockId;
bytes32 anchorInput;
uint64 timestamp;
uint32 txListOffset;
uint32 txListSize;
Expand All @@ -33,6 +34,7 @@ interface ITaikoL1 {
uint8 blobIndex;
uint64 anchorBlockId;
bytes32 anchorBlockHash;
bytes32 anchorInput;
LibSharedData.BaseFeeConfig baseFeeConfig;
}

Expand Down
12 changes: 6 additions & 6 deletions packages/protocol/contracts/layer1/based/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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
});
}
Expand Down
11 changes: 9 additions & 2 deletions packages/protocol/contracts/layer2/based/TaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
)
Expand All @@ -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);
Expand Down
7 changes: 2 additions & 5 deletions packages/protocol/script/gen-layouts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/snapshots/TaikoL1Test_Suite1.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"proposeBlocksV3": "84387",
"proveBlocksV3": "133463"
"proposeBlocksV3": "84973",
"proveBlocksV3": "133553"
}
4 changes: 2 additions & 2 deletions packages/protocol/test/layer2/TaikoL2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}

0 comments on commit 1927a30

Please sign in to comment.