Skip to content

Commit

Permalink
feat: proofClaim in Rollup (#8636)
Browse files Browse the repository at this point in the history
Fix #8608

Add the proofClaim to the rollup.

Update the `canPrune` logic to account for it.
  • Loading branch information
just-mitch committed Sep 27, 2024
1 parent 427b4e9 commit caad4ff
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
uint256 public constant CLAIM_DURATION_IN_L2_SLOTS = 13;
uint256 public constant PROOF_COMMITMENT_MIN_BOND_AMOUNT_IN_TST = 1000;

uint256 public constant CLAIM_DURATION_IN_L2_SLOTS = 13;
uint256 public constant PROOF_COMMITMENT_MIN_BOND_AMOUNT_IN_TST = 1000;

uint256 public immutable L1_BLOCK_AT_GENESIS;
IRegistry public immutable REGISTRY;
IInbox public immutable INBOX;
Expand Down Expand Up @@ -720,7 +723,26 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
return tips.pendingBlockNumber;
}

/**
* @notice Get the epoch that should be proven
*
* @dev This is the epoch that should be proven. It does so by getting the epoch of the block
* following the last proven block. If there is no such block (i.e. the pending chain is
* the same as the proven chain), then revert.
*
* @return uint256 - The epoch to prove
*/
function getEpochToProve() public view override(IRollup) returns (uint256) {
if (tips.provenBlockNumber == tips.pendingBlockNumber) {
revert Errors.Rollup__NoEpochToProve();
} else {
return getEpochAt(blocks[getProvenBlockNumber() + 1].slotNumber);
}
}

function _prune() internal {
delete proofClaim;

uint256 pending = tips.pendingBlockNumber;

// @note We are not deleting the blocks, but we are "winding back" the pendingTip to the last block that was proven.
Expand All @@ -741,12 +763,20 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
uint256 oldestPendingEpoch = getEpochAt(blocks[tips.provenBlockNumber + 1].slotNumber);
uint256 startSlotOfPendingEpoch = oldestPendingEpoch * Constants.AZTEC_EPOCH_DURATION;

// TODO: #8608 adds a proof claim, which will allow us to prune the chain more aggressively.
// That is what will add a `CLAIM_DURATION` to the pruning logic.
if (currentSlot < startSlotOfPendingEpoch + 2 * Constants.AZTEC_EPOCH_DURATION) {
// suppose epoch 1 is proven, epoch 2 is pending, epoch 3 is the current epoch.
// we prune the pending chain back to the end of epoch 1 if:
// - the proof claim phase of epoch 3 has ended without a claim to prove epoch 2 (or proof of epoch 2)
// - we reach epoch 4 without a proof of epoch 2 (regardless of whether a proof claim was submitted)
bool inClaimPhase = currentSlot
< startSlotOfPendingEpoch + Constants.AZTEC_EPOCH_DURATION + CLAIM_DURATION_IN_L2_SLOTS;

bool claimExists = currentSlot < startSlotOfPendingEpoch + 2 * Constants.AZTEC_EPOCH_DURATION
&& proofClaim.epochToProve == oldestPendingEpoch && proofClaim.proposerClaimant != address(0);

if (inClaimPhase || claimExists) {
// If we are in the claim phase, do not prune
return false;
}

return true;
}

Expand Down

0 comments on commit caad4ff

Please sign in to comment.