@@ -12,6 +12,25 @@ import "./Endian.sol";
12
12
import "./Groth16.sol " ;
13
13
14
14
contract Marketplace is Proofs , StateRetrieval , Endian {
15
+ error Marketplace_RepairRewardPercentageTooHigh ();
16
+ error Marketplace_SlashPercentageTooHigh ();
17
+ error Marketplace_MaximumSlashingTooHigh ();
18
+ error Marketplace_InvalidExpiry ();
19
+ error Marketplace_InvalidMaxSlotLoss ();
20
+ error Marketplace_InvalidClientAddress ();
21
+ error Marketplace_RequestAlreadyExists ();
22
+ error Marketplace_InvalidSlot ();
23
+ error Marketplace_SlotNotFree ();
24
+ error Marketplace_InvalidSlotHost ();
25
+ error Marketplace_AlreadyPaid ();
26
+ error Marketplace_TransferFailed ();
27
+ error Marketplace_UnknownRequest ();
28
+ error Marketplace_RequestNotYetTimedOut ();
29
+ error Marketplace_InvalidState ();
30
+ error Marketplace_StartNotBeforeExpiry ();
31
+ error Marketplace_SlotNotAcceptingProofs ();
32
+ error Marketplace_SlotIsFree ();
33
+
15
34
using EnumerableSet for EnumerableSet.Bytes32Set;
16
35
using Requests for Request;
17
36
@@ -61,20 +80,21 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
61
80
) Proofs (configuration.proofs, verifier) {
62
81
_token = token_;
63
82
64
- require (
65
- configuration.collateral.repairRewardPercentage <= 100 ,
66
- " Must be less than 100 "
67
- );
68
- require (
69
- configuration.collateral.slashPercentage <= 100 ,
70
- " Must be less than 100 "
71
- );
72
- require (
83
+ if (configuration.collateral.repairRewardPercentage > 100 ) {
84
+ revert Marketplace_RepairRewardPercentageTooHigh ();
85
+ }
86
+
87
+ if (configuration.collateral.slashPercentage > 100 ) {
88
+ revert Marketplace_SlashPercentageTooHigh ();
89
+ }
90
+
91
+ if (
73
92
configuration.collateral.maxNumberOfSlashes *
74
- configuration.collateral.slashPercentage <=
75
- 100 ,
76
- "Maximum slashing exceeds 100% "
77
- );
93
+ configuration.collateral.slashPercentage >
94
+ 100
95
+ ) {
96
+ revert Marketplace_MaximumSlashingTooHigh ();
97
+ }
78
98
_config = configuration;
79
99
}
80
100
@@ -87,18 +107,20 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
87
107
}
88
108
89
109
function requestStorage (Request calldata request ) public {
90
- require (request.client == msg .sender , "Invalid client address " );
110
+ if (request.client != msg .sender ) {
111
+ revert Marketplace_InvalidClientAddress ();
112
+ }
91
113
92
114
RequestId id = request.id ();
93
- require (_requests[id].client == address (0 ), " Request already exists " );
94
- require (
95
- request.expiry > 0 && request.expiry < request.ask.duration,
96
- " Expiry not in range "
97
- );
98
- require (
99
- request.ask.maxSlotLoss <= request.ask.slots,
100
- " maxSlotLoss exceeds slots "
101
- );
115
+ if (_requests[id].client != address (0 )) {
116
+ revert Marketplace_RequestAlreadyExists ();
117
+ }
118
+ if (request.expiry == 0 || request.expiry > request.ask.duration) {
119
+ revert Marketplace_InvalidExpiry ( );
120
+ }
121
+ if ( request.ask.maxSlotLoss > request.ask.slots) {
122
+ revert Marketplace_InvalidMaxSlotLoss ();
123
+ }
102
124
103
125
_requests[id] = request;
104
126
_requestContexts[id].endsAt = block .timestamp + request.ask.duration;
@@ -120,14 +142,18 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
120
142
Groth16Proof calldata proof
121
143
) public requestIsKnown (requestId) {
122
144
Request storage request = _requests[requestId];
123
- require (slotIndex < request.ask.slots, "Invalid slot " );
145
+ if (slotIndex >= request.ask.slots) {
146
+ revert Marketplace_InvalidSlot ();
147
+ }
124
148
125
149
SlotId slotId = Requests.slotId (requestId, slotIndex);
126
150
Slot storage slot = _slots[slotId];
127
151
slot.requestId = requestId;
128
152
slot.slotIndex = slotIndex;
129
153
130
- require (slotState (slotId) == SlotState.Free, "Slot is not free " );
154
+ if (slotState (slotId) != SlotState.Free) {
155
+ revert Marketplace_SlotNotFree ();
156
+ }
131
157
132
158
_startRequiringProofs (slotId, request.ask.proofProbability);
133
159
submitProof (slotId, proof);
@@ -160,9 +186,14 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
160
186
161
187
function freeSlot (SlotId slotId ) public slotIsNotFree (slotId) {
162
188
Slot storage slot = _slots[slotId];
163
- require (slot.host == msg .sender , "Slot filled by other host " );
189
+ if (slot.host != msg .sender ) {
190
+ revert Marketplace_InvalidSlotHost ();
191
+ }
192
+
164
193
SlotState state = slotState (slotId);
165
- require (state != SlotState.Paid, "Already paid " );
194
+ if (state == SlotState.Paid) {
195
+ revert Marketplace_AlreadyPaid ();
196
+ }
166
197
167
198
if (state == SlotState.Finished) {
168
199
_payoutSlot (slot.requestId, slotId);
@@ -209,7 +240,10 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
209
240
}
210
241
211
242
function markProofAsMissing (SlotId slotId , Period period ) public {
212
- require (slotState (slotId) == SlotState.Filled, "Slot not accepting proofs " );
243
+ if (slotState (slotId) != SlotState.Filled) {
244
+ revert Marketplace_SlotNotAcceptingProofs ();
245
+ }
246
+
213
247
_markProofAsMissing (slotId, period);
214
248
Slot storage slot = _slots[slotId];
215
249
Request storage request = _requests[slot.requestId];
@@ -296,13 +330,18 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
296
330
/// @param requestId the id of the request
297
331
function withdrawFunds (RequestId requestId ) public {
298
332
Request storage request = _requests[requestId];
299
- require (
300
- block .timestamp > requestExpiry (requestId),
301
- "Request not yet timed out "
302
- );
303
- require (request.client == msg .sender , "Invalid client address " );
333
+ if (block .timestamp <= requestExpiry (requestId)) {
334
+ revert Marketplace_RequestNotYetTimedOut ();
335
+ }
336
+
337
+ if (request.client != msg .sender ) {
338
+ revert Marketplace_InvalidClientAddress ();
339
+ }
340
+
304
341
RequestContext storage context = _requestContexts[requestId];
305
- require (context.state == RequestState.New, "Invalid state " );
342
+ if (context.state != RequestState.New) {
343
+ revert Marketplace_InvalidState ();
344
+ }
306
345
307
346
// Update request state to Cancelled. Handle in the withdraw transaction
308
347
// as there needs to be someone to pay for the gas to update the state
@@ -327,7 +366,10 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
327
366
}
328
367
329
368
modifier requestIsKnown (RequestId requestId ) {
330
- require (_requests[requestId].client != address (0 ), "Unknown request " );
369
+ if (_requests[requestId].client == address (0 )) {
370
+ revert Marketplace_UnknownRequest ();
371
+ }
372
+
331
373
_;
332
374
}
333
375
@@ -338,7 +380,9 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
338
380
}
339
381
340
382
modifier slotIsNotFree (SlotId slotId ) {
341
- require (_slots[slotId].state != SlotState.Free, "Slot is free " );
383
+ if (_slots[slotId].state == SlotState.Free) {
384
+ revert Marketplace_SlotIsFree ();
385
+ }
342
386
_;
343
387
}
344
388
@@ -362,11 +406,9 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
362
406
uint256 startingTimestamp
363
407
) private view returns (uint256 ) {
364
408
Request storage request = _requests[requestId];
365
- require (
366
- startingTimestamp < requestExpiry (requestId),
367
- "Start not before expiry "
368
- );
369
-
409
+ if (startingTimestamp >= requestExpiry (requestId)) {
410
+ revert Marketplace_StartNotBeforeExpiry ();
411
+ }
370
412
return (requestExpiry (requestId) - startingTimestamp) * request.ask.reward;
371
413
}
372
414
@@ -415,7 +457,9 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
415
457
416
458
function _transferFrom (address sender , uint256 amount ) internal {
417
459
address receiver = address (this );
418
- require (_token.transferFrom (sender, receiver, amount), "Transfer failed " );
460
+ if (! _token.transferFrom (sender, receiver, amount)) {
461
+ revert Marketplace_TransferFailed ();
462
+ }
419
463
}
420
464
421
465
event StorageRequested (RequestId requestId , Ask ask , uint256 expiry );
0 commit comments