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): user smaller cooldown windows #18345

Merged
merged 13 commits into from
Oct 30, 2024
6 changes: 0 additions & 6 deletions packages/protocol/contract_layout_layer1.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,6 @@
| state | struct TaikoData.State | 251 | 0 | 1600 | TaikoL1 |
| __gap | uint256[50] | 301 | 0 | 1600 | TaikoL1 |

## TierProviderV2
| Name | Type | Slot | Offset | Bytes | Contract |
|------|------|------|--------|-------|----------|

## HeklaTaikoL1
| Name | Type | Slot | Offset | Bytes | Contract |
|----------------|------------------------|------|--------|-------|------------------------------------------------------|
Expand All @@ -535,8 +531,6 @@
| __gap | uint256[50] | 301 | 0 | 1600 | HeklaTaikoL1 |

## HeklaTierProvider
| Name | Type | Slot | Offset | Bytes | Contract |
|------|------|------|--------|-------|----------|

## MainnetBridge
| Name | Type | Slot | Offset | Bytes | Contract |
Expand Down
9 changes: 4 additions & 5 deletions packages/protocol/contracts/layer1/based/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ library LibProving {

local.tier = tierProvider.getTier(local.proof.tier);
local.minTier = tierProvider.getTier(local.meta.minTier);
local.isTopTier = local.tier.contestBond == 0;
}

