-
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.
Revert "feat(protocol): implement tokenomics v1 (#243)"
This reverts commit 2570c99.
- Loading branch information
Showing
39 changed files
with
291 additions
and
613 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,8 +109,4 @@ dist | |
# vscode | ||
.vscode/ | ||
|
||
# python | ||
__pycache__/ | ||
|
||
# whitepaper | ||
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 |
---|---|---|
|
@@ -16,10 +16,10 @@ import "../common/IHeaderSync.sol"; | |
import "../libs/LibAnchorSignature.sol"; | ||
import "./LibData.sol"; | ||
import "./v1/V1Events.sol"; | ||
import "./v1/V1Finalizing.sol"; | ||
import "./v1/V1Proposing.sol"; | ||
import "./v1/V1Proving.sol"; | ||
import "./v1/V1Utils.sol"; | ||
import "./v1/V1Verifying.sol"; | ||
|
||
/** | ||
* @author dantaik <[email protected]> | ||
|
@@ -30,15 +30,14 @@ contract TaikoL1 is EssentialContract, IHeaderSync, V1Events { | |
using SafeCastUpgradeable for uint256; | ||
|
||
LibData.State public state; | ||
uint256[50] private __gap; | ||
uint256[43] private __gap; | ||
|
||
function init( | ||
address _addressManager, | ||
bytes32 _genesisBlockHash, | ||
uint256 _feeBase | ||
bytes32 _genesisBlockHash | ||
) external initializer { | ||
EssentialContract._init(_addressManager); | ||
V1Verifying.init(state, _genesisBlockHash, _feeBase); | ||
V1Finalizing.init(state, _genesisBlockHash); | ||
} | ||
|
||
/** | ||
|
@@ -75,11 +74,10 @@ contract TaikoL1 is EssentialContract, IHeaderSync, V1Events { | |
* transactions in the L2 block. | ||
*/ | ||
function proposeBlock(bytes[] calldata inputs) external nonReentrant { | ||
V1Proposing.proposeBlock(state, AddressResolver(this), inputs); | ||
V1Verifying.verifyBlocks( | ||
V1Proposing.proposeBlock(state, inputs); | ||
V1Finalizing.verifyBlocks( | ||
state, | ||
AddressResolver(this), | ||
LibConstants.K_MAX_VERIFICATIONS_PER_TX, | ||
LibConstants.TAIKO_MAX_VERIFICATIONS_PER_TX, | ||
false | ||
); | ||
} | ||
|
@@ -104,10 +102,9 @@ contract TaikoL1 is EssentialContract, IHeaderSync, V1Events { | |
bytes[] calldata inputs | ||
) external nonReentrant { | ||
V1Proving.proveBlock(state, AddressResolver(this), blockIndex, inputs); | ||
V1Verifying.verifyBlocks( | ||
V1Finalizing.verifyBlocks( | ||
state, | ||
AddressResolver(this), | ||
LibConstants.K_MAX_VERIFICATIONS_PER_TX, | ||
LibConstants.TAIKO_MAX_VERIFICATIONS_PER_TX, | ||
false | ||
); | ||
} | ||
|
@@ -136,10 +133,9 @@ contract TaikoL1 is EssentialContract, IHeaderSync, V1Events { | |
blockIndex, | ||
inputs | ||
); | ||
V1Verifying.verifyBlocks( | ||
V1Finalizing.verifyBlocks( | ||
state, | ||
AddressResolver(this), | ||
LibConstants.K_MAX_VERIFICATIONS_PER_TX, | ||
LibConstants.TAIKO_MAX_VERIFICATIONS_PER_TX, | ||
false | ||
); | ||
} | ||
|
@@ -150,7 +146,7 @@ contract TaikoL1 is EssentialContract, IHeaderSync, V1Events { | |
*/ | ||
function verifyBlocks(uint256 maxBlocks) external nonReentrant { | ||
require(maxBlocks > 0, "L1:maxBlocks"); | ||
V1Verifying.verifyBlocks(state, AddressResolver(this), maxBlocks, true); | ||
V1Finalizing.verifyBlocks(state, maxBlocks, true); | ||
} | ||
|
||
/* Add or remove a prover from the whitelist. | ||
|
@@ -183,21 +179,6 @@ contract TaikoL1 is EssentialContract, IHeaderSync, V1Events { | |
return V1Proving.isProverWhitelisted(state, prover); | ||
} | ||
|
||
function getBlockFee() public view returns (uint256 premiumFee) { | ||
(, premiumFee) = V1Proposing.getBlockFee(state); | ||
} | ||
|
||
function getProofReward( | ||
uint64 provenAt, | ||
uint64 proposedAt | ||
) public view returns (uint256 premiumReward) { | ||
(, premiumReward) = V1Verifying.getProofReward( | ||
state, | ||
provenAt, | ||
proposedAt | ||
); | ||
} | ||
|
||
/** | ||
* Check if the L1 is halted. | ||
* @return True if halted, false otherwise. | ||
|
@@ -246,35 +227,35 @@ contract TaikoL1 is EssentialContract, IHeaderSync, V1Events { | |
public | ||
pure | ||
returns ( | ||
uint256, // K_CHAIN_ID | ||
uint256, // K_MAX_NUM_BLOCKS | ||
uint256, // K_MAX_VERIFICATIONS_PER_TX | ||
uint256, // K_COMMIT_DELAY_CONFIRMS | ||
uint256, // K_MAX_PROOFS_PER_FORK_CHOICE | ||
uint256, // K_BLOCK_MAX_GAS_LIMIT | ||
uint256, // K_BLOCK_MAX_TXS | ||
bytes32, // K_BLOCK_DEADEND_HASH | ||
uint256, // K_TXLIST_MAX_BYTES | ||
uint256, // K_TX_MIN_GAS_LIMIT | ||
uint256, // K_ANCHOR_TX_GAS_LIMIT | ||
bytes4, // K_ANCHOR_TX_SELECTOR | ||
bytes32 // K_INVALIDATE_BLOCK_LOG_TOPIC | ||
uint256, // TAIKO_CHAIN_ID | ||
uint256, // TAIKO_MAX_PROPOSED_BLOCKS | ||
uint256, // TAIKO_MAX_VERIFICATIONS_PER_TX | ||
uint256, // TAIKO_COMMIT_DELAY_CONFIRMATIONS | ||
uint256, // TAIKO_MAX_PROOFS_PER_FORK_CHOICE | ||
uint256, // TAIKO_BLOCK_MAX_GAS_LIMIT | ||
uint256, // TAIKO_BLOCK_MAX_TXS | ||
bytes32, // TAIKO_BLOCK_DEADEND_HASH | ||
uint256, // TAIKO_TXLIST_MAX_BYTES | ||
uint256, // TAIKO_TX_MIN_GAS_LIMIT | ||
uint256, // V1_ANCHOR_TX_GAS_LIMIT | ||
bytes4, // V1_ANCHOR_TX_SELECTOR | ||
bytes32 // V1_INVALIDATE_BLOCK_LOG_TOPIC | ||
) | ||
{ | ||
return ( | ||
LibConstants.K_CHAIN_ID, | ||
LibConstants.K_MAX_NUM_BLOCKS, | ||
LibConstants.K_MAX_VERIFICATIONS_PER_TX, | ||
LibConstants.K_COMMIT_DELAY_CONFIRMS, | ||
LibConstants.K_MAX_PROOFS_PER_FORK_CHOICE, | ||
LibConstants.K_BLOCK_MAX_GAS_LIMIT, | ||
LibConstants.K_BLOCK_MAX_TXS, | ||
LibConstants.K_BLOCK_DEADEND_HASH, | ||
LibConstants.K_TXLIST_MAX_BYTES, | ||
LibConstants.K_TX_MIN_GAS_LIMIT, | ||
LibConstants.K_ANCHOR_TX_GAS_LIMIT, | ||
LibConstants.K_ANCHOR_TX_SELECTOR, | ||
LibConstants.K_INVALIDATE_BLOCK_LOG_TOPIC | ||
LibConstants.TAIKO_CHAIN_ID, | ||
LibConstants.TAIKO_MAX_PROPOSED_BLOCKS, | ||
LibConstants.TAIKO_MAX_VERIFICATIONS_PER_TX, | ||
LibConstants.TAIKO_COMMIT_DELAY_CONFIRMATIONS, | ||
LibConstants.TAIKO_MAX_PROOFS_PER_FORK_CHOICE, | ||
LibConstants.TAIKO_BLOCK_MAX_GAS_LIMIT, | ||
LibConstants.TAIKO_BLOCK_MAX_TXS, | ||
LibConstants.TAIKO_BLOCK_DEADEND_HASH, | ||
LibConstants.TAIKO_TXLIST_MAX_BYTES, | ||
LibConstants.TAIKO_TX_MIN_GAS_LIMIT, | ||
LibConstants.V1_ANCHOR_TX_GAS_LIMIT, | ||
LibConstants.V1_ANCHOR_TX_SELECTOR, | ||
LibConstants.V1_INVALIDATE_BLOCK_LOG_TOPIC | ||
); | ||
} | ||
} |
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,87 @@ | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// ╭━━━━╮╱╱╭╮╱╱╱╱╱╭╮╱╱╱╱╱╭╮ | ||
// ┃╭╮╭╮┃╱╱┃┃╱╱╱╱╱┃┃╱╱╱╱╱┃┃ | ||
// ╰╯┃┃┣┻━┳┫┃╭┳━━╮┃┃╱╱╭━━┫╰━┳━━╮ | ||
// ╱╱┃┃┃╭╮┣┫╰╯┫╭╮┃┃┃╱╭┫╭╮┃╭╮┃━━┫ | ||
// ╱╱┃┃┃╭╮┃┃╭╮┫╰╯┃┃╰━╯┃╭╮┃╰╯┣━━┃ | ||
// ╱╱╰╯╰╯╰┻┻╯╰┻━━╯╰━━━┻╯╰┻━━┻━━╯ | ||
pragma solidity ^0.8.9; | ||
|
||
import "./V1Utils.sol"; | ||
|
||
/// @author dantaik <[email protected]> | ||
library V1Finalizing { | ||
event BlockVerified(uint256 indexed id, bytes32 blockHash); | ||
|
||
event HeaderSynced( | ||
uint256 indexed height, | ||
uint256 indexed srcHeight, | ||
bytes32 srcHash | ||
); | ||
|
||
function init(LibData.State storage s, bytes32 _genesisBlockHash) public { | ||
s.l2Hashes[0] = _genesisBlockHash; | ||
s.nextBlockId = 1; | ||
s.genesisHeight = uint64(block.number); | ||
|
||
emit BlockVerified(0, _genesisBlockHash); | ||
emit HeaderSynced(block.number, 0, _genesisBlockHash); | ||
} | ||
|
||
function verifyBlocks( | ||
LibData.State storage s, | ||
uint256 maxBlocks, | ||
bool checkHalt | ||
) public { | ||
bool halted = V1Utils.isHalted(s); | ||
if (checkHalt) { | ||
require(!halted, "L1:halted"); | ||
} else if (halted) { | ||
// skip finalizing blocks | ||
return; | ||
} | ||
|
||
uint64 latestL2Height = s.latestVerifiedHeight; | ||
bytes32 latestL2Hash = s.l2Hashes[latestL2Height]; | ||
uint64 processed = 0; | ||
|
||
for ( | ||
uint256 i = s.latestVerifiedId + 1; | ||
i < s.nextBlockId && processed <= maxBlocks; | ||
i++ | ||
) { | ||
LibData.ForkChoice storage fc = s.forkChoices[i][latestL2Hash]; | ||
|
||
// TODO(daniel): use the average proof-time. | ||
if ( | ||
block.timestamp <= | ||
fc.provenAt + LibConstants.K_VERIFICATION_DELAY | ||
) { | ||
// This block is proven but still needs to wait for verificaiton. | ||
break; | ||
} | ||
|
||
if (fc.blockHash == LibConstants.TAIKO_BLOCK_DEADEND_HASH) { | ||
emit BlockVerified(i, 0); | ||
} else if (fc.blockHash != 0) { | ||
latestL2Height += 1; | ||
latestL2Hash = fc.blockHash; | ||
emit BlockVerified(i, latestL2Hash); | ||
} else { | ||
break; | ||
} | ||
processed += 1; | ||
} | ||
|
||
if (processed > 0) { | ||
s.latestVerifiedId += processed; | ||
|
||
if (latestL2Height > s.latestVerifiedHeight) { | ||
s.latestVerifiedHeight = latestL2Height; | ||
s.l2Hashes[latestL2Height] = latestL2Hash; | ||
emit HeaderSynced(block.number, latestL2Height, latestL2Hash); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.