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): change cooldown and proving window to minutes #16063

Merged
merged 10 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
10 changes: 5 additions & 5 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ contract TaikoL1 is EssentialContract, ITaikoL1, ITierProvider, TaikoEvents, Tai
return ITierProvider(resolve("tier_provider", false)).getTier(tierId);
}

/// @notice Retrieves the IDs of all supported tiers.
function getTierIds() public view virtual override returns (uint16[] memory ids) {
/// @inheritdoc ITierProvider
function getTierIds() public view override returns (uint16[] memory ids) {
ids = ITierProvider(resolve("tier_provider", false)).getTierIds();
if (ids.length >= type(uint8).max) revert L1_TOO_MANY_TIERS();
}

/// @notice Determines the minimal tier for a block based on a random input.
function getMinTier(uint256 rand) public view virtual override returns (uint16) {
return ITierProvider(resolve("tier_provider", false)).getMinTier(rand);
/// @inheritdoc ITierProvider
function getMinTier(uint64 blockId, uint256 rand) public view override returns (uint16) {
return ITierProvider(resolve("tier_provider", false)).getMinTier(blockId, rand);
}

/// @inheritdoc ITaikoL1
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ library LibProposing {

// Use the difficulty as a random number
meta.minTier = ITierProvider(resolver.resolve("tier_provider", false)).getMinTier(
uint256(meta.difficulty)
b.numBlocks, uint256(meta.difficulty)
);

// Create the block that will be stored onchain
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ library LibProving {
if (tier.contestBond == 0) return;

bool inProvingWindow = uint256(ts.timestamp).max(state.slotB.lastUnpausedAt)
+ tier.provingWindow >= block.timestamp;
+ tier.provingWindow * 60 >= block.timestamp;
bool isAssignedPover = msg.sender == blk.assignedProver;

// The assigned prover can only submit the very first transition.
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ library LibVerifying {
tierProvider = resolver.resolve("tier_provider", false);
}
if (
uint256(ITierProvider(tierProvider).getTier(ts.tier).cooldownWindow)
uint256(ITierProvider(tierProvider).getTier(ts.tier).cooldownWindow) * 60
+ uint256(ts.timestamp).max(state.slotB.lastUnpausedAt) > block.timestamp
) {
// If cooldownWindow is 0, the block can theoretically
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ pragma solidity 0.8.24;
import "../../common/EssentialContract.sol";
import "./ITierProvider.sol";

contract OptimisticTierProvider is EssentialContract, ITierProvider {
contract DevnetTierProvider is EssentialContract, ITierProvider {
uint256[50] private __gap;

error TIER_NOT_FOUND();

/// @notice Initializes the contract with the provided address manager.
function init() external initializer {
__Essential_init();
Expand All @@ -33,9 +31,9 @@ contract OptimisticTierProvider is EssentialContract, ITierProvider {
verifierName: "tier_optimistic",
validityBond: 250 ether, // TKO
contestBond: 500 ether, // TKO
cooldownWindow: 24 hours,
provingWindow: 2 hours,
maxBlocksToVerifyPerProof: 10
cooldownWindow: 1440, //24 hours
provingWindow: 120, // 2 hours
maxBlocksToVerifyPerProof: 16
});
}

Expand All @@ -44,9 +42,9 @@ contract OptimisticTierProvider is EssentialContract, ITierProvider {
verifierName: "tier_guardian",
validityBond: 0, // must be 0 for top tier
contestBond: 0, // must be 0 for top tier
cooldownWindow: 24 hours,
provingWindow: 8 hours,
maxBlocksToVerifyPerProof: 4
cooldownWindow: 60, //1 hours
provingWindow: 2880, // 48 hours
maxBlocksToVerifyPerProof: 16
});
}

Expand All @@ -59,7 +57,7 @@ contract OptimisticTierProvider is EssentialContract, ITierProvider {
tiers[1] = LibTiers.TIER_GUARDIAN;
}

function getMinTier(uint256 /*rand*/ ) public pure override returns (uint16) {
function getMinTier(uint64, uint256) public pure override returns (uint16) {
return LibTiers.TIER_OPTIMISTIC;
}
}
9 changes: 6 additions & 3 deletions packages/protocol/contracts/L1/tiers/ITierProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ interface ITierProvider {
bytes32 verifierName;
uint96 validityBond;
uint96 contestBond;
uint24 cooldownWindow;
uint16 provingWindow;
uint24 cooldownWindow; // in minutes
uint16 provingWindow; // in minutes
uint8 maxBlocksToVerifyPerProof;
}

error TIER_NOT_FOUND();

/// @dev Retrieves the configuration for a specified tier.
function getTier(uint16 tierId) external view returns (Tier memory);

Expand All @@ -35,12 +37,13 @@ interface ITierProvider {
function getTierIds() external view returns (uint16[] memory);

/// @dev Determines the minimal tier for a block based on a random input.
function getMinTier(uint256 rand) external view returns (uint16);
function getMinTier(uint64 blockId, uint256 rand) external view returns (uint16);
}

/// @dev Tier ID cannot be zero!
library LibTiers {
uint16 public constant TIER_OPTIMISTIC = 100;
uint16 public constant TIER_SGX = 200;
uint16 public constant TIER_SGX_ZKVM = 300;
uint16 public constant TIER_GUARDIAN = 1000;
}
85 changes: 85 additions & 0 deletions packages/protocol/contracts/L1/tiers/MainnetTierProvider.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-License-Identifier: MIT
// _____ _ _ _ _
// |_ _|_ _(_) |_____ | | __ _| |__ ___
// | |/ _` | | / / _ \ | |__/ _` | '_ (_-<
// |_|\__,_|_|_\_\___/ |____\__,_|_.__/__/
//
// Email: security@taiko.xyz
// Website: https://taiko.xyz
// GitHub: https://github.com/taikoxyz
// Discord: https://discord.gg/taikoxyz
// Twitter: https://twitter.com/taikoxyz
// Blog: https://mirror.xyz/labs.taiko.eth
// Youtube: https://www.youtube.com/@taikoxyz

pragma solidity 0.8.24;

import "../../common/EssentialContract.sol";
import "./ITierProvider.sol";

/// @title MainnetTierProvider
/// @dev Labeled in AddressResolver as "tier_provider"
/// @dev Assuming liveness bound is 250TKO.
// Taiko token's total supply is 1 billion. Assuming block time is 2 second, and
// the cool down period is 2 days. In 2 days, we can have (2*86400/2)=86400
// blocks. Assuming 10% tokens are used in bonds, then each block may use up to
// these many tokens: 1,000,000,000 * 10% / 86400=1157 TOK per block, which is
dantaik marked this conversation as resolved.
Show resolved Hide resolved
// about 722 USD.
contract MainnetTierProvider is EssentialContract, ITierProvider {
uint256[50] private __gap;

/// @notice Initializes the contract with the provided address manager.
function init() external initializer {
__Essential_init();
}

function getTier(uint16 tierId) public pure override returns (ITierProvider.Tier memory) {
if (tierId == LibTiers.TIER_SGX) {
return ITierProvider.Tier({
verifierName: "tier_sgx",
validityBond: 250 ether, // TKO
contestBond: 500 ether, // TKO
cooldownWindow: 1440, //24 hours
provingWindow: 60, // 1 hours
maxBlocksToVerifyPerProof: 8
});
}

if (tierId == LibTiers.TIER_SGX_ZKVM) {
return ITierProvider.Tier({
verifierName: "tier_sgx_zkvm",
validityBond: 500 ether, // TKO
contestBond: 1000 ether, // TKO
cooldownWindow: 1440, //24 hours
provingWindow: 240, // 4 hours
maxBlocksToVerifyPerProof: 4
});
}

if (tierId == LibTiers.TIER_GUARDIAN) {
return ITierProvider.Tier({
verifierName: "tier_guardian",
validityBond: 0, // must be 0 for top tier
contestBond: 0, // must be 0 for top tier
cooldownWindow: 60, //1 hours
provingWindow: 2880, // 48 hours
maxBlocksToVerifyPerProof: 16
});
}

revert TIER_NOT_FOUND();
}

function getTierIds() public pure override returns (uint16[] memory tiers) {
tiers = new uint16[](3);
tiers[0] = LibTiers.TIER_SGX;
tiers[1] = LibTiers.TIER_SGX_ZKVM;
tiers[2] = LibTiers.TIER_GUARDIAN;
}

function getMinTier(uint64 blockId, uint256) public pure override returns (uint16) {
// 0.1% require SGX + ZKVM; all others require SGX
if (blockId % 1000 == 0) return LibTiers.TIER_SGX_ZKVM;
else return LibTiers.TIER_SGX;
}
}
22 changes: 10 additions & 12 deletions packages/protocol/contracts/L1/tiers/TestnetTierProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import "./ITierProvider.sol";
contract TestnetTierProvider is EssentialContract, ITierProvider {
uint256[50] private __gap;

error TIER_NOT_FOUND();

/// @notice Initializes the contract with the provided address manager.
function init() external initializer {
__Essential_init();
Expand All @@ -41,9 +39,9 @@ contract TestnetTierProvider is EssentialContract, ITierProvider {
verifierName: "tier_optimistic",
validityBond: 250 ether, // TKO
contestBond: 500 ether, // TKO
cooldownWindow: 24 hours,
provingWindow: 2 hours,
maxBlocksToVerifyPerProof: 10
cooldownWindow: 1440, //24 hours
provingWindow: 30, // 0.5 hours
maxBlocksToVerifyPerProof: 12
});
}

Expand All @@ -52,8 +50,8 @@ contract TestnetTierProvider is EssentialContract, ITierProvider {
verifierName: "tier_sgx",
validityBond: 500 ether, // TKO
contestBond: 1000 ether, // TKO
cooldownWindow: 24 hours,
provingWindow: 4 hours,
cooldownWindow: 1440, //24 hours
provingWindow: 60, // 1 hours
maxBlocksToVerifyPerProof: 8
});
}
Expand All @@ -63,9 +61,9 @@ contract TestnetTierProvider is EssentialContract, ITierProvider {
verifierName: "tier_guardian",
validityBond: 0, // must be 0 for top tier
contestBond: 0, // must be 0 for top tier
cooldownWindow: 24 hours,
provingWindow: 8 hours,
maxBlocksToVerifyPerProof: 4
cooldownWindow: 60, //1 hours
provingWindow: 2880, // 48 hours
maxBlocksToVerifyPerProof: 16
});
}

Expand All @@ -79,9 +77,9 @@ contract TestnetTierProvider is EssentialContract, ITierProvider {
tiers[2] = LibTiers.TIER_GUARDIAN;
}

function getMinTier(uint256 rand) public pure override returns (uint16) {
function getMinTier(uint64 blockId, uint256) public pure override returns (uint16) {
// 10% will be selected to require SGX proofs.
if (rand % 10 == 0) return LibTiers.TIER_SGX;
if (blockId % 10 == 0) return LibTiers.TIER_SGX;
// Other blocks are optimisitc, without validity proofs.
return LibTiers.TIER_OPTIMISTIC;
}
Expand Down
24 changes: 15 additions & 9 deletions packages/protocol/script/DeployOnL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import "@openzeppelin/contracts/utils/Strings.sol";
import "../contracts/L1/TaikoToken.sol";
import "../contracts/L1/TaikoL1.sol";
import "../contracts/L1/provers/GuardianProver.sol";
import "../contracts/L1/tiers/DevnetTierProvider.sol";
import "../contracts/L1/tiers/TestnetTierProvider.sol";
import "../contracts/L1/tiers/OptimisticTierProvider.sol";
import "../contracts/L1/tiers/MainnetTierProvider.sol";
import "../contracts/L1/hooks/AssignmentHook.sol";
import "../contracts/L1/gov/TaikoTimelockController.sol";
import "../contracts/L1/gov/TaikoGovernor.sol";
Expand Down Expand Up @@ -320,16 +321,9 @@ contract DeployOnL1 is DeployCapability {
owner: timelock
});

address tierProvider;
if (vm.envBool("OPTIMISTIC_TIER_PROVIDER")) {
tierProvider = address(new OptimisticTierProvider());
} else {
tierProvider = address(new TestnetTierProvider());
}

deployProxy({
name: "tier_provider",
impl: tierProvider,
impl: deployTierProvider(vm.envString("TIER_PROVIDER")),
data: abi.encodeCall(TestnetTierProvider.init, ()),
registerTo: rollupAddressManager,
owner: timelock
Expand Down Expand Up @@ -380,6 +374,18 @@ contract DeployOnL1 is DeployCapability {
);
}

function deployTierProvider(string memory tierProviderName) private returns (address) {
if (keccak256(abi.encode(tierProviderName)) == keccak256(abi.encode("devnet"))) {
return address(new DevnetTierProvider());
} else if (keccak256(abi.encode(tierProviderName)) == keccak256(abi.encode("testnet"))) {
return address(new TestnetTierProvider());
} else if (keccak256(abi.encode(tierProviderName)) == keccak256(abi.encode("mainnet"))) {
return address(new MainnetTierProvider());
} else {
revert("invalid tier provider");
}
}

function deployAuxContracts() private {
address horseToken = address(new FreeMintERC20("Horse Token", "HORSE"));
console2.log("HorseToken", horseToken);
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/script/test_deploy_on_l1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TAIKO_TOKEN_NAME="Taiko Token Katla" \
TAIKO_TOKEN_SYMBOL=TTKOk \
SHARED_ADDRESS_MANAGER=0x0000000000000000000000000000000000000000 \
L2_GENESIS_HASH=0xee1950562d42f0da28bd4550d88886bc90894c77c9c9eaefef775d4c8223f259 \
OPTIMISTIC_TIER_PROVIDER=false \
TIER_PROVIDER="devnet" \
forge script script/DeployOnL1.s.sol:DeployOnL1 \
--fork-url http://localhost:8545 \
--broadcast \
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/test/L1/TaikoL1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract TaikoL1Test is TaikoL1TestBase {
vm.roll(block.number + 15 * 12);

uint16 minTier = meta.minTier;
vm.warp(block.timestamp + L1.getTier(minTier).cooldownWindow + 1);
vm.warp(block.timestamp + L1.getTier(minTier).cooldownWindow * 60 + 1);

verifyBlock(Carol, 1);
parentHash = blockHash;
Expand Down Expand Up @@ -89,7 +89,7 @@ contract TaikoL1Test is TaikoL1TestBase {
proveBlock(Bob, Bob, meta, parentHash, blockHash, stateRoot, meta.minTier, "");
vm.roll(block.number + 15 * 12);
uint16 minTier = meta.minTier;
vm.warp(block.timestamp + L1.getTier(minTier).cooldownWindow + 1);
vm.warp(block.timestamp + L1.getTier(minTier).cooldownWindow * 60 + 1);

verifyBlock(Alice, 2);
parentHash = blockHash;
Expand Down
Loading
Loading