From cc0b2732adfa0f17aaa24bf6e591882b19cc84b7 Mon Sep 17 00:00:00 2001 From: r4bbit <445106+0x-r4bbit@users.noreply.github.com> Date: Fri, 23 Aug 2024 09:46:28 +0200 Subject: [PATCH] fix(Marketplace): ensure requests include ask with sufficient slots There is a missing check in `requestStorage()` on whether the `Request` contains an `Ask` where its `slots` is `> 0`. This allows for making storage request without slots. Not harmful but not a valid state of the system either. This commit adds that check and a test with batteries included. --- contracts/Marketplace.sol | 1 + test/Marketplace.test.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 4641854..21aa466 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -95,6 +95,7 @@ contract Marketplace is Proofs, StateRetrieval, Endian { request.expiry > 0 && request.expiry < request.ask.duration, "Expiry not in range" ); + require(request.ask.slots > 0, "Insufficient slots"); require( request.ask.maxSlotLoss <= request.ask.slots, "maxSlotLoss exceeds slots" diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 3ffff93..3b4f1a9 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -211,6 +211,13 @@ describe("Marketplace", function () { ) }) + it("is rejected with insufficient slots ", async function () { + request.ask.slots = 0 + await expect(marketplace.requestStorage(request)).to.be.revertedWith( + "Insufficient slots" + ) + }) + it("is rejected when maxSlotLoss exceeds slots", async function () { request.ask.maxSlotLoss = request.ask.slots + 1 await expect(marketplace.requestStorage(request)).to.be.revertedWith(