Skip to content

Commit

Permalink
better randomness
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Jul 6, 2024
1 parent 3f93b70 commit af6e425
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ library TaikoData {
// this block is not verified as the last block in a batch, verifiedTransitionId
// will remain zero.
uint32 verifiedTransitionId;
uint16 minTier;
}

/// @dev Struct representing an Ethereum deposit.
Expand Down
13 changes: 10 additions & 3 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,18 @@ library LibProposing {
emit CalldataTxList(meta_.id, _txList);
}

uint16 minTier;
{
ITierRouter tierRouter = ITierRouter(_resolver.resolve(LibStrings.B_TIER_ROUTER, false));
ITierProvider tierProvider = ITierProvider(tierRouter.getProvider(local.b.numBlocks));

// Use the difficulty as a random number
meta_.minTier = tierProvider.getMinTier(uint256(meta_.difficulty));
if (local.postFork) {
minTier =
tierProvider.getMinTier(uint256(bytes32(block.prevrandao) ^ meta_.difficulty));
} else {
// Use the difficulty as a random number
meta_.minTier = tierProvider.getMinTier(uint256(meta_.difficulty));
}
}

// Create the block that will be stored onchain
Expand All @@ -217,7 +223,8 @@ library LibProposing {
// For a new block, the next transition ID is always 1, not 0.
nextTransitionId: 1,
// For unverified block, its verifiedTransitionId is always 0.
verifiedTransitionId: 0
verifiedTransitionId: 0,
minTier: minTier
});

// Store the block in the ring buffer
Expand Down
6 changes: 4 additions & 2 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ library LibProving {
uint64 slot;
uint64 blockId;
uint32 tid;
uint16 blockMinTier;
bool lastUnpausedAt;
bool isTopTier;
bool inProvingWindow;
Expand Down Expand Up @@ -165,6 +166,7 @@ library LibProving {
TaikoData.Block storage blk = _state.blocks[local.slot];

local.proposedAt = local.postFork ? meta.proposedAt : blk.proposedAt;
local.blockMinTier = meta.minTier == 0 ? blk.minTier : meta.minTier;

if (LibUtils.shouldSyncStateRoot(_config.stateRootSyncInternal, local.blockId)) {
local.stateRoot = tran.stateRoot;
Expand Down Expand Up @@ -197,7 +199,7 @@ library LibProving {

// The new proof must meet or exceed the minimum tier required by the
// block or the previous proof; it cannot be on a lower tier.
if (proof.tier == 0 || proof.tier < meta.minTier || proof.tier < ts.tier) {
if (proof.tier == 0 || proof.tier < local.blockMinTier || proof.tier < ts.tier) {
revert L1_INVALID_TIER();
}

Expand All @@ -208,7 +210,7 @@ library LibProving {
ITierProvider tierProvider = ITierProvider(tierRouter.getProvider(local.blockId));

local.tier = tierProvider.getTier(proof.tier);
local.minTier = tierProvider.getTier(meta.minTier);
local.minTier = tierProvider.getTier(local.blockMinTier);
}

local.inProvingWindow = !LibUtils.isPostDeadline({
Expand Down

0 comments on commit af6e425

Please sign in to comment.