Skip to content

Commit

Permalink
Double call to NPP reverts
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenGround0 committed Nov 20, 2024
1 parent eeb54b1 commit 9605d2a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 33 deletions.
6 changes: 3 additions & 3 deletions contracts/src/SimplePDPService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contract PDPRecordKeeper {
}
}

// SimplePDPServiceApplication is a default implementation of a PDP Application.
// SimplePDPServiceApplication is a default implementation of a PDP Listener
// It maintains a record of all events that have occurred in the PDP service,
// and provides a way to query these events.
// This contract only supports one PDP service caller, set in the constructor.
Expand Down Expand Up @@ -157,7 +157,7 @@ contract SimplePDPService is PDPListener, PDPRecordKeeper, Initializable, UUPSUp
// Can only get here if calling nextProvingPeriod multiple times within the same proving period
uint256 prevDeadline = provingDeadlines[proofSetId] - getMaxProvingPeriod();
if (block.number <= prevDeadline) {
return;
revert("One call to nextProvingPeriod allowed per proving period");
}

uint256 periodsSkipped;
Expand All @@ -178,4 +178,4 @@ contract SimplePDPService is PDPListener, PDPRecordKeeper, Initializable, UUPSUp
provingDeadlines[proofSetId] = provingDeadlines[proofSetId] + getMaxProvingPeriod()*(periodsSkipped+1);
provenThisPeriod[proofSetId] = false;
}
}
}
35 changes: 10 additions & 25 deletions contracts/test/PDPVerifier.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {PDPFees} from "../src/Fees.sol";
import {SimplePDPService, PDPRecordKeeper} from "../src/SimplePDPService.sol";

