From caad4ff1fd4085b2fea16f63a4c5f052f37b3284 Mon Sep 17 00:00:00 2001 From: just-mitch <68168980+just-mitch@users.noreply.github.com> Date: Thu, 19 Sep 2024 20:19:18 -0400 Subject: [PATCH] feat: proofClaim in Rollup (#8636) Fix #8608 Add the proofClaim to the rollup. Update the `canPrune` logic to account for it. --- l1-contracts/src/core/Rollup.sol | 38 ++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/l1-contracts/src/core/Rollup.sol b/l1-contracts/src/core/Rollup.sol index 782a3910bce..b92f04cbdd2 100644 --- a/l1-contracts/src/core/Rollup.sol +++ b/l1-contracts/src/core/Rollup.sol @@ -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; @@ -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. @@ -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; }