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 block propose to pass a bytes32 input to L2 anchor #18569

Merged
merged 27 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0a057d6
1
dantaik Dec 8, 2024
728d390
support an bytes32-typed arbitrary anchor input
dantaik Dec 8, 2024
2010536
more
dantaik Dec 8, 2024
6e83eb7
rename
dantaik Dec 8, 2024
943259d
Update TaikoL1.sol
dantaik Dec 8, 2024
4959ac5
Update TaikoL1.sol
dantaik Dec 8, 2024
3909e4c
more
dantaik Dec 8, 2024
9e552dc
Merge branch 'pacaya_fork' into pass_data_anchor
dantaik Dec 8, 2024
c7b78df
Merge branch 'pacaya_fork' into pass_data_anchor
dantaik Dec 8, 2024
37ad5b3
Merge branch 'pacaya_fork' into pass_data_anchor
dantaik Dec 13, 2024
441054a
Update ITaikoL1.sol
dantaik Dec 13, 2024
83bd754
Update ITaikoL1.sol
dantaik Dec 13, 2024
371c68f
Merge branch 'pass_data_anchor' of https://github.com/taikoxyz/taiko-…
dantaik Dec 13, 2024
6677005
forge fmt & update contract layout tables
dantaik Dec 13, 2024
72871de
rename
dantaik Dec 14, 2024
17e3336
Update TaikoL2.sol
dantaik Dec 14, 2024
8950074
Merge branch 'pacaya_fork' into pass_data_anchor
dantaik Dec 14, 2024
1b1133f
more
dantaik Dec 14, 2024
2edf605
Create TaikoL1Test_Suite1.json
dantaik Dec 14, 2024
2ec0f21
more
dantaik Dec 14, 2024
5dbb020
layout
dantaik Dec 14, 2024
322694b
Merge branch 'pacaya_fork' into pass_data_anchor
dantaik Dec 15, 2024
16c1596
Merge branch 'pacaya_fork' into pass_data_anchor
dantaik Dec 15, 2024
564dcb6
forge fmt & update contract layout tables
dantaik Dec 15, 2024
9faba01
rename anchorV2 to anchorV3
dantaik Dec 16, 2024
a2d2377
Delete TaikoL1Test_Suite1.json
dantaik Dec 16, 2024
d946187
forge fmt & update contract layout tables
dantaik Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 8 additions & 1 deletion 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(
davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved
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.anchorV2(++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.anchorV2(++anchorBlockId, anchorStateRoot, 0x0, parentGasUsed, baseFeeConfig);
}
}