Reject when probability is 0 (#212)

* Reject when probability is 0
* Apply custom error
This commit is contained in:
Arnaud 2025-01-24 10:13:45 +01:00 committed by GitHub
parent bfa5a78b4f
commit 604d4c87eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View File

@ -19,6 +19,7 @@ abstract contract Proofs is Periods {
error Proofs_ProofNotMissing(); error Proofs_ProofNotMissing();
error Proofs_ProofNotRequired(); error Proofs_ProofNotRequired();
error Proofs_ProofAlreadyMarkedMissing(); error Proofs_ProofAlreadyMarkedMissing();
error Proofs_InvalidProbability();
ProofConfig private _config; ProofConfig private _config;
IGroth16Verifier private _verifier; IGroth16Verifier private _verifier;
@ -69,6 +70,9 @@ abstract contract Proofs is Periods {
* and saves the required probability. * and saves the required probability.
*/ */
function _startRequiringProofs(SlotId id, uint256 probability) internal { function _startRequiringProofs(SlotId id, uint256 probability) internal {
if (probability == 0) {
revert Proofs_InvalidProbability();
}
_slotStarts[id] = block.timestamp; _slotStarts[id] = block.timestamp;
_probabilities[id] = probability; _probabilities[id] = probability;
} }

View File

@ -299,5 +299,12 @@ describe("Proofs", function () {
await proofs.setSlotState(slotId, SlotState.Finished) await proofs.setSlotState(slotId, SlotState.Finished)
expect(await proofs.isProofRequired(slotId)).to.be.false expect(await proofs.isProofRequired(slotId)).to.be.false
}) })
it("is rejected when probability is 0", async function () {
const probability = 0
await expect(
proofs.startRequiringProofs(slotId, probability)
).to.be.revertedWith("Proofs_InvalidProbability")
})
}) })
}) })