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

refactor(protocol): simplify protocol for single prover/proof #13216

Merged
merged 58 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
21fdb30
refactor(protocol): avoid memory copy
dantaik Feb 26, 2023
26d2b86
single_prover
dantaik Feb 26, 2023
87dbce0
more
dantaik Feb 26, 2023
38680ee
more
dantaik Feb 26, 2023
bb0dc18
Update LibProving.sol
dantaik Feb 26, 2023
bb9febd
fix
dantaik Feb 26, 2023
1f2f4b5
- halt
dantaik Feb 26, 2023
69c50ba
fix
dantaik Feb 26, 2023
8486624
fix
dantaik Feb 26, 2023
10d23a4
Update LibProving.sol
dantaik Feb 26, 2023
4d73c02
Update LibProving.sol
dantaik Feb 26, 2023
09ecda2
minor
dantaik Feb 26, 2023
f26a3d0
more
dantaik Feb 26, 2023
8976513
Update LibProving.sol
dantaik Feb 26, 2023
b63e6e4
fix
dantaik Feb 26, 2023
3a5c901
Update LibProving.sol
dantaik Feb 26, 2023
de4b44d
Update LibProving.sol
dantaik Feb 26, 2023
780d6ad
more
dantaik Feb 26, 2023
397e9fe
fix
dantaik Feb 26, 2023
2d0f3dd
fix
dantaik Feb 26, 2023
ae547e7
Merge branch 'small_optimize' into single_prover
dantaik Feb 26, 2023
3d3250c
Update LibVerifying.sol
dantaik Feb 26, 2023
50d7350
Update LibVerifying.sol
dantaik Feb 26, 2023
6ff7fc2
Update LibVerifying.sol
dantaik Feb 26, 2023
b8add1d
Update LibVerifying.sol
dantaik Feb 26, 2023
3d95473
Update LibVerifying.sol
dantaik Feb 26, 2023
66c7b6d
Update LibProving.sol
dantaik Feb 26, 2023
d17584c
Update LibProving.sol
dantaik Feb 26, 2023
6c6e485
Update LibProving.sol
dantaik Feb 26, 2023
a1084af
fix
dantaik Feb 27, 2023
1d9cb07
Update LibVerifying.sol
dantaik Feb 27, 2023
a187622
Update LibVerifying.sol
dantaik Feb 27, 2023
9b6dc6b
fix unit tests
dantaik Feb 27, 2023
8c10167
fix tests
dantaik Feb 27, 2023
9427182
Merge branch 'main' into single_prover
dantaik Feb 27, 2023
2a71a7e
Update TestLibProving.sol
dantaik Feb 27, 2023
1ebdc5c
rename
dantaik Feb 27, 2023
a0f5a92
fix
dantaik Feb 27, 2023
e31b299
fix
dantaik Feb 27, 2023
caae183
Update proofReward.test.ts
dantaik Feb 27, 2023
af66713
fix
dantaik Feb 27, 2023
66efb3d
fix
dantaik Feb 27, 2023
8d08897
Update hardhat.config.ts
dantaik Feb 27, 2023
879dd8e
Update proofReward.test.ts
dantaik Feb 27, 2023
9711942
Update blockFee.test.ts
dantaik Feb 27, 2023
e1c6543
Update blockFee.test.ts
dantaik Feb 27, 2023
1847f15
Update blockFee.test.ts
dantaik Feb 27, 2023
99c2db0
Update LibVerifying.sol
dantaik Feb 27, 2023
66186d8
Update LibVerifying.sol
dantaik Feb 27, 2023
281e1d9
remove .only
cyberhorsey Feb 27, 2023
304273d
Lower all test halving periods
cyberhorsey Feb 27, 2023
18d58c4
rm multiple provers test, since we only have one now
cyberhorsey Feb 27, 2023
013afbb
update prover tests
cyberhorsey Feb 27, 2023
ac750ed
Merge branch 'main' into single_prover
davidtaikocha Feb 28, 2023
3205ff8
Merge branch 'main' into single_prover
davidtaikocha Feb 28, 2023
ee862b7
fix
dantaik Feb 28, 2023
85663bc
Update main.py
dantaik Feb 28, 2023
73cf863
Merge branch 'main' into single_prover
dantaik Feb 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Brechtpd marked this conversation as resolved.
Show resolved Hide resolved
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