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

refactor #17951

Merged
merged 50 commits into from
Aug 20, 2024
Merged

refactor #17951

Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0da4756
make easy to compose multiple verifiers into one.
dantaik Aug 19, 2024
5f8f8ce
Update ZkVMVerifier.sol
dantaik Aug 19, 2024
2c4ffc4
Update package.json
dantaik Aug 19, 2024
129f888
Update pnpm-lock.yaml
dantaik Aug 19, 2024
1eaed4d
Update ZkVMVerifier.sol
dantaik Aug 19, 2024
847f65a
rename
dantaik Aug 19, 2024
024b6c8
Update ComposeVerifier.sol
dantaik Aug 19, 2024
cb49acd
Update ComposeVerifier.sol
dantaik Aug 19, 2024
6fa8ff2
Create ComposeVerifeir.t.sol
dantaik Aug 19, 2024
b75fcdf
Update ComposeVerifeir.t.sol
dantaik Aug 19, 2024
07810a2
Update MainnetZkVMVerifier.sol
dantaik Aug 19, 2024
49ec442
simplify
dantaik Aug 19, 2024
d2094ba
more
dantaik Aug 19, 2024
53147e6
Update ComposeVerifier.sol
dantaik Aug 19, 2024
cf3ae3b
more
dantaik Aug 20, 2024
4885609
Update gen-layouts.sh
dantaik Aug 20, 2024
8ad4245
Update gen-layouts.sh
dantaik Aug 20, 2024
e35333d
Merge branch 'main' into compose_verifiers
dantaik Aug 20, 2024
f150a4e
more
dantaik Aug 20, 2024
cca1a9d
more
dantaik Aug 20, 2024
be96345
more
dantaik Aug 20, 2024
fb23447
forge fmt & update contract layout table
dantaik Aug 20, 2024
a6d8f0b
Update ITierProvider.sol
dantaik Aug 20, 2024
8c452bd
fix
dantaik Aug 20, 2024
381a7ef
Update TierProviderV2.sol
dantaik Aug 20, 2024
d134bb2
Create TierProviderV3.sol
dantaik Aug 20, 2024
62cc477
Update HeklaTierProvider.sol
dantaik Aug 20, 2024
a38f5df
more
dantaik Aug 20, 2024
29e125b
Merge branch 'main' into compose_verifiers
dantaik Aug 20, 2024
7cbd43d
more
dantaik Aug 20, 2024
0b9a8a3
more
dantaik Aug 20, 2024
de98a6e
Update TierProviderV2.sol
dantaik Aug 20, 2024
7e5b03f
more
dantaik Aug 20, 2024
e883b14
more
dantaik Aug 20, 2024
d5b17cc
more
dantaik Aug 20, 2024
518571c
more
dantaik Aug 20, 2024
666697b
more
dantaik Aug 20, 2024
40f6ea6
rename
dantaik Aug 20, 2024
392cc42
more
dantaik Aug 20, 2024
4efa662
Update LibStrings.sol
dantaik Aug 20, 2024
1ed0b70
more
dantaik Aug 20, 2024
e6aa39d
more
dantaik Aug 20, 2024
893a766
Revert "more"
dantaik Aug 20, 2024
1d35ed1
Revert "more"
dantaik Aug 20, 2024
1f03dd8
Revert "Update LibStrings.sol"
dantaik Aug 20, 2024
41e28e6
Revert "more"
dantaik Aug 20, 2024
afb212f
Revert "rename"
dantaik Aug 20, 2024
0c8218e
Revert "more"
dantaik Aug 20, 2024
1faaa3c
Update TierProviderV2.sol
dantaik Aug 20, 2024
12e77f1
Merge branch 'refactor_tiers' into compose_verifiers
dantaik Aug 20, 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
148 changes: 93 additions & 55 deletions packages/protocol/contract_layout.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions packages/protocol/contracts/L1/tiers/DevnetTierProvider.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "./TierProviderBase.sol";
import "./TierProviderV2.sol";
import "./ITierRouter.sol";

