Move submitProof() function to Marketplace

This commit is contained in:
Mark Spanbroek 2024-01-18 14:09:36 +01:00 committed by markspanbroek
parent e6a918fed9
commit 38411c27ca
4 changed files with 20 additions and 12 deletions

View File

@ -159,6 +159,10 @@ contract Marketplace is Proofs, StateRetrieval {
}
}
function submitProof(SlotId id, Groth16Proof calldata proof) public {
_proofReceived(id, proof);
}
function markProofAsMissing(SlotId slotId, Period period) public {
require(slotState(slotId) == SlotState.Filled, "Slot not accepting proofs");
_markProofAsMissing(slotId, period);

View File

@ -109,7 +109,7 @@ abstract contract Proofs is Periods {
return isRequired && pointer < _config.downtime;
}
function submitProof(SlotId id, Groth16Proof calldata proof) public {
function _proofReceived(SlotId id, Groth16Proof calldata proof) internal {
require(!_received[id][_blockPeriod()], "Proof already submitted");
// TODO: The `pubSignals` should be constructed from information that we already know:

View File

@ -24,6 +24,10 @@ contract TestProofs is Proofs {
_markProofAsMissing(id, period);
}
function proofReceived(SlotId id, Groth16Proof calldata proof) public {
_proofReceived(id, proof);
}
function setSlotState(SlotId id, SlotState state) public {
_states[id] = state;
}

View File

@ -200,25 +200,25 @@ describe("Proofs", function () {
expect(challenge1 === challenge2 && challenge2 === challenge3).to.be.false
})
it("submits a correct proof", async function () {
await proofs.submitProof(slotId, proof)
it("handles a correct proof", async function () {
await proofs.proofReceived(slotId, proof)
})
it("fails proof submission when proof is incorrect", async function () {
let invalid = exampleProof()
await expect(proofs.submitProof(slotId, invalid)).to.be.reverted
await expect(proofs.proofReceived(slotId, invalid)).to.be.reverted
})
it("emits an event when proof was submitted", async function () {
await expect(proofs.submitProof(slotId, proof))
await expect(proofs.proofReceived(slotId, proof))
.to.emit(proofs, "ProofSubmitted")
.withArgs(slotId)
})
it("fails proof submission when already submitted", async function () {
await advanceTimeToForNextBlock(periodEnd(periodOf(await currentTime())))
await proofs.submitProof(slotId, proof)
await expect(proofs.submitProof(slotId, proof)).to.be.revertedWith(
await proofs.proofReceived(slotId, proof)
await expect(proofs.proofReceived(slotId, proof)).to.be.revertedWith(
"Proof already submitted"
)
})
@ -250,14 +250,14 @@ describe("Proofs", function () {
).to.be.revertedWith("Validation timed out")
})
it("does not mark a submitted proof as missing", async function () {
it("does not mark a received proof as missing", async function () {
await waitUntilProofIsRequired(slotId)
let submittedPeriod = periodOf(await currentTime())
await proofs.submitProof(slotId, proof)
await advanceTimeToForNextBlock(periodEnd(submittedPeriod))
let receivedPeriod = periodOf(await currentTime())
await proofs.proofReceived(slotId, proof)
await advanceTimeToForNextBlock(periodEnd(receivedPeriod))
await mine()
await expect(
proofs.markProofAsMissing(slotId, submittedPeriod)
proofs.markProofAsMissing(slotId, receivedPeriod)
).to.be.revertedWith("Proof was submitted, not missing")
})