Skip to content

Commit d9baebe

Browse files
authored
fix: bug in slot to timestamp conversion (#8839)
fixes issue with autopruning where we weren't converting slot to timestamp before getting epoch.
1 parent b5fc91c commit d9baebe

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

l1-contracts/src/core/Rollup.sol

+3-2
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
728728
if (tips.provenBlockNumber == tips.pendingBlockNumber) {
729729
revert Errors.Rollup__NoEpochToProve();
730730
} else {
731-
return getEpochAt(blocks[getProvenBlockNumber() + 1].slotNumber);
731+
return getEpochAt(getTimestampForSlot(blocks[getProvenBlockNumber() + 1].slotNumber));
732732
}
733733
}
734734

@@ -770,7 +770,8 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
770770
}
771771

772772
uint256 currentSlot = getCurrentSlot();
773-
uint256 oldestPendingEpoch = getEpochAt(blocks[tips.provenBlockNumber + 1].slotNumber);
773+
uint256 oldestPendingEpoch =
774+
getEpochAt(getTimestampForSlot(blocks[tips.provenBlockNumber + 1].slotNumber));
774775
uint256 startSlotOfPendingEpoch = oldestPendingEpoch * Constants.AZTEC_EPOCH_DURATION;
775776

776777
// suppose epoch 1 is proven, epoch 2 is pending, epoch 3 is the current epoch.

l1-contracts/test/Rollup.t.sol

+35-21
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ contract RollupTest is DecoderBase {
113113
}
114114