contract PDPVerifierProofSetCreateDeleteTest is Test {
SimplePDPService listener;
TestingRecordKeeperService listener;
ListenerHelper listenerAssert;
PDPVerifier pdpVerifier;

Expand All @@ -23,10 +23,7 @@ contract PDPVerifierProofSetCreateDeleteTest is Test {
);
MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData);
pdpVerifier = PDPVerifier(address(proxy));
SimplePDPService listenerImpl = new SimplePDPService();
initializeData = abi.encodeWithSelector(SimplePDPService.initialize.selector, address(pdpVerifier));
MyERC1967Proxy listenerProxy = new MyERC1967Proxy(address(listenerImpl), initializeData);
listener = SimplePDPService(address(listenerProxy));
listener = new TestingRecordKeeperService();
listenerAssert = new ListenerHelper(address(listener));
}
function tearDown() public view {
Expand Down Expand Up @@ -147,7 +144,7 @@ contract PDPVerifierProofSetCreateDeleteTest is Test {

contract PDPVerifierOwnershipTest is Test {
PDPVerifier pdpVerifier;
SimplePDPService listener;
TestingRecordKeeperService listener;
address public owner;
address public nextOwner;
address public nonOwner;
Expand All @@ -160,10 +157,7 @@ contract PDPVerifierOwnershipTest is Test {
);
MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData);
pdpVerifier = PDPVerifier(address(proxy));
SimplePDPService listenerImpl = new SimplePDPService();
initializeData = abi.encodeWithSelector(SimplePDPService.initialize.selector, address(pdpVerifier));
MyERC1967Proxy listenerProxy = new MyERC1967Proxy(address(listenerImpl), initializeData);
listener = SimplePDPService(address(listenerProxy));
listener = new TestingRecordKeeperService();

owner = address(this);
nextOwner = address(0x1234);
Expand Down Expand Up @@ -231,7 +225,7 @@ contract PDPVerifierProofSetMutateTest is Test {
uint256 constant challengeFinalityDelay = 2;

PDPVerifier pdpVerifier;
SimplePDPService listener;
TestingRecordKeeperService listener;
ListenerHelper listenerAssert;

function setUp() public {
Expand All @@ -242,10 +236,7 @@ contract PDPVerifierProofSetMutateTest is Test {
);
MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData);
pdpVerifier = PDPVerifier(address(proxy));
SimplePDPService listenerImpl = new SimplePDPService();
initializeData = abi.encodeWithSelector(SimplePDPService.initialize.selector, address(pdpVerifier));
MyERC1967Proxy listenerProxy = new MyERC1967Proxy(address(listenerImpl), initializeData);
listener = SimplePDPService(address(listenerProxy));
listener = new TestingRecordKeeperService();
listenerAssert = new ListenerHelper(address(listener));
}

Expand Down Expand Up @@ -887,7 +878,7 @@ import "../src/PDPVerifier.sol";

contract SumTreeAddTest is Test {
SumTreeInternalTestPDPVerifier pdpVerifier;
SimplePDPService listener;
TestingRecordKeeperService listener;
uint256 testSetId;

function setUp() public {
Expand All @@ -898,10 +889,7 @@ contract SumTreeAddTest is Test {
);
MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData);
pdpVerifier = SumTreeInternalTestPDPVerifier(address(proxy));
SimplePDPService listenerImpl = new SimplePDPService();
initializeData = abi.encodeWithSelector(SimplePDPService.initialize.selector, address(pdpVerifier));
MyERC1967Proxy listenerProxy = new MyERC1967Proxy(address(listenerImpl), initializeData);
listener = SimplePDPService(address(listenerProxy));
listener = new TestingRecordKeeperService();
testSetId = pdpVerifier.createProofSet{value: PDPFees.sybilFee()}(address(listener));
}

Expand Down Expand Up @@ -1263,7 +1251,7 @@ contract PDPListenerIntegrationTest is Test {

contract PDPVerifierE2ETest is Test, ProofBuilderHelper {
PDPVerifier pdpVerifier;
SimplePDPService listener;
TestingRecordKeeperService listener;
uint256 constant challengeFinalityDelay = 2;

function setUp() public {
Expand All @@ -1274,10 +1262,7 @@ contract PDPVerifierE2ETest is Test, ProofBuilderHelper {
);
MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData);
pdpVerifier = PDPVerifier(address(proxy));
SimplePDPService listenerImpl = new SimplePDPService();
initializeData = abi.encodeWithSelector(SimplePDPService.initialize.selector, address(pdpVerifier));
MyERC1967Proxy listenerProxy = new MyERC1967Proxy(address(listenerImpl), initializeData);
listener = SimplePDPService(address(listenerProxy));
listener = new TestingRecordKeeperService();
}

function testCompleteProvingPeriodE2E() public {
Expand Down
8 changes: 3 additions & 5 deletions contracts/test/SimplePDPService.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ contract SimplePDPServiceFaultsTest is Test {
pdpService.posessionProven(proofSetId, leafCount, seed, challengeCount);
}

// TODO this should change to a revert
function testNextProvingPeriodNoop() public {
function testNextProvingPeriodTwiceFails() public {
// Set up the proving deadline
pdpService.rootsAdded(proofSetId, 0, new PDPVerifier.RootData[](0));
vm.roll(block.number + pdpService.getMaxProvingPeriod() - 100);
Expand All @@ -153,11 +152,10 @@ contract SimplePDPServiceFaultsTest is Test {
assertEq(pdpService.provingDeadlines(proofSetId), deadline1, "Proving deadline should not change until nextProvingPeriod.");
pdpService.nextProvingPeriod(proofSetId, leafCount);
assertEq(pdpService.provingDeadlines(proofSetId), deadline1 + pdpService.getMaxProvingPeriod(), "Proving deadline should be updated");
uint256 deadline2 = pdpService.provingDeadlines(proofSetId);
assertFalse(pdpService.provenThisPeriod(proofSetId));

pdpService.nextProvingPeriod(proofSetId, leafCount); // NOOP
assertEq(pdpService.provingDeadlines(proofSetId), deadline2, "Proving deadline should not change");
vm.expectRevert("One call to nextProvingPeriod allowed per proving period");
pdpService.nextProvingPeriod(proofSetId, leafCount);
}

function testFaultWithinOpenPeriod() public {
Expand Down

0 comments on commit 9605d2a

Please sign in to comment.