-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protocol): implement & simulate tokenomics (#376)
- Implement tokenomics outlined in our whitepaper - Simulate tokenomics using python - Replaced LibConstants using a Config Object - Various renames for better readability
- Loading branch information
Showing
54 changed files
with
2,067 additions
and
884 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// ╭━━━━╮╱╱╭╮╱╱╱╱╱╭╮╱╱╱╱╱╭╮ | ||
// ┃╭╮╭╮┃╱╱┃┃╱╱╱╱╱┃┃╱╱╱╱╱┃┃ | ||
// ╰╯┃┃┣┻━┳┫┃╭┳━━╮┃┃╱╱╭━━┫╰━┳━━╮ | ||
// ╱╱┃┃┃╭╮┣┫╰╯┫╭╮┃┃┃╱╭┫╭╮┃╭╮┃━━┫ | ||
// ╱╱┃┃┃╭╮┃┃╭╮┫╰╯┃┃╰━╯┃╭╮┃╰╯┣━━┃ | ||
// ╱╱╰╯╰╯╰┻┻╯╰┻━━╯╰━━━┻╯╰┻━━┻━━╯ | ||
pragma solidity ^0.8.9; | ||
|
||
import "../thirdparty/LibMerkleTrie.sol"; | ||
import "../libs/LibZKP.sol"; | ||
|
||
/// @author dantaik <[email protected]> | ||
interface IProofVerifier { | ||
function verifyZKP( | ||
bytes memory verificationKey, | ||
bytes calldata zkproof, | ||
bytes32 blockHash, | ||
address prover, | ||
bytes32 txListHash | ||
) external pure returns (bool verified); | ||
|
||
function verifyMKP( | ||
bytes memory key, | ||
bytes memory value, | ||
bytes memory proof, | ||
bytes32 root | ||
) external pure returns (bool verified); | ||
} | ||
|
||
contract ProofVerifier is IProofVerifier { | ||
function verifyZKP( | ||
bytes memory verificationKey, | ||
bytes calldata zkproof, | ||
bytes32 blockHash, | ||
address prover, | ||
bytes32 txListHash | ||
) external pure returns (bool) { | ||
return | ||
LibZKP.verify({ | ||
verificationKey: verificationKey, | ||
zkproof: zkproof, | ||
blockHash: blockHash, | ||
prover: prover, | ||
txListHash: txListHash | ||
}); | ||
} | ||
|
||
function verifyMKP( | ||
bytes memory key, | ||
bytes memory value, | ||
bytes memory proof, | ||
bytes32 root | ||
) external pure returns (bool) { | ||
return | ||
LibMerkleTrie.verifyInclusionProof({ | ||
_key: key, | ||
_value: value, | ||
_proof: proof, | ||
_root: root | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,41 @@ | |
// ╱╱╰╯╰╯╰┻┻╯╰┻━━╯╰━━━┻╯╰┻━━┻━━╯ | ||
pragma solidity ^0.8.9; | ||
|
||
import "../libs/LibConstants.sol"; | ||
|
||
/// @author dantaik <[email protected]> | ||
library LibData { | ||
library TaikoData { | ||
struct Config { | ||
uint256 chainId; | ||
// up to 2048 pending blocks | ||
uint256 maxNumBlocks; | ||
uint256 blockHashHistory; | ||
// This number is calculated from maxNumBlocks to make | ||
// the 'the maximum value of the multiplier' close to 20.0 | ||
uint256 zkProofsPerBlock; | ||
uint256 maxVerificationsPerTx; | ||
uint256 commitConfirmations; | ||
uint256 maxProofsPerForkChoice; | ||
uint256 blockMaxGasLimit; | ||
uint256 maxTransactionsPerBlock; | ||
uint256 maxBytesPerTxList; | ||
uint256 minTxGasLimit; | ||
uint256 anchorTxGasLimit; | ||
uint256 feePremiumLamda; | ||
uint256 rewardBurnBips; | ||
uint256 proposerDepositPctg; | ||
// Moving average factors | ||
uint256 feeBaseMAF; | ||
uint256 blockTimeMAF; | ||
uint256 proofTimeMAF; | ||
uint64 rewardMultiplierPctg; | ||
uint64 feeGracePeriodPctg; | ||
uint64 feeMaxPeriodPctg; | ||
uint64 blockTimeCap; | ||
uint64 proofTimeCap; | ||
uint64 boostrapDiscountHalvingPeriod; | ||
uint64 initialUncleDelay; | ||
bool enableTokenomics; | ||
} | ||
|
||
struct BlockMetadata { | ||
uint256 id; | ||
uint256 l1Height; | ||
|
@@ -29,6 +60,7 @@ library LibData { | |
// 3 slots | ||
struct ProposedBlock { | ||
bytes32 metaHash; | ||
uint256 deposit; | ||
address proposer; | ||
uint64 proposedAt; | ||
} | ||
|
@@ -42,7 +74,7 @@ library LibData { | |
|
||
// This struct takes 9 slots. | ||
struct State { | ||
// block id => block hash | ||
// block id => block hash (some blocks' hashes won't be persisted) | ||
mapping(uint256 => bytes32) l2Hashes; | ||
// block id => ProposedBlock | ||
mapping(uint256 => ProposedBlock) proposedBlocks; | ||
|
@@ -55,6 +87,8 @@ library LibData { | |
uint64 genesisTimestamp; | ||
uint64 __reservedA1; | ||
uint64 statusBits; // rarely change | ||
// Changed when a block is proposed or proven/finalized | ||
uint256 feeBase; | ||
// Changed when a block is proposed | ||
uint64 nextBlockId; | ||
uint64 lastProposedAt; // Timestamp when the last block is proposed. | ||
|
@@ -70,60 +104,4 @@ library LibData { | |
// Reserved | ||
uint256[42] __gap; | ||
} | ||
|
||
struct TentativeState { | ||
mapping(address => bool) proposers; // Whitelisted proposers | ||
mapping(address => bool) provers; // Whitelisted provers | ||
bool whitelistProposers; | ||
bool whitelistProvers; | ||
// // Reserved | ||
uint256[46] __gap; | ||
} | ||
|
||
function saveProposedBlock( | ||
LibData.State storage state, | ||
uint256 id, | ||
ProposedBlock memory blk | ||
) internal { | ||
state.proposedBlocks[id % LibConstants.K_MAX_NUM_BLOCKS] = blk; | ||
} | ||
|
||
function getProposedBlock( | ||
State storage state, | ||
uint256 id | ||
) internal view returns (ProposedBlock storage) { | ||
return state.proposedBlocks[id % LibConstants.K_MAX_NUM_BLOCKS]; | ||
} | ||
|
||
function getL2BlockHash( | ||
State storage state, | ||
uint256 number | ||
) internal view returns (bytes32) { | ||
require(number <= state.latestVerifiedHeight, "L1:id"); | ||
return state.l2Hashes[number]; | ||
} | ||
|
||
function getStateVariables( | ||
State storage state | ||
) | ||
internal | ||
view | ||
returns ( | ||
uint64 genesisHeight, | ||
uint64 latestVerifiedHeight, | ||
uint64 latestVerifiedId, | ||
uint64 nextBlockId | ||
) | ||
{ | ||
genesisHeight = state.genesisHeight; | ||
latestVerifiedHeight = state.latestVerifiedHeight; | ||
latestVerifiedId = state.latestVerifiedId; | ||
nextBlockId = state.nextBlockId; | ||
} | ||
|
||
function hashMetadata( | ||
BlockMetadata memory meta | ||
) internal pure returns (bytes32) { | ||
return keccak256(abi.encode(meta)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,10 @@ | |
// ╱╱╰╯╰╯╰┻┻╯╰┻━━╯╰━━━┻╯╰┻━━┻━━╯ | ||
pragma solidity ^0.8.9; | ||
|
||
import "../LibData.sol"; | ||
import "./TaikoData.sol"; | ||
|
||
/// @author david <[email protected]> | ||
abstract contract V1Events { | ||
abstract contract TaikoEvents { | ||
// The following events must match the definitions in other V1 libraries. | ||
event BlockVerified(uint256 indexed id, bytes32 blockHash); | ||
|
||
|
@@ -21,7 +21,7 @@ abstract contract V1Events { | |
bytes32 commitHash | ||
); | ||
|
||
event BlockProposed(uint256 indexed id, LibData.BlockMetadata meta); | ||
event BlockProposed(uint256 indexed id, TaikoData.BlockMetadata meta); | ||
|
||
event BlockProven( | ||
uint256 indexed id, | ||
|
@@ -32,11 +32,5 @@ abstract contract V1Events { | |
address prover | ||
); | ||
|
||
event WhitelistingEnabled(bool whitelistProposers, bool whitelistProvers); | ||
|
||
event ProposerWhitelisted(address indexed prover, bool whitelisted); | ||
|
||
event ProverWhitelisted(address indexed prover, bool whitelisted); | ||
|
||
event Halted(bool halted); | ||
} |
Oops, something went wrong.