Skip to content

Commit

Permalink
Revert "feat(protocol): implement tokenomics v1 (#243)"
Browse files Browse the repository at this point in the history
This reverts commit 2570c99.
  • Loading branch information
dantaik committed Nov 23, 2022
1 parent 2570c99 commit 5c83410
Show file tree
Hide file tree
Showing 39 changed files with 291 additions and 613 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,4 @@ dist
# vscode
.vscode/

# python
__pycache__/

# whitepaper
.pdf
.pdf
25 changes: 4 additions & 21 deletions packages/protocol/contracts/L1/LibData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ library LibData {

struct ProposedBlock {
bytes32 metaHash;
address proposer;
uint64 gasLimit;
}

struct ForkChoice {
Expand All @@ -39,7 +37,6 @@ library LibData {
address[] provers;
}

// This struct takes 9 slots.
struct State {
// block id => block hash
mapping(uint256 => bytes32) l2Hashes;
Expand All @@ -50,40 +47,26 @@ library LibData {
// proposer => commitSlot => hash(commitHash, commitHeight)
mapping(address => mapping(uint256 => bytes32)) commits;
mapping(address => bool) provers; // Whitelisted provers
// Never or rarely changed
uint64 statusBits;
uint64 genesisHeight;
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.
uint64 avgBlockTime; // The block time moving average
uint64 __avgGasLimit; // the block gas-limit moving average, not updated.
// Changed when a block is proven/finalized
uint64 latestVerifiedHeight;
uint64 latestVerifiedId;
uint64 avgProofTime; // the proof time moving average
uint64 __reservedC1;
// Reserved
uint256[41] __gap;
uint64 nextBlockId;
}

function saveProposedBlock(
LibData.State storage s,
uint256 id,
ProposedBlock memory blk
) internal {
s.proposedBlocks[id % LibConstants.K_MAX_NUM_BLOCKS] = blk;
s.proposedBlocks[id % LibConstants.TAIKO_MAX_PROPOSED_BLOCKS] = blk;
}

function getProposedBlock(
State storage s,
uint256 id
) internal view returns (ProposedBlock storage) {
return s.proposedBlocks[id % LibConstants.K_MAX_NUM_BLOCKS];
return s.proposedBlocks[id % LibConstants.TAIKO_MAX_PROPOSED_BLOCKS];
}

function getL2BlockHash(
Expand Down
95 changes: 38 additions & 57 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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]>
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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
);
}
Expand All @@ -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
);
}
Expand Down Expand Up @@ -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
);
}
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
);
}
}
87 changes: 87 additions & 0 deletions packages/protocol/contracts/L1/v1/V1Finalizing.sol
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);
}
}
}
}
Loading

0 comments on commit 5c83410

Please sign in to comment.