115115
function testClaimWithWrongEpoch() public setUpFor("mixed_block_1") {
116-
_testBlock("mixed_block_1", false, 0);
116+
_testBlock("mixed_block_1", false, 1);
117117

118118
quote.quote.epochToProve = 1;
119119

@@ -126,7 +126,7 @@ contract RollupTest is DecoderBase {
126126
}
127127

128128
function testClaimWithInsufficientBond() public setUpFor("mixed_block_1") {
129-
_testBlock("mixed_block_1", false, 0);
129+
_testBlock("mixed_block_1", false, 1);
130130

131131
quote.quote.bondAmount = 0;
132132

@@ -141,22 +141,18 @@ contract RollupTest is DecoderBase {
141141
}
142142

143143
function testClaimPastValidUntil() public setUpFor("mixed_block_1") {
144-
_testBlock("mixed_block_1", false, 0);
144+
_testBlock("mixed_block_1", false, 1);
145145

146146
quote.quote.validUntilSlot = 0;
147147

148-
warpToL2Slot(1);
149-
150148
vm.expectRevert(
151149
abi.encodeWithSelector(Errors.Rollup__QuoteExpired.selector, 1, quote.quote.validUntilSlot)
152150
);
153151
rollup.claimEpochProofRight(quote);
154152
}
155153

156154
function testClaimSimple() public setUpFor("mixed_block_1") {
157-
_testBlock("mixed_block_1", false, 0);
158-
159-
warpToL2Slot(1);
155+
_testBlock("mixed_block_1", false, 1);
160156

161157
vm.expectEmit(true, true, true, true);
162158
emit IRollup.ProofRightClaimed(
@@ -181,9 +177,7 @@ contract RollupTest is DecoderBase {
181177
}
182178

183179
function testClaimTwice() public setUpFor("mixed_block_1") {
184-
_testBlock("mixed_block_1", false, 0);
185-
186-
warpToL2Slot(1);
180+
_testBlock("mixed_block_1", false, 1);
187181

188182
rollup.claimEpochProofRight(quote);
189183

@@ -208,7 +202,7 @@ contract RollupTest is DecoderBase {
208202
}
209203

210204
function testClaimOutsideClaimPhase() public setUpFor("mixed_block_1") {
211-
_testBlock("mixed_block_1", false, 0);
205+
_testBlock("mixed_block_1", false, 1);
212206

213207
warpToL2Slot(Constants.AZTEC_EPOCH_DURATION + rollup.CLAIM_DURATION_IN_L2_SLOTS());
214208

@@ -223,7 +217,7 @@ contract RollupTest is DecoderBase {
223217
}
224218

225219
function testNoPruneWhenClaimExists() public setUpFor("mixed_block_1") {
226-
_testBlock("mixed_block_1", false, 0);
220+
_testBlock("mixed_block_1", false, 1);
227221

228222
quote.quote.validUntilSlot = 2 * Constants.AZTEC_EPOCH_DURATION;
229223

@@ -238,7 +232,7 @@ contract RollupTest is DecoderBase {
238232
}
239233

240234
function testPruneWhenClaimExpires() public setUpFor("mixed_block_1") {
241-
_testBlock("mixed_block_1", false, 0);
235+
_testBlock("mixed_block_1", false, 1);
242236

243237
quote.quote.validUntilSlot = 2 * Constants.AZTEC_EPOCH_DURATION;
244238

@@ -259,34 +253,36 @@ contract RollupTest is DecoderBase {
259253
}
260254

261255
function testClaimAfterPrune() public setUpFor("mixed_block_1") {
262-
_testBlock("mixed_block_1", false, 0);
256+
_testBlock("mixed_block_1", false, 1);
263257

264-
quote.quote.validUntilSlot = 2 * Constants.AZTEC_EPOCH_DURATION;
258+
quote.quote.validUntilSlot = 3 * Constants.AZTEC_EPOCH_DURATION;
265259
quote.quote.prover = address(this);
266260

267261
warpToL2Slot(Constants.AZTEC_EPOCH_DURATION + rollup.CLAIM_DURATION_IN_L2_SLOTS() - 1);
268262

269263
rollup.claimEpochProofRight(quote);
270264

271-
warpToL2Slot(Constants.AZTEC_EPOCH_DURATION * 2);
265+
warpToL2Slot(Constants.AZTEC_EPOCH_DURATION * 3);
272266

273267
rollup.prune();
274268

275-
_testBlock("mixed_block_1", false, Constants.AZTEC_EPOCH_DURATION * 2);
269+
_testBlock("mixed_block_1", false, Constants.AZTEC_EPOCH_DURATION * 3);
270+
271+
quote.quote.epochToProve = 3;
276272

277273
vm.expectEmit(true, true, true, true);
278274
emit IRollup.ProofRightClaimed(
279275
quote.quote.epochToProve,
280276
address(this),
281277
address(this),
282278
quote.quote.bondAmount,
283-
Constants.AZTEC_EPOCH_DURATION * 2
279+
Constants.AZTEC_EPOCH_DURATION * 3
284280
);
285281
rollup.claimEpochProofRight(quote);
286282
}
287283

288284
function testPruneWhenNoProofClaim() public setUpFor("mixed_block_1") {
289-
_testBlock("mixed_block_1", false);
285+
_testBlock("mixed_block_1", false, 1);
290286
warpToL2Slot(Constants.AZTEC_EPOCH_DURATION + rollup.CLAIM_DURATION_IN_L2_SLOTS() - 1);
291287
vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__NothingToPrune.selector));
292288
rollup.prune();
@@ -398,8 +394,26 @@ contract RollupTest is DecoderBase {
398394
assertNotEq(minHeightEmpty, minHeightMixed, "Invalid min height");
399395
}
400396

397+
function testShouldNotBeTooEagerToPrune() public setUpFor("mixed_block_1") {
398+
warpToL2Slot(1);
399+
_testBlock("mixed_block_1", false, 1);
400+
// we prove epoch 0
401+
rollup.setAssumeProvenThroughBlockNumber(rollup.getPendingBlockNumber());
402+
403+
// jump to epoch 1
404+
warpToL2Slot(Constants.AZTEC_EPOCH_DURATION);
405+
_testBlock("mixed_block_2", false, Constants.AZTEC_EPOCH_DURATION);
406+
407+
// jump to epoch 2
408+
warpToL2Slot(Constants.AZTEC_EPOCH_DURATION * 2);
409+
410+
vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__NothingToPrune.selector));
411+
rollup.prune();
412+
}
413+
401414
function testPruneDuringPropose() public setUpFor("mixed_block_1") {
402-
_testBlock("mixed_block_1", false);
415+
_testBlock("mixed_block_1", false, 1);
416+
assertEq(rollup.getEpochToProve(), 0, "Invalid epoch to prove");
403417
warpToL2Slot(Constants.AZTEC_EPOCH_DURATION * 2);
404418
_testBlock("mixed_block_1", false, Constants.AZTEC_EPOCH_DURATION * 2);
405419

0 commit comments

Comments
 (0)