Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/passthrough-params
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Dec 3, 2024
2 parents fb85616 + c994801 commit dd32b04
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
30 changes: 22 additions & 8 deletions src/SimplePDPService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,40 @@ contract SimplePDPService is PDPListener, PDPRecordKeeper, Initializable, UUPSUp
return 2880;
}

// Number of epochs at the end of a provoing period during which a
// Number of epochs at the end of a proving period during which a
// proof of possession can be submitted
function challengeWindow() public pure returns (uint256) {
return 60;
}

// The start of the next challenge window
// Useful for querying before nextProvingPeriod to determine challengeEpoch
function nextChallengeWindowStart(uint256 setId) public view returns (uint256) {
// The start of the challenge window for the current proving period
function thisChallengeWindowStart(uint256 setId) public view returns (uint256) {
if (provingDeadlines[setId] == 0) {
revert("Proving period not yet open");
revert("Proving not yet started");
}

uint256 periodsSkipped;
// Proving period is open 0 skipped periods
if (block.number <= provingDeadlines[setId]) {
periodsSkipped = 0;
} else { // Proving period has closed possibly some skipped periods
periodsSkipped = (block.number - (provingDeadlines[setId] + 1)) / getMaxProvingPeriod();
periodsSkipped = 1 + (block.number - (provingDeadlines[setId] + 1)) / getMaxProvingPeriod();
}
return provingDeadlines[setId] + periodsSkipped*getMaxProvingPeriod() - challengeWindow();
}

// The start of the NEXT OPEN proving period's challenge window
// Useful for querying before nextProvingPeriod to determine challengeEpoch to submit for nextProvingPeriod
function nextChallengeWindowStart(uint256 setId) public view returns (uint256) {
if (provingDeadlines[setId] == 0) {
revert("Proving not yet started");
}
// If the current period is open this is the next period's challenge window
if (block.number <= provingDeadlines[setId]) {
return thisChallengeWindowStart(setId) + getMaxProvingPeriod();
}
return provingDeadlines[setId] + getMaxProvingPeriod()*(periodsSkipped+1) - challengeWindow();
// If the current period is not yet open this is the current period's challenge window
return thisChallengeWindowStart(setId);
}

// Challenges / merkle inclusion proofs provided per proof set
Expand Down Expand Up @@ -204,7 +218,7 @@ contract SimplePDPService is PDPListener, PDPRecordKeeper, Initializable, UUPSUp
if (faultPeriods > 0) {
emit FaultRecord(faultPeriods);
}
provingDeadlines[proofSetId] = nextDeadline;
provingDeadlines[proofSetId] = nextDeadline;
provenThisPeriod[proofSetId] = false;
}
}
6 changes: 3 additions & 3 deletions test/SimplePDPService.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ contract SimplePDPServiceFaultsTest is Test {
assertFalse(pdpService.provenThisPeriod(proofSetId));

vm.expectRevert("One call to nextProvingPeriod allowed per proving period");
pdpService.nextProvingPeriod(proofSetId, challengeEpoch, leafCount, empty);
pdpService.nextProvingPeriod(proofSetId, challengeEpoch, leafCount, empty);
}

function testFaultWithinOpenPeriod() public {
Expand Down Expand Up @@ -277,7 +277,7 @@ contract SimplePDPServiceFaultsTest is Test {

function testMissChallengeWindowAfterFaults() public {
pdpService.rootsAdded(proofSetId, 0, new PDPVerifier.RootData[](0), empty);

// Skip 2 proving periods
vm.roll(block.number + pdpService.getMaxProvingPeriod() * 3 - 100);

Expand All @@ -286,7 +286,7 @@ contract SimplePDPServiceFaultsTest is Test {
vm.expectRevert("Next challenge epoch must fall within the next challenge window");
pdpService.nextProvingPeriod(proofSetId, tooEarly, leafCount, empty);

// Too late
// Too late
uint256 tooLate = pdpService.nextChallengeWindowStart(proofSetId)+pdpService.challengeWindow()+1;
vm.expectRevert("Next challenge epoch must fall within the next challenge window");
pdpService.nextProvingPeriod(proofSetId, tooLate, leafCount, empty);
Expand Down

0 comments on commit dd32b04

Please sign in to comment.