Skip to content

Commit

Permalink
refactor getdelay with main changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey committed Jan 4, 2023
2 parents 2f1810c + 191eb11 commit 5f07c4d
Show file tree
Hide file tree
Showing 54 changed files with 2,075 additions and 894 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/solidity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: "16.15"

- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
Expand All @@ -46,7 +46,15 @@ jobs:
- name: protocol - Unit Tests
working-directory: ./packages/protocol
run: pnpm install && pnpm clean && pnpm test:coverage && pnpm test:integration && pnpm export:abi
run: pnpm install && pnpm clean && pnpm test

- name: protocol - Integration Tests
working-directory: ./packages/protocol
run: pnpm test:integration

- name: protocol - Test Coverage
working-directory: ./packages/protocol
run: pnpm test:coverage

- name: protocol - Generate Genesis
working-directory: ./packages/protocol
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/.solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ contracts/test/TestLibRLPWriter.sol
contracts/libs/Lib1559Math.sol
contracts/libs/LibAddress.sol
contracts/libs/LibMath.sol
contracts/libs/LibUint512Math.sol
**/contracts/thirdparty/**/*.sol
64 changes: 64 additions & 0 deletions packages/protocol/contracts/L1/ProofVerifier.sol
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 <dan@taiko.xyz>
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
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,41 @@
// ╱╱╰╯╰╯╰┻┻╯╰┻━━╯╰━━━┻╯╰┻━━┻━━╯
pragma solidity ^0.8.9;

import "../libs/LibConstants.sol";

/// @author dantaik <dan@taiko.xyz>
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;
Expand All @@ -29,6 +60,7 @@ library LibData {
// 3 slots
struct ProposedBlock {
bytes32 metaHash;
uint256 deposit;
address proposer;
uint64 proposedAt;
}
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// ╱╱╰╯╰╯╰┻┻╯╰┻━━╯╰━━━┻╯╰┻━━┻━━╯
pragma solidity ^0.8.9;

import "../LibData.sol";
import "./TaikoData.sol";

/// @author david <david@taiko.xyz>
abstract contract V1Events {
abstract contract TaikoEvents {
// The following events must match the definitions in other V1 libraries.
event BlockVerified(uint256 indexed id, bytes32 blockHash);

Expand All @@ -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,
Expand All @@ -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);
}

0 comments on commit 5f07c4d

Please sign in to comment.