feat: request duration limit

This commit is contained in:
Adam Uhlíř 2024-12-30 16:11:52 +01:00
parent dfab6102e7
commit 252a983558
No known key found for this signature in database
GPG Key ID: 1D17A9E81F76155B
7 changed files with 26 additions and 16 deletions

View File

@ -18,7 +18,8 @@ const DEFAULT_CONFIGURATION = {
},
reservations: {
maxReservations: 3
}
},
requestDurationLimit: 60*60*24*30 // 30 days
}
function loadConfiguration(name) {

View File

@ -15,5 +15,6 @@ module.exports = {
},
reservations: {
maxReservations: 3
}
},
requestDurationLimit: 60*60*24*30 // 30 days
}

View File

@ -7,6 +7,7 @@ struct MarketplaceConfig {
CollateralConfig collateral;
ProofConfig proofs;
SlotReservationsConfig reservations;
uint256 requestDurationLimit;
}
struct CollateralConfig {

View File

@ -11,7 +11,8 @@ contract FuzzMarketplace is Marketplace {
MarketplaceConfig(
CollateralConfig(10, 5, 3, 10),
ProofConfig(10, 5, 64, "", 67),
SlotReservationsConfig(20)
SlotReservationsConfig(20),
60 * 60 * 24 * 30 // 30 days
),
new TestToken(),
new TestVerifier()

View File

@ -62,30 +62,23 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
}
constructor(
MarketplaceConfig memory configuration,
MarketplaceConfig memory conf,
IERC20 token_,
IGroth16Verifier verifier
)
SlotReservations(configuration.reservations)
Proofs(configuration.proofs, verifier)
{
) SlotReservations(conf.reservations) Proofs(conf.proofs, verifier) {
_token = token_;
require(
configuration.collateral.repairRewardPercentage <= 100,
conf.collateral.repairRewardPercentage <= 100,
"Must be less than 100"
);
require(conf.collateral.slashPercentage <= 100, "Must be less than 100");
require(
configuration.collateral.slashPercentage <= 100,
"Must be less than 100"
);
require(
configuration.collateral.maxNumberOfSlashes *
configuration.collateral.slashPercentage <=
conf.collateral.maxNumberOfSlashes * conf.collateral.slashPercentage <=
100,
"Maximum slashing exceeds 100%"
);
_config = configuration;
_config = conf;
}
function configuration() public view returns (MarketplaceConfig memory) {
@ -105,6 +98,10 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
request.expiry > 0 && request.expiry < request.ask.duration,
"Expiry not in range"
);
require(
request.ask.duration <= _config.requestDurationLimit,
"Duration exceeds limit"
);
require(request.ask.slots > 0, "Insufficient slots");
require(
request.ask.maxSlotLoss <= request.ask.slots,

View File

@ -189,6 +189,14 @@ describe("Marketplace", function () {
)
})
it("rejects request with duration exceeding limit", async function () {
request.ask.duration = config.requestDurationLimit + 1
await token.approve(marketplace.address, maxPrice(request))
await expect(marketplace.requestStorage(request)).to.be.revertedWith(
"Duration exceeds limit"
)
})
it("rejects request with insufficient payment", async function () {
let insufficient = maxPrice(request) - 1
await token.approve(marketplace.address, insufficient)

View File

@ -19,6 +19,7 @@ const exampleConfiguration = () => ({
reservations: {
maxReservations: 3,
},
requestDurationLimit: 60 * 60 * 24 * 30, // 30 days
})
const exampleRequest = async () => {