From 64ed66628a18cb1b3fff2c4ab5d3c0149288dfe6 Mon Sep 17 00:00:00 2001 From: Gavin Yu Date: Thu, 15 Aug 2024 11:33:07 +0800 Subject: [PATCH] feat(protocol): add `TIER_ZKVM_RISC0` tier and `HeklaTierProvider` (#17913) Co-authored-by: YoGhurt111 Co-authored-by: David Co-authored-by: Daniel Wang --- .../contracts/L1/tiers/ITierProvider.sol | 3 ++ .../contracts/L1/tiers/TierProviderBase.sol | 45 ++++++++++++------- .../protocol/contracts/common/LibStrings.sol | 1 + .../contracts/hekla/HeklaTierProvider.sol | 30 +++++++++++++ .../deployments/hekla-contract-logs.md | 12 +++++ packages/protocol/script/DeployOnL1.s.sol | 2 +- .../protocol/script/DeployRisc0Verifier.s.sol | 28 ++++++++++++ 7 files changed, 104 insertions(+), 17 deletions(-) create mode 100644 packages/protocol/contracts/hekla/HeklaTierProvider.sol create mode 100644 packages/protocol/script/DeployRisc0Verifier.s.sol diff --git a/packages/protocol/contracts/L1/tiers/ITierProvider.sol b/packages/protocol/contracts/L1/tiers/ITierProvider.sol index 7faf63571ff..474867446ff 100644 --- a/packages/protocol/contracts/L1/tiers/ITierProvider.sol +++ b/packages/protocol/contracts/L1/tiers/ITierProvider.sol @@ -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; diff --git a/packages/protocol/contracts/L1/tiers/TierProviderBase.sol b/packages/protocol/contracts/L1/tiers/TierProviderBase.sol index 9fbc61bf22b..bbf4fc2ec16 100644 --- a/packages/protocol/contracts/L1/tiers/TierProviderBase.sol +++ b/packages/protocol/contracts/L1/tiers/TierProviderBase.sol @@ -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 ) @@ -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 }); @@ -38,10 +40,10 @@ 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 }); } @@ -49,10 +51,21 @@ abstract contract TierProviderBase is ITierProvider { 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 }); } @@ -60,9 +73,9 @@ abstract contract TierProviderBase is ITierProvider { 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 }); @@ -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 diff --git a/packages/protocol/contracts/common/LibStrings.sol b/packages/protocol/contracts/common/LibStrings.sol index 4e1e014d1ca..43a4ad66972 100644 --- a/packages/protocol/contracts/common/LibStrings.sol +++ b/packages/protocol/contracts/common/LibStrings.sol @@ -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"); diff --git a/packages/protocol/contracts/hekla/HeklaTierProvider.sol b/packages/protocol/contracts/hekla/HeklaTierProvider.sol new file mode 100644 index 00000000000..3b0c77701fe --- /dev/null +++ b/packages/protocol/contracts/hekla/HeklaTierProvider.sol @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.24; + +import "../L1/tiers/TierProviderBase.sol"; + +/// @title HeklaTierProvider +/// @custom:security-contact security@taiko.xyz +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; + } +} diff --git a/packages/protocol/deployments/hekla-contract-logs.md b/packages/protocol/deployments/hekla-contract-logs.md index f110716c414..87df44a4b2d 100644 --- a/packages/protocol/deployments/hekla-contract-logs.md +++ b/packages/protocol/deployments/hekla-contract-logs.md @@ -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 diff --git a/packages/protocol/script/DeployOnL1.s.sol b/packages/protocol/script/DeployOnL1.s.sol index c880b2b0560..a912b8cf374 100644 --- a/packages/protocol/script/DeployOnL1.s.sol +++ b/packages/protocol/script/DeployOnL1.s.sol @@ -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 diff --git a/packages/protocol/script/DeployRisc0Verifier.s.sol b/packages/protocol/script/DeployRisc0Verifier.s.sol new file mode 100644 index 00000000000..04a6fc71b4d --- /dev/null +++ b/packages/protocol/script/DeployRisc0Verifier.s.sol @@ -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(); + } +}