Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify fault design #67

Merged
merged 7 commits into from
Nov 21, 2024
Merged

Simplify fault design #67

merged 7 commits into from
Nov 21, 2024

Conversation

ZenGround0
Copy link
Contributor

No description provided.

@@ -170,9 +164,14 @@ contract SimplePDPService is PDPListener, PDPRecordKeeper, Initializable, UUPSUp
uint256 periodsSkipped = 1;
if (provingDeadlines[proofSetId] < block.number) {
periodsSkipped = 1 + ((block.number - provingDeadlines[proofSetId]) / getMaxProvingPeriod());
provingDeadlines[proofSetId] = block.number + getMaxProvingPeriod(); // reset deadline
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that also be provingDeadlines[proofSetId] = provingDeadlines[proofSetId] + getMaxProvingPeriod(); to keep the deadline in a fixed window?

The current way the proving window will keep sliding backwards as I have to compute and submit the proof some time before the deadline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM but we need to catch up multiple windows if we missed multiple otherwise you need to call this a bunch. So you'll need to add periodsSkipped I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't PR now but fee lfree to push

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some discussion about policy options here, it wants a bit of thought.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current way the proving window will keep sliding backwards as I have to compute and submit the proof some time before the deadline

Note the line you commented on is only the unproven case, so it only slides until a valid proof is submitted. But note also there's no window or equivalent here that makes the deadline really matter: the proof can be submitted any time in the 24hr window (after the short challenge delay). So I don't think the scheduling matters as much as it does for Window PoST.

Copy link
Collaborator

@anorth anorth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would benefit from some tests demonstrating the behaviour, especially around when the proving deadline moves.

@@ -170,9 +164,14 @@ contract SimplePDPService is PDPListener, PDPRecordKeeper, Initializable, UUPSUp
uint256 periodsSkipped = 1;
if (provingDeadlines[proofSetId] < block.number) {
periodsSkipped = 1 + ((block.number - provingDeadlines[proofSetId]) / getMaxProvingPeriod());
provingDeadlines[proofSetId] = block.number + getMaxProvingPeriod(); // reset deadline
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current way the proving window will keep sliding backwards as I have to compute and submit the proof some time before the deadline

Note the line you commented on is only the unproven case, so it only slides until a valid proof is submitted. But note also there's no window or equivalent here that makes the deadline really matter: the proof can be submitted any time in the 24hr window (after the short challenge delay). So I don't think the scheduling matters as much as it does for Window PoST.

}
emit FaultRecord(FaultType.SKIPPED, periodsSkipped);
}

}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update provingDeadlines[proofSetId] if there was a successful proof, too.

@ZenGround0
Copy link
Contributor Author

Because things were getting too complicated I did a small redesign here. This should now close
#71 #66 and #65

Copy link
Collaborator

@anorth anorth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is very close.

The grinding that I see remaining could only be exercised with integration tests, which we lack. I suggest following up to add some integration tests, with some of them explicitly constructed from an "SP trying to cheat" frame.

Comment on lines 172 to 181
uint256 periodsSkipped = (block.number - provingDeadlines[proofSetId]) / getMaxProvingPeriod();
uint256 faultPeriods = periodsSkipped;
if (!provenThisPeriod[proofSetId]) {
// include previous unproven period
faultPeriods += 1;
}
if (faultPeriods > 0) {
emit FaultRecord(faultPeriods);
}
provingDeadlines[proofSetId] = provingDeadlines[proofSetId] + getMaxProvingPeriod()*periodsSkipped;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think this code could also handle the on-time case, with something like periodsSkipped = max(0, (block.number - provingDeadlines[proofSetId])) / getMaxProvingPeriod(). The rest is basically duplicate.

// Can only get here if calling nextProvingPeriod multiple times within the same proving period
uint256 prevDeadline = provingDeadlines[proofSetId] - getMaxProvingPeriod();
if (block.number <= prevDeadline) {
return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to revert. As is, a provider could grind challenges by calling verifier.nextProvingPeriod once each epoch after a successful proof until the deadline is reached.

In general, I think any call to this method must either (1) advance the proving period (possibly with fault), or (2) revert.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me think that, in the PDP Verifier contract, the method name nextProvingPeriod is not quite right. That contract doesn't know anything about proving periods. It could instead be newChallenge or something. However since that's the method actually invoked by SPs, I can see the motivation for a name that represents their expected workflow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch on the revert.

Yeah I'm still not happy with the name but there is some sort of proving period thing that the pdp verifier knows about. Namely when batched adds and removes get added into the proofset. I think this name is probably ok for now even though pdp service has a modified idea of proving period

contracts/test/SimplePDPService.t.sol Outdated Show resolved Hide resolved
@ZenGround0 ZenGround0 changed the title Fixing up bug caught in delayed review Simplify fault design Nov 19, 2024
initializeData = abi.encodeWithSelector(SimplePDPService.initialize.selector, address(pdpVerifier));
MyERC1967Proxy listenerProxy = new MyERC1967Proxy(address(listenerImpl), initializeData);
listener = SimplePDPService(address(listenerProxy));
listener = new TestingRecordKeeperService();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@ZenGround0 ZenGround0 merged commit 19993af into main Nov 21, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants