fix: only slots host should be able to submit proof (#227)

* fix: only slots host should be able to submit proof

* chore: formatting
This commit is contained in:
Adam Uhlíř 2025-03-26 11:05:21 +01:00 committed by GitHub
parent 1982e71d52
commit 0bf138512b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View File

@ -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));

View File

@ -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)