Skip to content

Commit

Permalink
refactor(protocol): simplify protocol for single prover/proof (#13216)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeffery Walsh <[email protected]>
Co-authored-by: David <[email protected]>
  • Loading branch information
3 people authored Feb 28, 2023
1 parent 84a1093 commit 0d86d4b
Show file tree
Hide file tree
Showing 29 changed files with 477 additions and 1,444 deletions.
10 changes: 3 additions & 7 deletions packages/protocol/contracts/L1/TaikoCustomErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pragma solidity ^0.8.18;
abstract contract TaikoCustomErrors {
// The following custom errors must match the definitions in other V1 libraries.
error L1_0_FEE_BASE();
error L1_ALREADY_PROVEN();
error L1_ANCHOR_CALLDATA();
error L1_ANCHOR_DEST();
error L1_ANCHOR_GAS_LIMIT();
Expand All @@ -24,28 +25,23 @@ abstract contract TaikoCustomErrors {
error L1_ANCHOR_TYPE();
error L1_BLOCK_NUMBER();
error L1_CANNOT_BE_FIRST_PROVER();
error L1_CIRCUIT_LENGTH();
error L1_COMMITTED();
error L1_CONFLICT_PROOF();
error L1_CONTRACT_NOT_ALLOWED();
error L1_DUP_PROVERS();
error L1_EXTRA_DATA();
error L1_GAS_LIMIT();
error L1_HALTED();
error L1_HALT_CONDITION();
error L1_ID();
error L1_INPUT_SIZE();
error L1_INVALID_PARAM();
error L1_METADATA_FIELD();
error L1_META_MISMATCH();
error L1_NOT_COMMITTED();
error L1_NOT_FIRST_PROVER();
error L1_NOT_ORACLE_PROVER();
error L1_PROOF_LENGTH();
error L1_PROVER();
error L1_SOLO_PROPOSER();
error L1_TOO_LATE();
error L1_TOO_MANY();
error L1_TOO_MANY_PROVERS();
error L1_TOO_MANY_BLOCKS();
error L1_TX_LIST();
error L1_ZKP();
}
21 changes: 14 additions & 7 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

pragma solidity ^0.8.18;

import {BlockHeader} from "../libs/LibBlockHeader.sol";

library TaikoData {
struct Config {
uint256 chainId;
Expand All @@ -14,10 +16,8 @@ library TaikoData {
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;
Expand All @@ -36,12 +36,9 @@ library TaikoData {
uint64 blockTimeCap;
uint64 proofTimeCap;
uint64 bootstrapDiscountHalvingPeriod;
uint64 initialUncleDelay;
uint64 proverRewardRandomizedPercentage;
bool enableTokenomics;
bool enablePublicInputsCheck;
bool enableAnchorValidation;
bool enableOracleProver;
}

struct BlockMetadata {
Expand All @@ -58,6 +55,14 @@ library TaikoData {
uint64 commitSlot;
}

struct Evidence {
TaikoData.BlockMetadata meta;
BlockHeader header;
address prover;
bytes[] proofs;
uint16 circuitId;
}

// 3 slots
struct ProposedBlock {
bytes32 metaHash;
Expand All @@ -69,8 +74,8 @@ library TaikoData {
// 3 + n slots
struct ForkChoice {
bytes32 blockHash;
address prover;
uint64 provenAt;
address[] provers;
}

// This struct takes 9 slots.
Expand All @@ -83,11 +88,13 @@ library TaikoData {
mapping(uint256 blockId => mapping(bytes32 parentHash => ForkChoice forkChoice)) forkChoices;
// solhint-disable-next-line max-line-length
mapping(address proposerAddress => mapping(uint256 commitSlot => bytes32 commitHash)) commits;
// solhint-disable-next-line max-line-length
mapping(address prover => uint256 outstandingReward) balances;
// Never or rarely changed
uint64 genesisHeight;
uint64 genesisTimestamp;
uint64 __reservedA1;
uint64 statusBits; // rarely change
uint64 __reservedA2;
// Changed when a block is proposed or proven/finalized
uint256 feeBase;
// Changed when a block is proposed
Expand Down
7 changes: 2 additions & 5 deletions packages/protocol/contracts/L1/TaikoEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ abstract contract TaikoEvents {
uint256 indexed id,
bytes32 parentHash,
bytes32 blockHash,
uint64 timestamp,
uint64 provenAt,
address prover
address prover,
uint64 provenAt
);

event Halted(bool halted);
}
59 changes: 10 additions & 49 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ contract TaikoL1 is
LibVerifying.verifyBlocks({
state: state,
config: config,
resolver: AddressResolver(this),
maxBlocks: config.maxVerificationsPerTx,
checkHalt: false
maxBlocks: config.maxVerificationsPerTx
});
}

Expand Down Expand Up @@ -136,9 +134,7 @@ contract TaikoL1 is
LibVerifying.verifyBlocks({
state: state,
config: config,
resolver: AddressResolver(this),
maxBlocks: config.maxVerificationsPerTx,
checkHalt: false
maxBlocks: config.maxVerificationsPerTx
});
}

Expand Down Expand Up @@ -172,9 +168,7 @@ contract TaikoL1 is
LibVerifying.verifyBlocks({
state: state,
config: config,
resolver: AddressResolver(this),
maxBlocks: config.maxVerificationsPerTx,
checkHalt: false
maxBlocks: config.maxVerificationsPerTx
});
}

Expand All @@ -187,18 +181,16 @@ contract TaikoL1 is
LibVerifying.verifyBlocks({
state: state,
config: getConfig(),
resolver: AddressResolver(this),
maxBlocks: maxBlocks,
checkHalt: true
maxBlocks: maxBlocks
});
}

/**
* Halt or resume the chain.
* @param toHalt True to halt, false to resume.
*/
function halt(bool toHalt) public onlyOwner {
LibUtils.halt(state, toHalt);
function withdrawBalance() external nonReentrant {
LibVerifying.withdrawBalance(state, AddressResolver(this));
}

function getRewardBalance(address addr) public view returns (uint256) {
return state.balances[addr];
}

function getBlockFee() public view returns (uint256) {
Expand All @@ -221,14 +213,6 @@ contract TaikoL1 is
});
}

/**
* Check if the L1 is halted.
* @return True if halted, false otherwise.
*/
function isHalted() public view returns (bool) {
return LibUtils.isHalted(state);
}

function isCommitValid(
uint256 commitSlot,
uint256 commitHeight,
Expand Down Expand Up @@ -287,29 +271,6 @@ contract TaikoL1 is
return state.forkChoices[id][parentHash];
}

function getUncleProofDelay(uint256 blockId) public view returns (uint64) {
return LibUtils.getUncleProofDelay(state, getConfig(), blockId);
}

function getProverRewardBips(
uint256 numProvers
) public view returns (uint256[] memory) {
return LibVerifying.getProverRewardBips(getConfig(), numProvers);
}

function isBlockVerifiable(
uint256 blockId,
bytes32 parentHash
) public view returns (bool) {
return
LibVerifying.isVerifiable({
state: state,
config: getConfig(),
fc: state.forkChoices[blockId][parentHash],
blockId: blockId
});
}

function getConfig() public pure virtual returns (TaikoData.Config memory) {
return LibSharedConfig.getConfig();
}
Expand Down
18 changes: 6 additions & 12 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ library LibProposing {
event BlockCommitted(uint64 commitSlot, bytes32 commitHash);
event BlockProposed(uint256 indexed id, TaikoData.BlockMetadata meta);

error L1_METADATA_FIELD();
error L1_COMMITTED();
error L1_EXTRA_DATA();
error L1_ID();
error L1_TOO_MANY();
error L1_GAS_LIMIT();
error L1_COMMITTED();
error L1_ID();
error L1_INPUT_SIZE();
error L1_METADATA_FIELD();
error L1_NOT_COMMITTED();
error L1_SOLO_PROPOSER();
error L1_INPUT_SIZE();
error L1_TOO_MANY_BLOCKS();
error L1_TX_LIST();

function commitBlock(
Expand All @@ -43,10 +43,6 @@ library LibProposing {
bytes32 commitHash
) public {
assert(config.commitConfirmations > 0);
// It's OK to allow committing block when the system is halt.
// By not checking the halt status, this method will be cheaper.
//
// assert(!LibUtils.isHalted(state));

bytes32 hash = _aggregateCommitHash(block.number, commitHash);

Expand All @@ -73,8 +69,6 @@ library LibProposing {
if (soloProposer != address(0) && soloProposer != msg.sender)
revert L1_SOLO_PROPOSER();

assert(!LibUtils.isHalted(state));

if (inputs.length != 2) revert L1_INPUT_SIZE();
TaikoData.BlockMetadata memory meta = abi.decode(
inputs[0],
Expand All @@ -99,7 +93,7 @@ library LibProposing {
if (
state.nextBlockId >=
state.latestVerifiedId + config.maxNumBlocks
) revert L1_TOO_MANY();
) revert L1_TOO_MANY_BLOCKS();

meta.id = state.nextBlockId;
meta.l1Height = block.number - 1;
Expand Down
Loading

0 comments on commit 0d86d4b

Please sign in to comment.