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): add TIER_ZKVM_RISC0 tier and HeklaTierProvider #17913

Merged
merged 8 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions packages/protocol/contracts/L1/tiers/ITierProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ library LibTiers {
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;

Expand Down
45 changes: 29 additions & 16 deletions packages/protocol/contracts/L1/tiers/TierProviderBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ abstract contract TierProviderBase is ITierProvider {
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
)
Expand All @@ -27,9 +29,9 @@ abstract contract TierProviderBase is ITierProvider {
if (_tierId == LibTiers.TIER_OPTIMISTIC) {
return ITierProvider.Tier({
verifierName: "",
validityBond: 125 ether, // TKO
contestBond: 250 ether, // TKO
cooldownWindow: 1440, //24 hours
validityBond: 100 ether, // TAIKO
contestBond: 656.25 ether, // = 100 TAIKO * 6.5625
cooldownWindow: 1440, // 24 hours
provingWindow: GRACE_PERIOD + 15, // 15 minutes
maxBlocksToVerifyPerProof: 0
});
Expand All @@ -38,31 +40,42 @@ abstract contract TierProviderBase is ITierProvider {
if (_tierId == LibTiers.TIER_SGX) {
return ITierProvider.Tier({
verifierName: LibStrings.B_TIER_SGX,
validityBond: 125 ether, // TKO
contestBond: 820 ether, // =250TKO * 6.5625
cooldownWindow: 1440, //24 hours
provingWindow: GRACE_PERIOD + 60, // 1 hours
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 == LibTiers.TIER_SGX2) {
return ITierProvider.Tier({
verifierName: LibStrings.B_TIER_SGX2,
validityBond: 125 ether, // TKO
contestBond: 820 ether, // =250TKO * 6.5625
cooldownWindow: 1440, //24 hours
provingWindow: GRACE_PERIOD + 60, // 1 hours
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 == LibTiers.TIER_ZKVM_RISC0) {
return ITierProvider.Tier({
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 == LibTiers.TIER_SGX_ZKVM) {
return ITierProvider.Tier({
verifierName: LibStrings.B_TIER_SGX_ZKVM,
validityBond: 250 ether, // TKO
contestBond: 1640 ether, // =500TKO * 6.5625
cooldownWindow: 1440, //24 hours
validityBond: 300 ether, // TAIKO
contestBond: 1968.75 ether, // = 300 TAIKO * 6.5625
cooldownWindow: 1440, // 24 hours
provingWindow: GRACE_PERIOD + 240, // 4 hours
maxBlocksToVerifyPerProof: 0
});
Expand All @@ -71,8 +84,8 @@ abstract contract TierProviderBase is ITierProvider {
if (_tierId == LibTiers.TIER_GUARDIAN_MINORITY) {
return ITierProvider.Tier({
verifierName: LibStrings.B_TIER_GUARDIAN_MINORITY,
validityBond: 250 ether, // TKO
contestBond: 1640 ether, // =500TKO * 6.5625
validityBond: 350 ether, // TAIKO
contestBond: 2296.875 ether, // = 350 TAIKO * 6.5625
cooldownWindow: GRACE_PERIOD + 240, // 4 hours
provingWindow: 2880, // 48 hours
maxBlocksToVerifyPerProof: 0
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/contracts/common/LibStrings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ library LibStrings {
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_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_WITHDRAWER = bytes32("withdrawer");
Expand Down
30 changes: 30 additions & 0 deletions packages/protocol/contracts/hekla/HeklaTierProvider.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "../L1/tiers/TierProviderBase.sol";

/// @title HeklaTierProvider
/// @custom:security-contact [email protected]
contract HeklaTierProvider is TierProviderBase {
/// @inheritdoc ITierProvider
function getTierIds() public pure override returns (uint16[] memory tiers_) {
tiers_ = new uint16[](5);
tiers_[0] = LibTiers.TIER_OPTIMISTIC;
tiers_[1] = LibTiers.TIER_SGX;
tiers_[2] = LibTiers.TIER_ZKVM_RISC0;
tiers_[3] = LibTiers.TIER_GUARDIAN_MINORITY;
tiers_[4] = LibTiers.TIER_GUARDIAN;
}

/// @inheritdoc ITierProvider
function getMinTier(uint256 _rand) public pure override returns (uint16) {
if (_rand % 1000 == 0) {
// 0.1% of the total blocks will require ZKVM proofs.
return LibTiers.TIER_ZKVM_RISC0;
} else if (_rand % 2 == 0) {
// 50% of the total blocks will require SGX proofs.
return LibTiers.TIER_SGX;
}
return LibTiers.TIER_OPTIMISTIC;
}
}
12 changes: 12 additions & 0 deletions packages/protocol/deployments/hekla-contract-logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@
- upgraded on Jun 10, 2024 at commit `d5965bb`
- transfered ownership on Jul 8, 2024

### risc0_groth16_verifier
- addr : 0xc2c2676E31b59085dfDA9b1B066519b20e756D9d
- logs:
- deployed on August 14, 2024 at commit `cba2a1e`

### tier_zkvm_risc0
- proxy : 0x4fEd801C5a876D4289e869cbEfA1E1A448b10714
- impl : 0x33BD79aA6a24d8ED4413E01FEc546D4d49bF6C39
- owner : 0x1D2D1bb9D180541E88a6a682aCf3f61c1605B190
- logs:
- deployed on August 14, 2024 at commit `cba2a1e`

## L2 Contracts

### bridge
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/script/DeployOnL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ contract DeployOnL1 is DeployCapability {
register(rollupAddressManager, "risc0_groth16_verifier", address(verifier));

deployProxy({
name: "risc0_verifier",
name: "tier_zkvm_risc0",
impl: address(new RiscZeroVerifier()),
data: abi.encodeCall(RiscZeroVerifier.init, (owner, rollupAddressManager)),
registerTo: rollupAddressManager
Expand Down
28 changes: 28 additions & 0 deletions packages/protocol/script/DeployRisc0Verifier.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.24;

import "@risc0/contracts/groth16/RiscZeroGroth16Verifier.sol";
import "../test/DeployCapability.sol";
import "../contracts/verifiers/RiscZeroVerifier.sol";

contract DeployRisc0Verifier is DeployCapability {
uint256 public deployerPrivKey = vm.envUint("PRIVATE_KEY");
address public rollupAddressManager = vm.envAddress("ROLLUP_ADDRESS_MANAGER");

function run() external {
require(deployerPrivKey != 0, "invalid deployer priv key");
require(rollupAddressManager != address(0), "invalid rollup address manager address");

vm.startBroadcast(deployerPrivKey);
RiscZeroGroth16Verifier verifier =
new RiscZeroGroth16Verifier(ControlID.CONTROL_ROOT, ControlID.BN254_CONTROL_ID);
register(rollupAddressManager, "risc0_groth16_verifier", address(verifier));
deployProxy({
name: "tier_zkvm_risc0",
impl: address(new RiscZeroVerifier()),
data: abi.encodeCall(RiscZeroVerifier.init, (address(0), rollupAddressManager)),
registerTo: rollupAddressManager
});
vm.stopBroadcast();
}
}