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): apply multiple improvements for "ontake" fork #17734

Merged
merged 60 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
35768ec
feat(protocol): prepare `ontake` fork to support new params & metadat…
dantaik Jul 4, 2024
3f93b70
respond to comments
dantaik Jul 6, 2024
96544ce
Update LibProposing.sol
dantaik Jul 6, 2024
39a784e
Update LibProposing.sol
dantaik Jul 6, 2024
a9c1d00
Merge branch 'main' into ontake_fork
dantaik Jul 7, 2024
e878336
Update TaikoL1TestGroupBase.sol
dantaik Jul 7, 2024
c5d7519
more
dantaik Jul 7, 2024
6ca42ea
Merge branch 'main' into ontake_fork
dantaik Jul 11, 2024
235d42f
Merge branch 'main' into ontake_fork
dantaik Jul 11, 2024
78df730
Update TaikoL1Hekla.sol
dantaik Jul 11, 2024
2668736
Merge branch 'main' into ontake_fork
dantaik Jul 11, 2024
a60716e
BlockVerified2
dantaik Jul 11, 2024
35b8e00
more
dantaik Jul 11, 2024
7429b2a
proposeBlock2 nonpayable
dantaik Jul 13, 2024
cdc0f70
Create L1ProverSet.sol
dantaik Jul 13, 2024
2e53985
more
dantaik Jul 13, 2024
1bbf568
more
dantaik Jul 13, 2024
9f6302a
more
dantaik Jul 13, 2024
54421a0
Update ProverSet.sol
dantaik Jul 13, 2024
bf7142e
Update ProverSet.sol
dantaik Jul 13, 2024
4ebe4b6
Update ProverSet.sol
dantaik Jul 13, 2024
e03bbd5
Update ProverSet.sol
dantaik Jul 13, 2024
a5c867a
rename
dantaik Jul 14, 2024
ac422a5
more
dantaik Jul 14, 2024
7eadb0a
Merge branch 'prover_set_opt' into ontake_fork
dantaik Jul 14, 2024
00ba1fa
more
dantaik Jul 14, 2024
7988e9b
Merge branch 'prover_set_opt' into ontake_fork
dantaik Jul 14, 2024
bf6ffb6
Merge branch 'main' into ontake_fork
dantaik Jul 14, 2024
484cd10
fix MainnetTaikoL1 code too large
dantaik Jul 14, 2024
00e1997
Update TaikoEvents.sol
dantaik Jul 14, 2024
bdeaa52
Update DeployOnL1.s.sol
dantaik Jul 14, 2024
31412ef
Merge branch 'reduce_contract_size' into ontake_fork
dantaik Jul 14, 2024
8a50029
more
dantaik Jul 14, 2024
c869666
Merge branch 'main' into ontake_fork
dantaik Jul 15, 2024
751de97
add 3 more parameters
dantaik Jul 16, 2024
c0e89f5
L1_INVALID_BASEFEE_SHARING
dantaik Jul 16, 2024
a87a7bf
Merge branch 'main' into ontake_fork
dantaik Jul 16, 2024
2a406d2
Update LibRollupAddressCache.sol
dantaik Jul 16, 2024
e7afeb5
Merge branch 'main' into ontake_fork
dantaik Jul 17, 2024
20557fc
Update MainnetTierRouter.sol
dantaik Jul 17, 2024
e00507d
Update MainnetTierRouter.sol
dantaik Jul 17, 2024
22d0133
Update MainnetTierRouter.sol
dantaik Jul 17, 2024
c504176
Merge branch 'main' into ontake_fork
dantaik Jul 17, 2024
7a008ec
Merge branch 'main' into ontake_fork
dantaik Jul 19, 2024
08e6a3f
x2 to xV2
dantaik Jul 19, 2024
2359c84
Delete packages/protocol/contracts/L1/access/ProposerRegistry.sol
dantaik Jul 19, 2024
96b5a09
Update ProverSet.sol
dantaik Jul 19, 2024
fca0764
Update TaikoData.sol
dantaik Jul 19, 2024
114a967
fix
dantaik Jul 19, 2024
2727e9d
rename
dantaik Jul 19, 2024
254ef95
Merge branch 'main' into ontake_fork
dantaik Jul 19, 2024
d39aca0
rename
dantaik Jul 21, 2024
f2e2c8f
fix
dantaik Jul 21, 2024
c2df9e6
Merge branch 'main' into ontake_fork
dantaik Jul 21, 2024
66aafb5
Merge branch 'main' into ontake_fork
davidtaikocha Jul 22, 2024
59cbd8e
fix(protocol): change transition ID to uint24 and fix a liveness bond…
dantaik Jul 22, 2024
0f39c5c
Update TaikoL1.sol
dantaik Jul 22, 2024
46280cb
fix
dantaik Jul 22, 2024
33493aa
feat(protocol): relocate L2 basefee parameters to L1 configuration (#…
dantaik Jul 24, 2024
ebce3db
Merge branch 'main' into ontake_fork
mask-pp Jul 24, 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 ontakeForkHeight;
}

/// @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 {
dantaik marked this conversation as resolved.
Show resolved Hide resolved
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;
dantaik marked this conversation as resolved.
Show resolved Hide resolved
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
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 All @@ -27,6 +28,7 @@ contract TaikoL1 is EssentialContract, ITaikoL1 {
/// @param slotB The SlotB data structure.
event StateVariablesUpdated(TaikoData.SlotB slotB);

error L1_FORK_ERROR();
error L1_RECEIVE_DISABLED();

modifier whenProvingNotPaused() {
Expand Down Expand Up @@ -85,7 +87,29 @@ contract TaikoL1 is EssentialContract, ITaikoL1 {
{
TaikoData.Config memory config = getConfig();

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

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

if (LibUtils.shouldVerifyBlocks(config, meta_.id, true) && !state.slotB.provingPaused) {
LibVerifying.verifyBlocks(state, 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();

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

davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved
if (LibUtils.shouldVerifyBlocks(config, meta_.id, true) && !state.slotB.provingPaused) {
LibVerifying.verifyBlocks(state, config, this, config.maxBlocksToVerify);
Expand Down Expand Up @@ -246,7 +270,7 @@ contract TaikoL1 is EssentialContract, ITaikoL1 {
blockMaxGasLimit: 240_000_000,
livenessBond: 125e18, // 125 Taiko token
stateRootSyncInternal: 16,
checkEOAForCalldataDA: true
ontakeForkHeight: 324_512 * 2
dantaik marked this conversation as resolved.
Show resolved Hide resolved
});
}

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);
}
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)
davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved
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