/// @title DevnetTierProvider
/// @custom:security-contact security@taiko.xyz
contract DevnetTierProvider is TierProviderBase, ITierRouter {
contract DevnetTierProvider is TierProviderV2, ITierRouter {
/// @inheritdoc ITierRouter
function getProvider(uint256) external view returns (address) {
return address(this);
Expand All @@ -15,13 +15,13 @@ contract DevnetTierProvider is TierProviderBase, ITierRouter {
/// @inheritdoc ITierProvider
function getTierIds() public pure override returns (uint16[] memory tiers_) {
tiers_ = new uint16[](3);
tiers_[0] = LibTiers.TIER_OPTIMISTIC;
tiers_[1] = LibTiers.TIER_GUARDIAN_MINORITY;
tiers_[2] = LibTiers.TIER_GUARDIAN;
tiers_[0] = LibTierId.TIER_OPTIMISTIC;
tiers_[1] = LibTierId.TIER_GUARDIAN_MINORITY;
tiers_[2] = LibTierId.TIER_GUARDIAN;
}

/// @inheritdoc ITierProvider
function getMinTier(address, uint256) public pure override returns (uint16) {
return LibTiers.TIER_OPTIMISTIC;
return LibTierId.TIER_OPTIMISTIC;
}
}
24 changes: 2 additions & 22 deletions packages/protocol/contracts/L1/tiers/ITierProvider.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "./LibTierId.sol";

/// @title ITierProvider
/// @notice Defines interface to return tier configuration.
/// @custom:security-contact security@taiko.xyz
Expand Down Expand Up @@ -33,25 +35,3 @@ interface ITierProvider {
/// @return The tier id.
function getMinTier(address proposer, uint256 rand) external view returns (uint16);
}

/// @dev Tier ID cannot be zero!
library LibTiers {
/// @notice Optimistic tier ID.
uint16 public constant TIER_OPTIMISTIC = 100;

/// @notice SGX tier ID.
uint16 public constant TIER_SGX = 200;
uint16 public constant TIER_SGX2 = 200;

// @notice ZKVM risc0 tier ID
uint16 public constant TIER_ZKVM_RISC0 = 290;

/// @notice SGX + ZKVM tier ID.
uint16 public constant TIER_SGX_ZKVM = 300;

/// @notice Guardian tier ID with minority approval.
uint16 public constant TIER_GUARDIAN_MINORITY = 900;

/// @notice Guardian tier ID with majority approval.
uint16 public constant TIER_GUARDIAN = 1000;
}
26 changes: 26 additions & 0 deletions packages/protocol/contracts/L1/tiers/LibTierId.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

/// @title LibTierId
/// @dev Unique identifiers for all supported tiers. Each tier must have a distinct ID to avoid
/// conflicts.
/// @custom:security-contact security@taiko.xyz
library LibTierId {
/// @notice Optimistic tier ID.
uint16 public constant TIER_OPTIMISTIC = 100;

/// @notice TEE tier
uint16 public constant TIER_TEE = 200;

/// @notice ZKVM tier
uint16 public constant TIER_ZKVM = 290;

/// @notice TEE + ZK tier
uint16 public constant TIER_ZKVM_PLUS_TEE = 300;

/// @notice Guardian tier ID with minority approval.
uint16 public constant TIER_GUARDIAN_MINORITY = 900;

/// @notice Guardian tier ID with majority approval.
uint16 public constant TIER_GUARDIAN = 1000;
}
108 changes: 0 additions & 108 deletions packages/protocol/contracts/L1/tiers/TierProviderBase.sol

This file was deleted.

99 changes: 91 additions & 8 deletions packages/protocol/contracts/L1/tiers/TierProviderV2.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,104 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "./TierProviderBase.sol";
import "../../common/LibStrings.sol";
import "./ITierProvider.sol";

/// @title TierProviderV2
/// @custom:security-contact security@taiko.xyz
contract TierProviderV2 is TierProviderBase {
contract TierProviderV2 is ITierProvider {
/// @dev Grace period for block proving service.
/// @notice This constant defines the time window (in minutes) during which the block proving
/// service may be paused if gas prices are excessively high. Since block proving is
/// asynchronous, this grace period allows provers to defer submissions until gas
/// prices become more favorable, potentially reducing transaction costs.
uint16 public constant GRACE_PERIOD = 240; // 4 hours

/// @inheritdoc ITierProvider
/// @notice Each tier, except the top tier, has a validity bond that is 50 TAIKO higher than the
/// previous tier. Additionally, each tier's contest bond is 6.5625 times its validity bond.
function getTier(uint16 _tierId) public pure override returns (ITierProvider.Tier memory) {
if (_tierId == LibTierId.TIER_OPTIMISTIC) {
return ITierProvider.Tier({
verifierName: "",
validityBond: 100 ether, // TAIKO
contestBond: 656.25 ether, // = 100 TAIKO * 6.5625
cooldownWindow: 1440, // 24 hours
provingWindow: GRACE_PERIOD + 15, // 15 minutes
maxBlocksToVerifyPerProof: 0
});
}

if (_tierId == LibTierId.TIER_TEE) {
return ITierProvider.Tier({
// verifierName can also be B_TIER_TEE
verifierName: LibStrings.B_TIER_TEE_SGX,
validityBond: 150 ether, // TAIKO
contestBond: 984.375 ether, // = 150 TAIKO * 6.5625
cooldownWindow: 1440, // 24 hours
provingWindow: GRACE_PERIOD + 60, // 1 hour
maxBlocksToVerifyPerProof: 0
});
}

if (_tierId == LibTierId.TIER_ZKVM) {
return ITierProvider.Tier({
// verifierName can also be B_TIER_ZKVM and B_TIER_ZKVM_SP1
verifierName: LibStrings.B_TIER_ZKVM_RISC0,
validityBond: 250 ether, // TAIKO
contestBond: 1640.625 ether, // = 250 TAIKO * 6.5625
cooldownWindow: 1440, // 24 hours
provingWindow: GRACE_PERIOD + 180, // 3 hours
maxBlocksToVerifyPerProof: 0
});
}

if (_tierId == LibTierId.TIER_ZKVM_PLUS_TEE) {
return ITierProvider.Tier({
verifierName: LibStrings.B_TIER_ZKVM_AND_TEE,
validityBond: 300 ether, // TAIKO
contestBond: 1968.75 ether, // = 300 TAIKO * 6.5625
cooldownWindow: 1440, // 24 hours
provingWindow: GRACE_PERIOD + 240, // 4 hours
maxBlocksToVerifyPerProof: 0
});
}

if (_tierId == LibTierId.TIER_GUARDIAN_MINORITY) {
return ITierProvider.Tier({
verifierName: LibStrings.B_TIER_GUARDIAN_MINORITY,
validityBond: 350 ether, // TAIKO
contestBond: 2296.875 ether, // = 350 TAIKO * 6.5625
cooldownWindow: GRACE_PERIOD + 240, // 4 hours
provingWindow: 2880, // 48 hours
maxBlocksToVerifyPerProof: 0
});
}

if (_tierId == LibTierId.TIER_GUARDIAN) {
return ITierProvider.Tier({
verifierName: LibStrings.B_TIER_GUARDIAN,
validityBond: 0, // must be 0 for top tier
contestBond: 0, // must be 0 for top tier
cooldownWindow: 1440, // 24 hours
provingWindow: GRACE_PERIOD + 2880, // 48 hours
maxBlocksToVerifyPerProof: 0
});
}

revert TIER_NOT_FOUND();
}

/// @inheritdoc ITierProvider
function getTierIds() public pure override returns (uint16[] memory tiers_) {
function getTierIds() public pure virtual override returns (uint16[] memory tiers_) {
tiers_ = new uint16[](3);
tiers_[0] = LibTiers.TIER_SGX;
tiers_[1] = LibTiers.TIER_GUARDIAN_MINORITY;
tiers_[2] = LibTiers.TIER_GUARDIAN;
tiers_[0] = LibTierId.TIER_TEE;
tiers_[1] = LibTierId.TIER_GUARDIAN_MINORITY;
tiers_[2] = LibTierId.TIER_GUARDIAN;
}

/// @inheritdoc ITierProvider
function getMinTier(address, uint256) public pure override returns (uint16) {
return LibTiers.TIER_SGX;
function getMinTier(address, uint256) public pure virtual override returns (uint16) {
return LibTierId.TIER_TEE;
}
}
21 changes: 0 additions & 21 deletions packages/protocol/contracts/L1/tiers/TierProviderV3.sol

This file was deleted.

13 changes: 9 additions & 4 deletions packages/protocol/contracts/common/LibStrings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ library LibStrings {
bytes32 internal constant B_PROVER_ASSIGNMENT = bytes32("PROVER_ASSIGNMENT");
bytes32 internal constant B_PROVER_SET = bytes32("prover_set");
bytes32 internal constant B_QUOTA_MANAGER = bytes32("quota_manager");
bytes32 internal constant B_RISCZERO_GROTH16_VERIFIER = bytes32("risc0_groth16_verifier");
bytes32 internal constant B_SGX_WATCHDOG = bytes32("sgx_watchdog");
bytes32 internal constant B_SIGNAL_SERVICE = bytes32("signal_service");
bytes32 internal constant B_SP1_REMOTE_VERIFIER = bytes32("sp1_remote_verifier");
Expand All @@ -26,11 +27,15 @@ library LibStrings {
bytes32 internal constant B_TIER_GUARDIAN = bytes32("tier_guardian");
bytes32 internal constant B_TIER_GUARDIAN_MINORITY = bytes32("tier_guardian_minority");
bytes32 internal constant B_TIER_ROUTER = bytes32("tier_router");
bytes32 internal constant B_TIER_SGX = bytes32("tier_sgx");
bytes32 internal constant B_TIER_SGX2 = bytes32("tier_sgx2");
bytes32 internal constant B_TIER_TEE = bytes32("tier_tee");

// keep the value to maintain backward compatibility.
bytes32 internal constant B_TIER_TEE_SGX = bytes32("tier_sgx");

bytes32 internal constant B_TIER_ZKVM = bytes32("tier_zkvm");
bytes32 internal constant B_TIER_ZKVM_AND_TEE = bytes32("tier_zkvm_and_tee");
bytes32 internal constant B_TIER_ZKVM_RISC0 = bytes32("tier_zkvm_risc0");
bytes32 internal constant B_TIER_SGX_ZKVM = bytes32("tier_sgx_zkvm");
bytes32 internal constant B_RISCZERO_GROTH16_VERIFIER = bytes32("risc0_groth16_verifier");
bytes32 internal constant B_TIER_ZKVM_SP1 = bytes32("tier_zkvm_sp1");
bytes32 internal constant B_WITHDRAWER = bytes32("withdrawer");
bytes32 internal constant H_RETURN_LIVENESS_BOND = keccak256("RETURN_LIVENESS_BOND");
bytes32 internal constant H_SIGNAL_ROOT = keccak256("SIGNAL_ROOT");
Expand Down
Loading
Loading