local.inProvingWindow = !LibUtils.isPostDeadline({
Expand All @@ -326,8 +327,8 @@ library LibProving {
// The assigned prover is granted exclusive permission to prove only the first
// transition.
if (
local.tier.contestBond != 0 && ts.contester == address(0) && local.tid == 1
&& ts.tier == 0 && local.inProvingWindow
!local.isTopTier && ts.contester == address(0) && local.tid == 1 && ts.tier == 0
dantaik marked this conversation as resolved.
Show resolved Hide resolved
&& local.inProvingWindow
) {
if (msg.sender != local.assignedProver) revert L1_NOT_ASSIGNED_PROVER();
}
Expand All @@ -353,7 +354,7 @@ library LibProving {
prover: msg.sender,
msgSender: msg.sender,
blockId: local.blockId,
isContesting: local.proof.tier == ts.tier && local.tier.contestBond != 0,
isContesting: local.proof.tier == ts.tier && !local.isTopTier,
blobUsed: local.meta.blobUsed,
tran: ctx_.tran
});
Expand All @@ -368,8 +369,6 @@ library LibProving {
}
}

local.isTopTier = local.tier.contestBond == 0;

local.sameTransition = local.isSyncBlock
? ctx_.tran.blockHash == ts.blockHash && local.stateRoot == ts.stateRoot
: ctx_.tran.blockHash == ts.blockHash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract DevnetTierRouter is TierProviderBase, ITierRouter {
}

/// @inheritdoc ITierProvider
function getTierIds() public pure override returns (uint16[] memory tiers_) {
function getTierIds() external pure returns (uint16[] memory tiers_) {
tiers_ = new uint16[](3);
tiers_[0] = LibTiers.TIER_OPTIMISTIC;
tiers_[1] = LibTiers.TIER_GUARDIAN_MINORITY;
Expand Down
49 changes: 0 additions & 49 deletions packages/protocol/contracts/layer1/hekla/HeklaTierProvider.sol

This file was deleted.

43 changes: 43 additions & 0 deletions packages/protocol/contracts/layer1/hekla/HeklaTierRouter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

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

/// @title HeklaTierRouter
/// @custom:security-contact [email protected]
contract HeklaTierRouter is TierProviderBase, ITierRouter {
address public immutable DAO_FALLBACK_PROPOSER;

constructor(address _daoFallbackProposer) {
// 0xD3f681bD6B49887A48cC9C9953720903967E9DC0
DAO_FALLBACK_PROPOSER = _daoFallbackProposer;
}
/// @inheritdoc ITierRouter

function getProvider(uint256) external view returns (address) {
return address(this);
}

/// @inheritdoc ITierProvider
function getTierIds() external pure returns (uint16[] memory tiers_) {
tiers_ = new uint16[](6);
tiers_[0] = LibTiers.TIER_OPTIMISTIC;
tiers_[1] = LibTiers.TIER_SGX;
tiers_[2] = LibTiers.TIER_ZKVM_RISC0;
tiers_[3] = LibTiers.TIER_ZKVM_SP1;
tiers_[4] = LibTiers.TIER_GUARDIAN_MINORITY;
tiers_[5] = LibTiers.TIER_GUARDIAN;
}

/// @inheritdoc ITierProvider
function getMinTier(address _proposer, uint256 _rand) public view override returns (uint16) {
if (_proposer == DAO_FALLBACK_PROPOSER) {
if (_rand % 1000 == 0) return LibTiers.TIER_ZKVM_RISC0;
else if (_rand % 1000 == 1) return LibTiers.TIER_ZKVM_SP1;
else return LibTiers.TIER_SGX;
}

return _rand % 2 == 0 ? LibTiers.TIER_SGX : LibTiers.TIER_OPTIMISTIC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,38 @@
pragma solidity ^0.8.24;

import "src/layer1/tiers/ITierRouter.sol";
import "src/layer1/tiers/TierProviderV2.sol";
import "src/layer1/tiers/TierProviderBase.sol";

/// @title MainnetTierRouter
/// @dev Labeled in AddressResolver as "tier_router"
/// @custom:security-contact [email protected]
contract MainnetTierRouter is ITierRouter, TierProviderV2 {
contract MainnetTierRouter is ITierRouter, TierProviderBase {
address public immutable DAO_FALLBACK_PROPOSER;

constructor(address _daoFallbackProposer) {
// 0xD3f681bD6B49887A48cC9C9953720903967E9DC0
DAO_FALLBACK_PROPOSER = _daoFallbackProposer;
}

/// @inheritdoc ITierRouter
function getProvider(uint256) external view returns (address) {
return address(this);
}

/// @inheritdoc ITierProvider
function getTierIds() external pure returns (uint16[] memory tiers_) {
tiers_ = new uint16[](4);
tiers_[0] = LibTiers.TIER_SGX;
tiers_[1] = LibTiers.TIER_ZKVM_ANY;
tiers_[2] = LibTiers.TIER_GUARDIAN_MINORITY;
tiers_[3] = LibTiers.TIER_GUARDIAN;
}

/// @inheritdoc ITierProvider
function getMinTier(address _proposer, uint256 _rand) public view override returns (uint16) {
if (_proposer == DAO_FALLBACK_PROPOSER) {
return _rand % 500 == 0 ? LibTiers.TIER_ZKVM_ANY : LibTiers.TIER_SGX;
}
return LibTiers.TIER_SGX;
}
}
27 changes: 14 additions & 13 deletions packages/protocol/contracts/layer1/tiers/TierProviderBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ abstract contract TierProviderBase is ITierProvider {
/// previous tier. Additionally, each tier's contest bond is 6.5625 times its validity bond.
function getTier(uint16 _tierId) public pure virtual returns (ITierProvider.Tier memory) {
if (_tierId == LibTiers.TIER_OPTIMISTIC) {
// cooldownWindow is 1440 minutes and provingWindow is 15 minutes
return _buildTier("", BOND_UNIT, 1440, 15);
// cooldownWindow is 24 hours and provingWindow is 15 minutes
return _buildTier("", BOND_UNIT, 24, 15);
}

// TEE Tiers
Expand All @@ -37,19 +37,20 @@ abstract contract TierProviderBase is ITierProvider {

// ZKVM+TEE Tier
if (_tierId == LibTiers.TIER_ZKVM_AND_TEE) {
return _buildTier(LibStrings.B_TIER_ZKVM_AND_TEE, BOND_UNIT * 4, 1440, 180);
// cooldownWindow is 2 hours and provingWindow is 3 hours
return _buildTier(LibStrings.B_TIER_ZKVM_AND_TEE, BOND_UNIT * 4, 2, 180);
}

// Guardian Minority Tiers
if (_tierId == LibTiers.TIER_GUARDIAN_MINORITY) {
// cooldownWindow is 240 minutes and provingWindow is 2880 minutes
return _buildTier(LibStrings.B_TIER_GUARDIAN_MINORITY, BOND_UNIT * 4, 240, 2880);
// cooldownWindow is 4 hours
return _buildTier(LibStrings.B_TIER_GUARDIAN_MINORITY, BOND_UNIT * 4, 4, 0);
}

// Guardian Major Tiers
if (_tierId == LibTiers.TIER_GUARDIAN) {
// cooldownWindow is 1440 minutes and provingWindow is 2880 minutes
return _buildTier(LibStrings.B_TIER_GUARDIAN, 0, 1440, 2880);
// cooldownWindow is 4 hours
return _buildTier(LibStrings.B_TIER_GUARDIAN, 0, 4, 0);
}

revert TIER_NOT_FOUND();
Expand All @@ -63,22 +64,22 @@ abstract contract TierProviderBase is ITierProvider {
pure
returns (ITierProvider.Tier memory)
{
// cooldownWindow is 1440 minutes and provingWindow is 60 minutes
return _buildTier(_verifierName, BOND_UNIT * 2, 1440, 60);
// cooldownWindow is 4 hours and provingWindow is 60 minutes
return _buildTier(_verifierName, BOND_UNIT * 2, 4, 60);
}

/// @dev Builds a ZK tier with a specific verifier name.
/// @param _verifierName The name of the verifier.
/// @return A Tier struct with predefined parameters for ZK.
function _buildZkTier(bytes32 _verifierName) private pure returns (ITierProvider.Tier memory) {
// cooldownWindow is 1440 minutes and provingWindow is 180 minutes
return _buildTier(_verifierName, BOND_UNIT * 3, 1440, 180);
// cooldownWindow is 4 hours and provingWindow is 3 hours
return _buildTier(_verifierName, BOND_UNIT * 3, 4, 180);
}

/// @dev Builds a generic tier with specified parameters.
/// @param _verifierName The name of the verifier.
/// @param _validityBond The validity bond amount.
/// @param _cooldownWindow The cooldown window duration in minutes.
/// @param _cooldownWindow The cooldown window duration in hours.
/// @param _provingWindow The proving window duration in minutes.
/// @return A Tier struct with the provided parameters.
function _buildTier(
Expand All @@ -95,7 +96,7 @@ abstract contract TierProviderBase is ITierProvider {
verifierName: _verifierName,
validityBond: _validityBond,
contestBond: _validityBond / 10_000 * 65_625,
cooldownWindow: _cooldownWindow,
cooldownWindow: _cooldownWindow * 60,
provingWindow: GRACE_PERIOD + _provingWindow,
maxBlocksToVerifyPerProof: 0
});
Expand Down
21 changes: 0 additions & 21 deletions packages/protocol/contracts/layer1/tiers/TierProviderV2.sol

This file was deleted.

1 change: 0 additions & 1 deletion packages/protocol/script/gen-layouts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ contracts_layer1=(
"contracts/layer1/verifiers/SgxVerifier.sol:SgxVerifier"
"contracts/layer1/automata-attestation/AutomataDcapV3Attestation.sol:AutomataDcapV3Attestation"
"contracts/layer1/based/TaikoL1.sol:TaikoL1"
"contracts/layer1/tiers/TierProviderV2.sol:TierProviderV2"
"contracts/layer1/hekla/HeklaTaikoL1.sol:HeklaTaikoL1"
"contracts/layer1/hekla/HeklaTierProvider.sol:HeklaTierProvider"
"contracts/layer1/mainnet/multirollup/MainnetBridge.sol:MainnetBridge"
Expand Down
3 changes: 2 additions & 1 deletion packages/protocol/script/layer1/DeployProtocolOnL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import "test/shared/DeployCapability.sol";
contract DeployProtocolOnL1 is DeployCapability {
uint256 public NUM_MIN_MAJORITY_GUARDIANS = vm.envUint("NUM_MIN_MAJORITY_GUARDIANS");
uint256 public NUM_MIN_MINORITY_GUARDIANS = vm.envUint("NUM_MIN_MINORITY_GUARDIANS");
address public DAO_FALLBACK_PROPOSER = 0xD3f681bD6B49887A48cC9C9953720903967E9DC0;

address public constant MAINNET_CONTRACT_OWNER = 0x9CBeE534B5D8a6280e01a14844Ee8aF350399C7F; // admin.taiko.eth

Expand Down Expand Up @@ -432,7 +433,7 @@ contract DeployProtocolOnL1 is DeployCapability {
} else if (keccak256(abi.encode(tierRouterName)) == keccak256(abi.encode("testnet"))) {
return address(new TestTierRouter());
} else if (keccak256(abi.encode(tierRouterName)) == keccak256(abi.encode("mainnet"))) {
return address(new MainnetTierRouter());
return address(new MainnetTierRouter(DAO_FALLBACK_PROPOSER));
} else {
revert("invalid tier provider");
}
Expand Down
10 changes: 0 additions & 10 deletions packages/protocol/test/layer1/based/TaikoL1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,6 @@ contract TaikoL1Tests is TaikoL1TestBase {
proposeBlock(Alice, 1024);
}

function test_getTierIds() external {
uint16[] memory tiers = tr.getTierIds();
assertEq(tiers[0], LibTiers.TIER_OPTIMISTIC);
assertEq(tiers[1], LibTiers.TIER_SGX);
assertEq(tiers[2], LibTiers.TIER_GUARDIAN);

vm.expectRevert();
tr.getTier(123);
}

function proposeButRevert(address proposer, uint24 txListSize, bytes4 revertReason) internal {
uint256 msgValue = 2 ether;
TaikoData.HookCall[] memory hookcalls = new TaikoData.HookCall[](0);
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/layer1/based/TestTierRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ contract TestTierRouter is ITierProvider, ITierRouter {
function getProvider(uint256) external view returns (address) {
return address(this);
}
/// @inheritdoc ITierProvider

/// @inheritdoc ITierProvider
function getTier(uint16 _tierId) public pure override returns (ITierProvider.Tier memory) {
if (_tierId == LibTiers.TIER_OPTIMISTIC) {
return ITierProvider.Tier({
Expand Down
Loading