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): alpha-4 with staking-based tokenomics #14006

Merged
merged 23 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8cc5ef2
Initial interface and example implementation
adaki2004 Jun 16, 2023
4b0c4a8
Add all functions to interface
adaki2004 Jun 16, 2023
446d6d2
Add auto-generated contract documentation
adaki2004 Jun 16, 2023
3f7478c
add proxy + deploy script
cyberhorsey Jun 16, 2023
b3e93ae
Add auto-generated contract documentation
cyberhorsey Jun 16, 2023
7b18a67
add event when staking tokens so eventindexer could pick it up
cyberhorsey Jun 16, 2023
39f7c26
Merge branch 'PoS_initial_impl' of github.com:taikoxyz/taiko-mono int…
cyberhorsey Jun 16, 2023
45cd819
add more events to index
cyberhorsey Jun 16, 2023
b790fd5
Add auto-generated contract documentation
cyberhorsey Jun 16, 2023
7fd4fe4
Merge branch 'alpha-4-base' into PoS_initial_impl
dantaik Jun 17, 2023
b5ebbbc
Add auto-generated contract documentation
dantaik Jun 17, 2023
64984b7
Staking improvement 1 (#14010)
dantaik Jun 22, 2023
fbec76c
Staking tokenomicis 1 (#14035)
adaki2004 Jun 22, 2023
bd0274f
Fix test issues 1
adaki2004 Jun 23, 2023
5410ce0
linting
adaki2004 Jun 23, 2023
e7ba8ab
Fixing test issues and findings (#14042)
adaki2004 Jun 23, 2023
0be4c75
Following changes:
adaki2004 Jun 25, 2023
c3a7b42
Add auto-generated contract documentation
adaki2004 Jun 25, 2023
6a649a1
feat(protocol): provided an alternative staking implementation (#14049)
dantaik Jun 26, 2023
9a55d68
Rename Brecht proposal to PP2
adaki2004 Jun 26, 2023
f3d56c7
Fix typo
adaki2004 Jun 26, 2023
6abf623
Add more unit tests
adaki2004 Jun 26, 2023
ae28298
Add auto-generated contract documentation
adaki2004 Jun 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
528 changes: 528 additions & 0 deletions packages/protocol/contracts/L1/ProverPool.sol

Large diffs are not rendered by default.

40 changes: 19 additions & 21 deletions packages/protocol/contracts/L1/TaikoConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,45 @@ import { TaikoData } from "../L1/TaikoData.sol";
library TaikoConfig {
function getConfig() internal pure returns (TaikoData.Config memory) {
return TaikoData.Config({
// Group 1: general configs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please run pnpm fmt:sol

chainId: 167,
relaySignalRoot: false,
// Group 2: block level configs
// Two weeks if avg block time is 10 seconds
maxNumProposedBlocks: 120_960,
blockMaxProposals: 120_960,
blockRingBufferSize: 120_960 + 10,
// 1 block batch consist of 100 blocks, so divided block ring buffer
// by 100
// to be kind of in-sync, but it does not have to be fully in sync,
// they are decoupled
auctionRingBufferSize: 1221,
// Each time one more block is verified, there will be ~20k
// more gas cost.
maxVerificationsPerTx: 10,
blockMaxVerificationsPerTx: 10,
// Set it to 6M, since its the upper limit of the Alpha-2
// testnet's circuits.
blockMaxGasLimit: 6_000_000,
blockFeeBaseGas: 20_000,
// Set it to 79 (+1 TaikoL2.anchor transaction = 80),
// and 80 is the upper limit of the Alpha-2 testnet's circuits.
maxTransactionsPerBlock: 79,
blockMaxTransactions: 79,
// Set it to 120KB, since 128KB is the upper size limit
// of a geth transaction, so using 120KB for the proposed
// transactions list calldata, 8K for the remaining tx fields.
maxBytesPerTxList: 120_000,
txListCacheExpiry: 0,
proofCooldownPeriod: 30 minutes,
systemProofCooldownPeriod: 15 minutes,
auctionWindow: 120,
auctionProofWindowMultiplier: 2,
auctionDepositMultipler: 10,
auctionMaxFeePerGasMultipler: 5,
auctionBatchSize: 100,
auctionMaxAheadOfProposals: 10,
auctionMaxProofWindow: 7200,
blockMaxTxListBytes: 120_000,
blockTxListExpiry: 0,
// Group 3: proof related configs
proofRegularCooldown: 30 minutes,
proofOracleCooldown: 15 minutes,
proofMinWindow: 10 minutes,
proofMaxWindow: 90 minutes,
// Group 4: eth deposit related configs
ethDepositRingBufferSize: 1024,
ethDepositMinCountPerBlock: 8,
ethDepositMaxCountPerBlock: 32,
ethDepositMaxAmount: 10_000 ether,
ethDepositMinAmount: 1 ether,
ethDepositMaxAmount: 10_000 ether,
ethDepositGas: 21_000,
ethDepositMaxFee: 1 ether / 10,
relaySignalRoot: false
// Group 5: tokenomics
rewardPerGasRange: 1000, // 10%
rewardOpenMultipler: 200, // percentage
rewardOpenMaxCount: 2000
});
}
}
104 changes: 44 additions & 60 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,45 @@ pragma solidity ^0.8.20;

library TaikoData {
struct Config {
// Group 1: general configs
uint256 chainId;
uint256 maxNumProposedBlocks;
bool relaySignalRoot;
// Group 2: block level configs
uint256 blockMaxProposals;
uint256 blockRingBufferSize;
uint256 auctionRingBufferSize;
// This number is calculated from maxNumProposedBlocks to make
// This number is calculated from blockMaxProposals to make
// the 'the maximum value of the multiplier' close to 20.0
uint256 maxVerificationsPerTx;
uint64 blockMaxGasLimit;
uint64 blockFeeBaseGas;
uint64 maxTransactionsPerBlock;
uint64 maxBytesPerTxList;
uint256 txListCacheExpiry;
uint256 proofCooldownPeriod;
uint256 systemProofCooldownPeriod;
//How long auction window will be open after the first bid
uint16 auctionWindow;
//How long proof window will be granted to winning bidder
uint64 auctionProofWindowMultiplier;
uint64 auctionDepositMultipler;
uint64 auctionMaxFeePerGasMultipler;
uint16 auctionBatchSize;
uint16 auctionMaxAheadOfProposals;
uint16 auctionMaxProofWindow;
uint256 blockMaxVerificationsPerTx;
uint32 blockMaxGasLimit;
uint32 blockFeeBaseGas;
uint64 blockMaxTransactions;
uint64 blockMaxTxListBytes;
uint256 blockTxListExpiry;
// Group 3: proof related configs
uint256 proofRegularCooldown;
uint256 proofOracleCooldown;
uint16 proofMinWindow;
uint16 proofMaxWindow;
// Group 4: eth deposit related configs
uint256 ethDepositRingBufferSize;
uint64 ethDepositMinCountPerBlock;
uint64 ethDepositMaxCountPerBlock;
uint96 ethDepositMaxAmount;
uint96 ethDepositMinAmount;
uint96 ethDepositMaxAmount;
uint256 ethDepositGas;
uint256 ethDepositMaxFee;
bool relaySignalRoot;
// Group 5: tokenomics
uint32 rewardPerGasRange;
uint8 rewardOpenMultipler;
uint256 rewardOpenMaxCount;
}

struct StateVariables {
uint48 feePerGas;
uint32 feePerGas;
uint64 genesisHeight;
uint64 genesisTimestamp;
uint64 numBlocks;
uint64 lastVerifiedBlockId;
uint64 numAuctions;
uint64 nextEthDepositToProcess;
uint64 numEthDeposits;
}
Expand All @@ -59,7 +58,7 @@ library TaikoData {
uint32 gasLimit;
uint24 txListByteStart; // byte-wise start index (inclusive)
uint24 txListByteEnd; // byte-wise end index (exclusive)
uint8 cacheTxListInfo; // non-zero = True
bool cacheTxListInfo;
}

// Changing this struct requires changing LibUtils.hashMetadata accordingly.
Expand Down Expand Up @@ -89,7 +88,6 @@ library TaikoData {
uint32 gasUsed;
uint16 verifierId;
bytes proof;
bytes sig;
}

// 4 slots
Expand All @@ -98,26 +96,33 @@ library TaikoData {
bytes32 key;
bytes32 blockHash;
bytes32 signalRoot;
uint64 provenAt;
address prover;
uint64 provenAt;
uint32 gasUsed;
}

// 4 slots
// 5 slots
struct Block {
// ForkChoice storage are reusable
// slot 1: ForkChoice storage are reusable
mapping(uint256 forkChoiceId => ForkChoice) forkChoices;
// slot 2
bytes32 metaHash;
// slot 3: (13 bytes available)
uint64 blockId;
uint64 proposedAt;
uint48 feePerGas;
uint32 gasLimit;
address proposer;
uint24 nextForkChoiceId;
uint24 verifiedForkChoiceId;
bool proverReleased;
// slot 4
address proposer;
uint32 feePerGas;
uint64 proposedAt;
// slot 5
address prover;
uint32 rewardPerGas;
uint64 proofWindow;
}

// This struct takes 9 slots.
struct TxListInfo {
uint64 validSince;
uint24 size;
Expand All @@ -129,39 +134,18 @@ library TaikoData {
uint64 id;
}

// 1 slot
struct Bid {
address prover;
uint64 deposit;
uint48 feePerGas;
// In order to refund the diff betwen gasUsed vs. blockMaxGasLimit
// It is also part of the bidding - how fast some can submit proofs
// according to his/her own commitment.
// Can be zero and it will just signal that the proofs are coming
// somewhere within config.auctionWindow
uint16 proofWindow;
}

struct Auction {
Bid bid;
uint64 batchId;
uint64 startedAt;
}

struct State {
// Ring buffer for proposed blocks and a some recent verified blocks.
mapping(uint256 blockId_mode_blockRingBufferSize => Block) blocks;
mapping(
uint256 blockId
=> mapping(
bytes32 parentHash
=> mapping(uint32 parentGasUsed => uint256 forkChoiceId)
=> mapping(uint32 parentGasUsed => uint24 forkChoiceId)
)
) forkChoiceIds;
mapping(address account => uint256 balance) taikoTokenBalances;
mapping(bytes32 txListHash => TxListInfo) txListInfo;
mapping(uint256 batchId => Auction auction) auctions;
mapping(uint256 depositId_mod_ethDepositRingBufferSize => uint256)
mapping(uint256 depositId_mode_ethDepositRingBufferSize => uint256)
ethDeposits;
// Never or rarely changed
// Slot 7: never or rarely changed
Expand All @@ -170,17 +154,17 @@ library TaikoData {
uint64 __reserved70;
uint64 __reserved71;
// Slot 8
uint64 numAuctions;
uint64 numOpenBlocks;
uint64 numEthDeposits;
uint64 numBlocks;
uint64 nextEthDepositToProcess;
// Slot 9
uint64 lastVerifiedAt;
uint64 lastVerifiedBlockId;
uint48 feePerGas;
uint16 avgProofWindow;
uint64 __reserved90;
uint32 feePerGas;
uint16 avgProofDelay;
// Reserved
uint256[42] __gap;
uint256[43] __gap; // TODO: update this
}
}
9 changes: 9 additions & 0 deletions packages/protocol/contracts/L1/TaikoErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@ abstract contract TaikoErrors {
error L1_NOT_SPECIAL_PROVER();
error L1_SAME_PROOF();
error L1_TOO_MANY_BLOCKS();
error L1_TOO_MANY_OPEN_BLOCKS();
error L1_TX_LIST_NOT_EXIST();
error L1_TX_LIST_HASH();
error L1_TX_LIST_RANGE();
error L1_TX_LIST();
error L1_UNAUTHORIZED();

// Prover pool related error
error POOL_CALLER_NOT_AUTHORIZED();
error POOL_CANNOT_YET_EXIT();
error POOL_NOT_ENOUGH_RESOURCES();
error POOL_PROVER_NOT_FOUND();
error POOL_REWARD_CANNOT_BE_NULL();
error POOL_NOT_MEETING_MIN_REQUIREMENTS();
}
13 changes: 1 addition & 12 deletions packages/protocol/contracts/L1/TaikoEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import { TaikoData } from "./TaikoData.sol";
abstract contract TaikoEvents {
// The following events must match the definitions in corresponding L1
// libraries.
event BatchBid(uint64 indexed batchId, uint64 startedAt, TaikoData.Bid bid);

event BlockProposed(
uint256 indexed id, TaikoData.BlockMetadata meta, uint64 blockFee
);
event BlockProposed(uint256 indexed id, TaikoData.BlockMetadata meta);

event BlockProven(
uint256 indexed id,
Expand All @@ -29,11 +25,4 @@ abstract contract TaikoEvents {
event BlockVerified(uint256 indexed id, bytes32 blockHash, uint64 reward);

event EthDeposited(TaikoData.EthDeposit deposit);

event ProofParamsChanged(
uint64 proofTimeTarget,
uint64 proofTimeIssued,
uint64 blockFee,
uint16 adjustmentQuotient
);
}