diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 0f38754..d8c23ae 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -35,6 +35,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { error Marketplace_InvalidState(); error Marketplace_StartNotBeforeExpiry(); error Marketplace_SlotNotAcceptingProofs(); + error Marketplace_ProofNotSubmittedByHost(); error Marketplace_SlotIsFree(); error Marketplace_ReservationRequired(); error Marketplace_NothingToWithdraw(); @@ -208,12 +209,12 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { revert Marketplace_SlotNotFree(); } - _startRequiringProofs(slotId); - submitProof(slotId, proof); - slot.host = msg.sender; slot.filledAt = uint64(block.timestamp); + _startRequiringProofs(slotId); + submitProof(slotId, proof); + context.slotsFilled += 1; context.fundsToReturnToClient -= _slotPayout(requestId, slot.filledAt); @@ -321,6 +322,11 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { Groth16Proof calldata proof ) public requestIsKnown(_slots[id].requestId) { Slot storage slot = _slots[id]; + + if (msg.sender != slot.host) { + revert Marketplace_ProofNotSubmittedByHost(); + } + Request storage request = _requests[slot.requestId]; uint256[] memory pubSignals = new uint256[](3); pubSignals[0] = _challengeToFieldElement(getChallenge(id)); diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 073dcd4..f465c53 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -485,6 +485,13 @@ describe("Marketplace", function () { await marketplace.submitProof(slotId(slot), proof) }) + it("reverts when somebody other then host submit the proof", async function () { + switchAccount(host2) + await expect( + marketplace.submitProof(slotId(slot), proof) + ).to.be.revertedWith("Marketplace_ProofNotSubmittedByHost") + }) + it("converts first 31 bytes of challenge to field element", async function () { let challenge = arrayify(await marketplace.getChallenge(slotId(slot))) let truncated = challenge.slice(0, 31)