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): prepare ontake fork to support new params & metadata #17679

Merged
merged 92 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
d8d670b
allow contract propoers to use calldata as well.
dantaik Jun 21, 2024
0b0c50f
Merge branch 'main' into support_calldata_for_contract_proposer
dantaik Jun 24, 2024
42897f5
rename
dantaik Jun 24, 2024
10d81d8
emit CalldataTxList
dantaik Jun 24, 2024
0206ff6
Merge branch 'emit_CalldataTxList' into support_calldata_for_contract…
dantaik Jun 24, 2024
27ada28
Update LibProposing.sol
dantaik Jun 24, 2024
0594f0e
more
dantaik Jun 26, 2024
429d39e
refactor TaikoL1 code
dantaik Jun 26, 2024
220cc29
Update LibProposing.sol
dantaik Jun 26, 2024
f0256d4
Merge branch 'refactor_taikoL1' into plan_for_a_hard_fork
dantaik Jun 26, 2024
46bf716
Update TaikoEvents.sol
dantaik Jun 26, 2024
644457f
more
dantaik Jun 26, 2024
f6ed532
Update TaikoL1.sol
dantaik Jun 26, 2024
b0a1205
more
dantaik Jun 26, 2024
f6e6011
more
dantaik Jun 26, 2024
31ada4a
more
dantaik Jun 26, 2024
ba1d6bb
forge fmt & update contract layout table
dantaik Jun 26, 2024
711c733
more
dantaik Jun 26, 2024
8409a8f
more
dantaik Jun 26, 2024
2a82410
Update LibProposing.sol
dantaik Jun 26, 2024
194ac8e
Update LibProving.sol
dantaik Jun 26, 2024
1719bb9
Update LibVerifying.sol
dantaik Jun 26, 2024
3f5b385
more
dantaik Jun 26, 2024
b33fe9d
Update LibProposing.sol
dantaik Jun 26, 2024
b94839e
Update LibProposing.sol
dantaik Jun 26, 2024
ef4be90
Update LibProposing.sol
dantaik Jun 26, 2024
e67aee0
more
dantaik Jun 27, 2024
f37aab8
more
dantaik Jun 27, 2024
fd2456f
more
dantaik Jun 27, 2024
5abd944
Update TaikoL1TestGroupBase.sol
dantaik Jun 27, 2024
280cd14
more
dantaik Jun 27, 2024
27faf96
more
dantaik Jun 27, 2024
7828f9e
more
dantaik Jun 27, 2024
a713fe8
Update LibProposing.sol
dantaik Jun 27, 2024
548f497
Update LibProposing.sol
dantaik Jun 27, 2024
3d987aa
Update LibProposing.sol
dantaik Jun 27, 2024
2da7fda
Update LibProposing.sol
dantaik Jun 27, 2024
bc8f67e
Update TaikoL2.sol
dantaik Jun 27, 2024
8a52cbe
Update TaikoL2.sol
dantaik Jun 27, 2024
309fd92
Update TaikoData.sol
dantaik Jun 27, 2024
3668636
Merge branch 'main' into plan_for_a_hard_fork
dantaik Jun 27, 2024
d1a755b
Update LibProposing.sol
dantaik Jun 27, 2024
950daf5
comment
dantaik Jun 27, 2024
b2e0b86
rename
dantaik Jun 27, 2024
11353ef
Merge branch 'main' into plan_for_a_hard_fork
dantaik Jun 27, 2024
d9b3851
rename
dantaik Jun 27, 2024
bd41b24
one more test
dantaik Jun 27, 2024
0225104
improve test
dantaik Jun 28, 2024
a4e98c9
test
dantaik Jun 28, 2024
448d443
one more test
dantaik Jun 28, 2024
2437559
one more test
dantaik Jun 28, 2024
985e6d7
feat(protocol): enable AddressManager to cache address(0) without rea…
dantaik Jun 28, 2024
714691e
fix
dantaik Jun 28, 2024
6b198f4
Merge branch 'main' into plan_for_a_hard_fork
dantaik Jun 28, 2024
b359ae2
Update TaikoL1.sol
dantaik Jun 26, 2024
0519245
fix lint
dantaik Jun 28, 2024
22b8cbd
feat(protocol): add IProposerAccess (#17696)
dantaik Jun 28, 2024
38b1794
TierProviderV3
dantaik Jun 30, 2024
cba1735
Update TierRouter.sol
dantaik Jun 30, 2024
b718d7a
do not write proposedAt in Block
dantaik Jun 30, 2024
d959d95
Update TaikoL1testGroupA2.t.sol
dantaik Jun 30, 2024
4f92f94
do not write proposedIn in Block
dantaik Jun 30, 2024
bca4cf8
Update TaikoData.sol
dantaik Jun 30, 2024
57fbd0d
more
dantaik Jun 30, 2024
b134442
Update LibProposing.sol
dantaik Jun 30, 2024
cc60ace
fix tests
dantaik Jul 1, 2024
d79e9cb
Merge branch 'main' into plan_for_a_hard_fork
dantaik Jul 1, 2024
ed2a817
Update LibProving.sol
dantaik Jul 1, 2024
fe197da
Update LibProposing.sol
dantaik Jul 1, 2024
5c5bb37
fuji
dantaik Jul 1, 2024
5297c24
Merge branch 'ontake_fork' into plan_for_a_hard_fork
dantaik Jul 2, 2024
e543f6d
rename
dantaik Jul 2, 2024
10d633e
Allow bonds deposits and withdrawal
dantaik Jul 3, 2024
9febe80
Merge branch 'main' into bond_alt
dantaik Jul 3, 2024
9fdd6b9
Update LibBonds.sol
dantaik Jul 3, 2024
7bec257
pnpm test
dantaik Jul 3, 2024
307f8a0
Update TaikoEvents.sol
dantaik Jul 3, 2024
5fe7f36
Merge branch 'main' into bond_alt
dantaik Jul 3, 2024
509e8a8
Update LibBonds.sol
dantaik Jul 3, 2024
47e9fdc
Update TaikoToken.sol
dantaik Jul 4, 2024
92c7041
Update TaikoL1.sol
dantaik Jul 4, 2024
55b5f2b
Update TaikoL1.sol
dantaik Jul 4, 2024
9f84826
Update TaikoL1.sol
dantaik Jul 4, 2024
94747e8
Update LibBonds.sol
dantaik Jul 4, 2024
266c5dc
more
dantaik Jul 4, 2024
7cfb159
Update TaikoL1TestGroupBase.sol
dantaik Jul 4, 2024
37f7267
Merge branch 'main' into bond_alt
dantaik Jul 4, 2024
6d132c1
Merge branch 'bond_alt' into plan_for_a_hard_fork
dantaik Jul 4, 2024
3012e94
Update LibProving.sol
dantaik Jul 4, 2024
7a47857
fix tests
dantaik Jul 4, 2024
c70d6dd
Merge branch 'ontake_fork' into plan_for_a_hard_fork
dantaik Jul 4, 2024
548d811
resolve conflicts
dantaik Jul 4, 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
12 changes: 12 additions & 0 deletions packages/protocol/contracts/L1/ITaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ interface ITaikoL1 {
payable
returns (TaikoData.BlockMetadata memory meta_, TaikoData.EthDeposit[] memory deposits_);

/// @notice Proposes a Taiko L2 block (version 2)
/// @param _params Block parameters, currently an encoded BlockParams object.
/// @param _txList txList data if calldata is used for DA.
/// @return meta_ The metadata of the proposed L2 block.
function proposeBlock2(
bytes calldata _params,
bytes calldata _txList
)
external
payable
returns (TaikoData.BlockMetadata2 memory meta_);

/// @notice Proves or contests a block transition.
/// @param _blockId The index of the block to prove. This is also used to
/// select the right implementation version.
Expand Down
41 changes: 37 additions & 4 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ library TaikoData {
// ---------------------------------------------------------------------
// The number of L2 blocks between each L2-to-L1 state root sync.
uint8 stateRootSyncInternal;
bool checkEOAForCalldataDA;
uint64 fujiForkHeight;
}

/// @dev Struct representing prover fees per given tier
Expand Down Expand Up @@ -63,7 +63,15 @@ library TaikoData {
bytes32 extraData;
bytes32 parentMetaHash;
HookCall[] hookCalls; // DEPRECATED, value ignored.
bytes signature;
bytes signature; // DEPRECATED, value ignored.
}

struct BlockParams2 {
address coinbase;
bytes32 extraData;
bytes32 parentMetaHash;
uint64 anchorBlockId; // NEW
uint64 timestamp; // NEW
}

/// @dev Struct containing data only required for proving a block
Expand All @@ -87,6 +95,25 @@ library TaikoData {
address sender; // a.k.a proposer
}

struct BlockMetadata2 {
bytes32 anchorBlockHash; // `_l1BlockHash` in TaikoL2's anchor tx.
bytes32 difficulty;
bytes32 blobHash;
bytes32 extraData;
address coinbase;
uint64 id;
uint32 gasLimit;
uint64 timestamp;
uint64 anchorBlockId; // `_l1BlockId` in TaikoL2's anchor tx.
uint16 minTier;
bool blobUsed;
bytes32 parentMetaHash;
address proposer;
uint96 livenessBond;
uint64 proposedAt; // timestamp
uint64 proposedIn; // L1 block number, required/used by node/client.
}

/// @dev Struct representing transition to be proven.
struct Transition {
bytes32 parentHash;
Expand Down Expand Up @@ -117,8 +144,14 @@ library TaikoData {
address assignedProver; // slot 2
uint96 livenessBond;
uint64 blockId; // slot 3
uint64 proposedAt; // timestamp
uint64 proposedIn; // L1 block number, required/used by node/client.
// Before the fork, this field is the L1 timestamp when this block is proposed.
// After the fork, this is the timestamp of the L2 block.
// In a later fork, we an rename this field to `timestamp`.
uint64 proposedAt;
// Before the fork, this field is the L1 block number where this block is proposed.
// After the fork, this is the L1 block number input for the anchor transaction.
// In a later fork, we an rename this field to `anchorBlockId`.
uint64 proposedIn;
uint32 nextTransitionId;
// The ID of the transaction that is used to verify this block. However, if
// this block is not verified as the last block in a batch, verifiedTransitionId
Expand Down
5 changes: 4 additions & 1 deletion packages/protocol/contracts/L1/TaikoErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ abstract contract TaikoErrors {
error L1_BLOB_NOT_FOUND();
error L1_BLOCK_MISMATCH();
error L1_CANNOT_CONTEST();
error L1_FORK_ERROR();
error L1_INVALID_BLOCK_ID();
error L1_INVALID_CONFIG();
error L1_INVALID_GENESIS_HASH();
error L1_INVALID_ANCHOR_BLOCK();
error L1_INVALID_PARAM();
error L1_INVALID_PAUSE_STATUS();
error L1_INVALID_SIG();
error L1_INVALID_PROPOSER();
error L1_INVALID_TIER();
error L1_INVALID_TIMESTAMP();
error L1_INVALID_TRANSITION();
error L1_LIVENESS_BOND_NOT_RECEIVED();
error L1_NOT_ASSIGNED_PROVER();
Expand Down
23 changes: 23 additions & 0 deletions packages/protocol/contracts/L1/TaikoEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ abstract contract TaikoEvents {
TaikoData.EthDeposit[] depositsProcessed
);

/// @notice Emitted when a block is proposed.
/// @param blockId The ID of the proposed block.
/// @param meta The metadata of the proposed block.
event BlockProposed2(uint256 indexed blockId, TaikoData.BlockMetadata2 meta);

/// @notice Emitted when a block's txList is in the calldata.
/// @param blockId The ID of the proposed block.
/// @param txList The txList.
Expand Down Expand Up @@ -65,6 +70,15 @@ abstract contract TaikoEvents {
uint16 tier
);

event TransitionProved2(
uint256 indexed blockId,
TaikoData.Transition tran,
address prover,
uint96 validityBond,
uint16 tier,
uint64 proposedIn
);

/// @dev Emitted when a block transition is contested.
/// @param blockId The ID of the proven block.
/// @param tran The verified transition.
Expand All @@ -79,6 +93,15 @@ abstract contract TaikoEvents {
uint16 tier
);

event TransitionContested2(
uint256 indexed blockId,
TaikoData.Transition tran,
address contester,
uint96 contestBond,
uint16 tier,
uint64 proposedIn
);

/// @dev Emitted when proving has been paused
/// @param paused True if paused, false if unpaused.
event ProvingPaused(bool paused);
Expand Down
28 changes: 26 additions & 2 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.24;

import "../common/EssentialContract.sol";
import "./libs/LibData.sol";
import "./libs/LibProposing.sol";
import "./libs/LibProving.sol";
import "./libs/LibVerifying.sol";
Expand Down Expand Up @@ -81,7 +82,30 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
TaikoData.Config memory config = getConfig();
TaikoToken tko = TaikoToken(resolve(LibStrings.B_TAIKO_TOKEN, false));

(meta_, deposits_) = LibProposing.proposeBlock(state, tko, config, this, _params, _txList);
TaikoData.BlockMetadata2 memory meta2;
(meta2, deposits_) = LibProposing.proposeBlock(state, tko, config, this, _params, _txList);

if (meta2.id >= config.fujiForkHeight) revert L1_FORK_ERROR();

if (LibUtils.shouldVerifyBlocks(config, meta_.id, true) && !state.slotB.provingPaused) {
LibVerifying.verifyBlocks(state, tko, config, this, config.maxBlocksToVerify);
}
meta_ = LibData.metadataV2toV1(meta2);
}

function proposeBlock2(
bytes calldata _params,
bytes calldata _txList
)
external
payable
returns (TaikoData.BlockMetadata2 memory meta_)
{
TaikoData.Config memory config = getConfig();
TaikoToken tko = TaikoToken(resolve(LibStrings.B_TAIKO_TOKEN, false));

(meta_,) = LibProposing.proposeBlock(state, tko, config, this, _params, _txList);
if (meta_.id < config.fujiForkHeight) revert L1_FORK_ERROR();

if (LibUtils.shouldVerifyBlocks(config, meta_.id, true) && !state.slotB.provingPaused) {
LibVerifying.verifyBlocks(state, tko, config, this, config.maxBlocksToVerify);
Expand Down Expand Up @@ -234,7 +258,7 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
blockMaxGasLimit: 240_000_000,
livenessBond: 125e18, // 125 Taiko token
stateRootSyncInternal: 16,
checkEOAForCalldataDA: true
fujiForkHeight: 324_512 * 2
});
}

Expand Down
13 changes: 13 additions & 0 deletions packages/protocol/contracts/L1/access/IProposerAccess.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

/// @title IProposerAccess
/// @dev An interface to check if a proposer is eligible to propose blocks in a specific Ethereum
/// block.
/// @custom:security-contact [email protected]
interface IProposerAccess {
/// @notice Checks if a proposer can propose block in the current Ethereum block.
/// @param _proposer The proposer.
/// @return true if the proposer can propose blocks, false otherwise.
function isProposerEligible(address _proposer) external view returns (bool);
}
Comment on lines +8 to +13
Copy link
Contributor

@adaki2004 adaki2004 Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for client interface point of view, would be good to use the exact same namings like here, in this PR, if we wanna reuse the backend OR use this naming (IProposerAccess) there, to avoid duplicated, unnecessary work later.
cc @Brechtpd @dantaik

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the word sequencer. And I also believe going forward, ISequencerRegistry will also change due to the dependency on restaking platforms/protocols.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ISequencerRegistry very likely stable because how the implementation selects the current proposer does not matter to taiko.

Sequencer vs proposer is subjective, I'm fine with both but people do tend to use the word sequencer here to stress that they are sequencing the blocks and there's only one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can change it later. I think we just care about the permission checking function rather than the registration logics.

52 changes: 52 additions & 0 deletions packages/protocol/contracts/L1/access/ProposerRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "../../common/EssentialContract.sol";
import "./IProposerAccess.sol";

/// @title ProposerRegistry
/// A dummy implementation that only whitelist some trusted addresses. A real
/// implementation would only allow a single proposer address to propose a block
/// using some selection mechanism.
/// @custom:security-contact [email protected]
contract ProposerRegistry is EssentialContract, IProposerAccess {
/// @dev Emitted when the status of a proposer is updated.
/// @param proposer The address of the proposer whose state has updated.
/// @param enabled If the proposer is now enabled or not.
event ProposerUpdated(address indexed proposer, bool enabled);

error PR_INVALID_PARAM();

/// @notice Whitelisted proposers
mapping(address proposer => bool enabled) public proposers;

uint256[49] private __gap;

/// @notice Initializes the contract with the provided address manager.
/// @param _owner The address of the owner.
function init(address _owner) external initializer {
__Essential_init(_owner);
}

/// @notice Register or unregister proposers.
/// @param _proposers The list of proposers
/// @param _enabled The corresponding list of the new status of the proposers
function registerProposers(
address[] memory _proposers,
bool[] memory _enabled
)
external
onlyOwner
{
if (_proposers.length != _enabled.length) revert PR_INVALID_PARAM();
for (uint256 i = 0; i < _proposers.length; ++i) {
proposers[_proposers[i]] = _enabled[i];
emit ProposerUpdated(_proposers[i], _enabled[i]);
}
}

/// @inheritdoc IProposerAccess
function isProposerEligible(address _proposer) external view returns (bool) {
return proposers[_proposer];
}
}
91 changes: 91 additions & 0 deletions packages/protocol/contracts/L1/libs/LibData.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "../TaikoData.sol";

/// @title LibData
/// @notice A library that offers helper functions.
/// @custom:security-contact [email protected]
library LibData {
// = keccak256(abi.encode(new TaikoData.EthDeposit[](0)))
bytes32 internal constant EMPTY_ETH_DEPOSIT_HASH =
0x569e75fc77c1a856f6daaf9e69d8a9566ca34aa47f9133711ce065a571af0cfd;

function paramV1toV2(TaikoData.BlockParams memory _v1)
internal
pure
returns (TaikoData.BlockParams2 memory)
{
return TaikoData.BlockParams2({
coinbase: _v1.coinbase,
extraData: _v1.extraData,
parentMetaHash: _v1.parentMetaHash,
anchorBlockId: 0,
timestamp: 0
});
}

function metadataV2toV1(TaikoData.BlockMetadata2 memory _v2)
internal
pure
returns (TaikoData.BlockMetadata memory)
{
return TaikoData.BlockMetadata({
l1Hash: _v2.anchorBlockHash,
difficulty: _v2.difficulty,
blobHash: _v2.blobHash,
extraData: _v2.extraData,
depositsHash: EMPTY_ETH_DEPOSIT_HASH,
coinbase: _v2.coinbase,
id: _v2.id,
gasLimit: _v2.gasLimit,
timestamp: _v2.timestamp,
l1Height: _v2.anchorBlockId,
minTier: _v2.minTier,
blobUsed: _v2.blobUsed,
parentMetaHash: _v2.parentMetaHash,
sender: _v2.proposer
});
}

function metadataV1toV2(
TaikoData.BlockMetadata memory _v1,
uint96 _livenessBond
)
internal
pure
returns (TaikoData.BlockMetadata2 memory)
{
return TaikoData.BlockMetadata2({
anchorBlockHash: _v1.l1Hash,
difficulty: _v1.difficulty,
blobHash: _v1.blobHash,
extraData: _v1.extraData,
coinbase: _v1.coinbase,
id: _v1.id,
gasLimit: _v1.gasLimit,
timestamp: _v1.timestamp,
anchorBlockId: _v1.l1Height,
minTier: _v1.minTier,
blobUsed: _v1.blobUsed,
parentMetaHash: _v1.parentMetaHash,
proposer: _v1.sender,
livenessBond: _livenessBond,
proposedAt: 0,
proposedIn: 0
});
}

function hashMetadata(
bool postFork,
TaikoData.BlockMetadata2 memory _meta
)
internal
pure
returns (bytes32)
{
return postFork
? keccak256(abi.encode(_meta)) //
: keccak256(abi.encode(metadataV2toV1(_meta)));
}
}
Loading