Skip to content

Commit

Permalink
feat(protocol): allow whitelisting proposers (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Dec 5, 2022
1 parent 0a37cd9 commit 80b99a4
Show file tree
Hide file tree
Showing 45 changed files with 905 additions and 608 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ dist
# vscode
.vscode/

.pdf
# python
__pycache__/

# whitepaper
.pdf
2 changes: 2 additions & 0 deletions packages/protocol/.solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ contracts/aux/tokens/ERC20Upgradeable.sol
contracts/test/TestLibRLPReader.sol
contracts/test/TestLibRLPWriter.sol
contracts/libs/Lib1559Math.sol
contracts/libs/LibAddress.sol
contracts/libs/LibMath.sol
**/contracts/thirdparty/**/*.sol
56 changes: 40 additions & 16 deletions packages/protocol/contracts/L1/LibData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ library LibData {
uint64 commitSlot;
}

// 3 slots
struct ProposedBlock {
bytes32 metaHash;
address proposer;
uint64 proposedAt;
}

// 3 + n slots
struct ForkChoice {
bytes32 blockHash;
uint64 proposedAt;
uint64 provenAt;
address[] provers;
}

// This struct takes 9 slots.
struct State {
// block id => block hash
mapping(uint256 => bytes32) l2Hashes;
Expand All @@ -46,39 +50,59 @@ library LibData {
mapping(uint256 => mapping(bytes32 => ForkChoice)) forkChoices;
// proposer => commitSlot => hash(commitHash, commitHeight)
mapping(address => mapping(uint256 => bytes32)) commits;
mapping(address => bool) provers; // Whitelisted provers
uint64 statusBits;
// Never or rarely changed
uint64 genesisHeight;
uint64 genesisTimestamp;
uint64 __reservedA1;
uint64 statusBits; // rarely change
// 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 gaslimit moving average, not updated.
// Changed when a block is proven/finalized
uint64 latestVerifiedHeight;
uint64 latestVerifiedId;
uint64 nextBlockId;
uint64 avgProofTime; // the proof time moving average
uint64 __reservedC1;
// 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 s,
LibData.State storage state,
uint256 id,
ProposedBlock memory blk
) internal {
s.proposedBlocks[id % LibConstants.TAIKO_MAX_PROPOSED_BLOCKS] = blk;
state.proposedBlocks[id % LibConstants.K_MAX_NUM_BLOCKS] = blk;
}

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

function getL2BlockHash(
State storage s,
State storage state,
uint256 number
) internal view returns (bytes32) {
require(number <= s.latestVerifiedHeight, "L1:id");
return s.l2Hashes[number];
require(number <= state.latestVerifiedHeight, "L1:id");
return state.l2Hashes[number];
}

function getStateVariables(
State storage s
State storage state
)
internal
view
Expand All @@ -89,10 +113,10 @@ library LibData {
uint64 nextBlockId
)
{
genesisHeight = s.genesisHeight;
latestVerifiedHeight = s.latestVerifiedHeight;
latestVerifiedId = s.latestVerifiedId;
nextBlockId = s.nextBlockId;
genesisHeight = state.genesisHeight;
latestVerifiedHeight = state.latestVerifiedHeight;
latestVerifiedId = state.latestVerifiedId;
nextBlockId = state.nextBlockId;
}

function hashMetadata(
Expand Down
Loading

0 comments on commit 80b99a4

Please sign in to comment.