From 38411c27ca595a8f6bce9ef6b76714cf4090d10c Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 18 Jan 2024 14:09:36 +0100 Subject: [PATCH] Move submitProof() function to Marketplace --- contracts/Marketplace.sol | 4 ++++ contracts/Proofs.sol | 2 +- contracts/TestProofs.sol | 4 ++++ test/Proofs.test.js | 22 +++++++++++----------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 2fd431d..1723bc0 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -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); diff --git a/contracts/Proofs.sol b/contracts/Proofs.sol index 4c3b34f..f30ae8a 100644 --- a/contracts/Proofs.sol +++ b/contracts/Proofs.sol @@ -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: diff --git a/contracts/TestProofs.sol b/contracts/TestProofs.sol index b0b4500..36676aa 100644 --- a/contracts/TestProofs.sol +++ b/contracts/TestProofs.sol @@ -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; } diff --git a/test/Proofs.test.js b/test/Proofs.test.js index c67d85d..82eeb1d 100644 --- a/test/Proofs.test.js +++ b/test/Proofs.test.js @@ -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") })