Commit Graph

288 Commits

Author SHA1 Message Date
Mark Spanbroek 1af40f1790 Read proof from file in test 2024-01-25 13:08:10 +01:00
Mark Spanbroek bf64de7e50 Update to solidity 0.8.8 2024-01-25 13:08:10 +01:00
Mark Spanbroek 3e3f2307d8 Remove GPL'ed verifier, replace by MIT verifier 2024-01-25 13:08:10 +01:00
Mark Spanbroek e1657acdd0 Stub out zk proof verification in marketplace tests 2024-01-25 13:08:10 +01:00
Mark Spanbroek e59f0f961e Submit proofs as array of bytes 2024-01-25 13:08:10 +01:00
Mark Spanbroek d29a259090 Fix linter warnings 2024-01-25 13:08:10 +01:00
Mark Spanbroek 327ae14112 Formatting with prettier 2024-01-25 13:08:10 +01:00
Mark Spanbroek db124ddbd9 Re-arrange marketplace constructor parameters
first configuration, then contracts that we depend on
2024-01-25 13:08:10 +01:00
Adam Uhlíř 0d9b67bb31 feat: verifier integration 2024-01-25 13:08:10 +01:00
Eric b5f33992b6
Increase pointer by 67 blocks each time the period is increased (#75)
* Increase pointer by 67 instead of 64 for each period

Use a prime number to ensure that we don't get cycles
where we're looking at the same hash four periods
from now.

---------

Co-authored-by: Mark Spanbroek <mark@spanbroek.net>
2023-12-15 10:02:03 +11:00
Adam Uhlíř 87461f6b83
fix: check expiration is before request end (#77) 2023-12-05 11:18:43 +01:00
Mark Spanbroek b625f0d519 Merkle root is 32 bytes 2023-11-22 14:43:11 +01:00
Mark Spanbroek efafa43910 Remove PoR parameters, add merkle root for storage proofs 2023-11-22 14:43:11 +01:00
Adam Uhlíř 14e453ac31
feat: partial payouts for cancelled requests (#69) 2023-10-16 11:14:02 +02:00
Eric Mastro 230e7276e2
Support slot queue (#61)
* feat: add request expiry to StorageRequested event

* add slot index to SlotFreed event

* copy slotIndex before delete for emit

* Update tests
2023-06-22 06:18:33 +10:00
Mark Spanbroek a7dd840eaa [fuzzing] transfers out of the contract should always pass
When a transfer of tokens from the contract fails, then the
fuzzer has found a bug. Changing `require` to `assert`
ensures that the fuzzer considers this a test failure.
2023-06-19 14:58:47 +02:00
Mark Spanbroek 03e5546121 [marketplace] formatting 2023-06-19 14:58:47 +02:00
Mark Spanbroek 3390e21071 [fuzzing] Enable fuzzing for Marketplace
Replaces runtime invariant checks with fuzzing tests,
simplifying the contract code and lowering gas costs.
2023-06-19 14:58:47 +02:00
Slava 7b7773c436
Update links to codex-storage organization (#55) 2023-05-25 12:56:04 +03:00
Eric Mastro 6e66abbfcd
retreive active slot for sales state restoration (#51)
Store slotIndex in slot struct and expose the slot via getActiveSlot. This is to be used when restoring state in the sales module after a node restart.
2023-04-14 09:28:39 +10:00
Adam Uhlíř 2b5d079882
feat: collateral fractions (#47)
Co-authored-by: Eric Mastro <github@egonat.me>
2023-03-30 11:11:21 +02:00
Adam Uhlíř 8b39ef8f4a
fix: reset missed counter when slot is freed (#48) 2023-03-08 17:19:49 +01:00
Adam Uhlíř dfdbd16d5b
feat: collateral per slot (#44) 2023-03-08 12:02:34 +01:00
Mark Spanbroek c9b51695aa [proofs] support probability 1 (proofs always required) 2023-01-30 14:47:37 +01:00
Eric Mastro cde5436262
get request from slot id (#34)
* get request from slot id

- Add public function to get request from slot id.
- Add chai test assertion that compares requests. Usage: `expect(await marketplace.getRequestFromSlotId(slotId(slot))).to.be.request(request)`

This is used when restoring active sales, and a node calls `mySlots`, then iterates the slots and needs originating request details.

* merge upstream changes
2023-01-24 15:59:56 +11:00
Mark Spanbroek be38c54622 [style] enforce `_` prefix for private names
Co-authored-by: Eric Mastro <eric.mastro@gmail.com>
2023-01-23 15:10:23 +01:00
Mark Spanbroek b3855c4ba3 [style] Use _ for private and internal functions
Co-authored-by: Eric Mastro <eric.mastro@gmail.com>
2023-01-23 15:10:23 +01:00
Mark Spanbroek 3bb077db7a [marketplace] reordering
Co-authored-by: Eric Mastro <eric.mastro@gmail.com>
2023-01-23 15:10:23 +01:00
Mark Spanbroek b62eeb564a [marketplace] test & fix slotState() 2023-01-23 15:10:23 +01:00
Mark Spanbroek ae70fd7c6f [marketplace] introduce MarketplaceConfiguration struct
Container for all configuration values, replaces separate
constructor parameters and getters.
2023-01-23 15:10:23 +01:00
Mark Spanbroek 2dbdd0028d [marketplace] move price calculations to Requests.sol 2023-01-23 15:10:23 +01:00
Mark Spanbroek 7aa162b526 [marketplace] move proofPeriod() getter to Proofs.sol 2023-01-23 15:10:23 +01:00
Mark Spanbroek 8c6891f1e2 [marketplace] slotIsNotFree() modifier
Replaces _slot getter
2023-01-23 15:10:23 +01:00
Mark Spanbroek 944e9c9da2 [marketplace] requestIsKnown() modifier
Replaces _request() getter
2023-01-23 15:10:23 +01:00
Mark Spanbroek 6eab9fee9a [marketplace] remove wrappers around proof functions
No longer required; slot state is checked in Proofs.sol
2023-01-23 15:10:23 +01:00
Mark Spanbroek 55ef97687e [proofs] Remove outdated comment 2023-01-23 15:10:23 +01:00
Mark Spanbroek 97af6f7484 [marketplace] remove dead code 2023-01-23 15:10:23 +01:00
Mark Spanbroek 32b137a427 [marketplace] inline _context() 2023-01-23 15:10:23 +01:00
Mark Spanbroek e828529e90 [marketplace] inline the requestAcceptsProofs() function
It was only used in one place
2023-01-23 15:10:23 +01:00
Mark Spanbroek 1316682a6f [marketplace] remove slotMustAcceptProofs modifier
Replaced by checks on slot state
2023-01-23 15:10:23 +01:00
Mark Spanbroek 7d377a3739 [marketplace] remove requestMustAcceptProofs modifier
Is already covered by the slot state check later on
2023-01-23 15:10:23 +01:00
Mark Spanbroek dd65133576 [marketplace] replace Slot.hostPaid with SlotState.Paid 2023-01-23 15:10:23 +01:00
Mark Spanbroek c8dda37300 [marketplace] introduce SlotState
- replace proofEnd() by slotState()
- replace _slotAcceptsProofs() by slotState()
- remove _stopRequiringProofs()
2023-01-23 15:10:23 +01:00
Mark Spanbroek de0595edb3 [marketplace] rename state(id) -> requestState(id) 2023-01-23 15:10:23 +01:00
Mark Spanbroek 10f88a62a7 [marketplace] Move RequestState enum to Requests.sol 2023-01-23 15:10:23 +01:00
Mark Spanbroek bb0302afcb [marketplace] inline function _notEqual 2023-01-23 15:10:23 +01:00
Mark Spanbroek e496ac3550 [marketplace] remove _isCancelled and _isFinished 2023-01-23 15:10:23 +01:00
Mark Spanbroek 9aa4773392 [marketplace] remove unused _isSlotCancelled() 2023-01-23 15:10:23 +01:00
Mark Spanbroek fffd0dcb86 [marketplace] remove dead code 2023-01-23 15:10:23 +01:00
Mark Spanbroek de368708b2 [marketplace, proofs] simplify proofTimeout getter 2023-01-23 15:10:23 +01:00
Mark Spanbroek 6aa76257f8 [Marketplace] Move `slotId()` to `Requests` library
Co-authored-by: Eric Mastro <eric.mastro@gmail.com>
2023-01-12 13:57:44 +01:00
Mark Spanbroek 07e9043b30 [Marketplace] Remove dead code
Co-authored-by: Eric Mastro <eric.mastro@gmail.com>
2023-01-12 13:57:44 +01:00
Mark Spanbroek 2bfed21584 [Marketplace] Extract myRequests() and mySlots() 2023-01-12 13:57:44 +01:00
Mark Spanbroek af08a72d7d Fix: use slot start instead of request start
Proofs should be required from the moment a slot is filled,
not from the moment a request is submitted.

This reverts commit f224cb8eda.
2023-01-12 13:49:08 +01:00
Mark Spanbroek ad155be5a1 [Proofs] Extract period related types and function 2023-01-11 10:32:58 +01:00
Mark Spanbroek c0690cd5d1 [Proofs] rename expectProofs -> startRequiringProofs 2023-01-11 10:27:08 +01:00
Mark Spanbroek f224cb8eda [Proofs] Remove double administration of request start
The timestamp when proofs start to be required was
stored in both the Marketplace and Proofs. It is now
only stored in the Marketplace.
2023-01-11 10:27:08 +01:00
Mark Spanbroek 527c21e103 [Proofs] Remove dead code 2023-01-11 10:27:08 +01:00
Mark Spanbroek f8e9f3c848 [Proofs] Remove double administration of request end
The timestamp when proofs no longer are required was
stored in both the Marketplace and Proofs. It is now
only stored in the Marketplace.
2023-01-11 10:27:08 +01:00
Mark Spanbroek 19f93500ea [Marketplace] Combine host getters
Co-authored-by: Eric Mastro <eric.mastro@gmail.com>
2023-01-11 10:27:08 +01:00
Mark Spanbroek ce335d0568 [Proofs] Improved naming
Co-authored-by: Eric Mastro <eric.mastro@gmail.com>
2023-01-10 12:15:22 +01:00
Mark Spanbroek afad73d588 [Markeplace] Linting 2023-01-10 12:15:22 +01:00
Mark Spanbroek afb89c9233 [Storage] Remove Storage
Rationale: it was already a very thin wrapper
around Marketplace, and now that its remaining
functionality has been moved to Proofs and
Marketplace, we no longer need it.
2023-01-10 12:15:22 +01:00
Mark Spanbroek 6ea2b77a8f [Storage] Move markProofAsMissing() to Marketplace 2023-01-10 12:15:22 +01:00
Mark Spanbroek a7397981bb [Collateral] Inline slashAmount() function 2023-01-10 12:15:22 +01:00
Mark Spanbroek 39da450c2a [Storage] Move submitProof() to Proofs 2023-01-10 12:15:22 +01:00
Mark Spanbroek 31d109f0d3 [Storage] Move isProofRequired() et al to Marketplace 2023-01-10 12:15:22 +01:00
Mark Spanbroek c9cf47f327 [Storage] Move missingProofs() to Proofs 2023-01-10 12:15:22 +01:00
Mark Spanbroek d5d99515fc [Proofs] Remove ProofId and EndId, use SlotId and RequestId
Rationale: in practice, a ProofId was always a slot id, and
an EndId was always a request id. Now that the definitons
of SlotId and RequestId are separated from the Marketplace,
we can import and use them.
2023-01-10 12:15:22 +01:00
Mark Spanbroek 27ccb1e2bc [Marketplace] Extract Request struct into separate file 2023-01-10 12:15:22 +01:00
Mark Spanbroek ac98689892 [Storage] Remove getSlot()
Rationale: Slot is struct that is used by the contract
to keep track of the state of a slot, it doesn't need
to be exposed on the API
2023-01-10 12:15:22 +01:00
Mark Spanbroek 9b8bcc0bc7 [Storage] Move getRequest() and getHost() to Marketplace 2023-01-10 12:15:22 +01:00
Mark Spanbroek 71656f6a95 [collateral] Remove AccountLocks
AccountLocks is replaced by the isWithDrawAllowed()
implementation in Marketplace.
2022-12-22 10:29:06 +01:00
Mark Spanbroek d5d4dba442 [marketplace] Add missing tests for freeSlot()
Removes unnecessary double removal from slotsPerHost.
2022-12-22 10:29:06 +01:00
Mark Spanbroek 0ecce3094a [utils] Remove Utils
No longer required
2022-12-22 10:29:06 +01:00
Mark Spanbroek 4f75159e02 [marketplace] Slots of failed request remain in mySlots()
Until hosts calls freeSlot()
2022-12-22 10:29:06 +01:00
Mark Spanbroek a7be363f04 [marketplace] Unlock collateral when list of slots is empty 2022-12-22 10:29:06 +01:00
Mark Spanbroek c46c268880 [marketplace] freeSlot() can be called by host
Handles payout, slashing and removal from mySlots
2022-12-22 10:29:06 +01:00
Mark Spanbroek 6c52f60381 [marketplace] Formatting 2022-12-22 10:29:06 +01:00
Mark Spanbroek 6e0dfdf7db [marketplace] Rename _freeSlot() -> _forciblyFreeSlot() 2022-12-22 10:29:06 +01:00
Mark Spanbroek a96333ce5f [marketplace] mySlots() returns slots of cancelled request
Reasoning: the node will want to call payoutSlot() for
cancelled requests, at which point it will be removed
from the list.
2022-12-22 10:29:06 +01:00
Mark Spanbroek 3fbc851a8d [marketplace] Cleanup 2022-12-22 10:29:06 +01:00
Mark Spanbroek a19e3f4198 [marketplace] Remove SetMap
No longer needed
2022-12-22 10:29:06 +01:00
Mark Spanbroek 0f6eb306ea [marketplace] Remove resize()
No longer needed
2022-12-22 10:29:06 +01:00
Mark Spanbroek c832dfbb7c [marketplace] Simplify myRequests() 2022-12-22 10:29:06 +01:00
Mark Spanbroek c0a1e11b87 [marketplace] replace mySlots(requestId) by mySlots()
Allows a host to get all slots that it participates in
in a single call.
2022-12-22 10:29:06 +01:00
Eric Mastro 7f59e545b2 Add more tests
- Marketplace tests for requestsForHost, and additional tests for myRequests and mySlots
- Added Utils lib with tests
- Added additional Bytes32AddressSetMap.keys expectations
2022-12-22 10:29:06 +01:00
Eric Mastro 429b9034d8 Add SetMap tests 2022-12-22 10:29:06 +01:00
Eric Mastro b08169198a rename AddressSetMap to Bytes32AddressSetMap 2022-12-22 10:29:06 +01:00
Eric Mastro f6991d6933 add Bytes32AddressSetMap for active requests by host
Add `Bytes32AddressSetMap` which maps addresses to a requestId. This is used in `Marketplace.activeRequestsForHost`, where all addresses for a particular requestId are listed. This can then be used to iterate and list out the actives requests for a particular address in a view function only. This allows for all addresses for a request to be cleared in situations such as when a request fails or is cancelled.
2022-12-22 10:29:06 +01:00
Eric Mastro eebf3a0709 Add SetMap type for mapping all requests 2022-12-22 10:29:06 +01:00
Eric Mastro 81dd4c203f add ability to get all requests 2022-12-22 10:29:06 +01:00
Eric Mastro 6397835635 switch to a lib, and generalise the api 2022-12-22 10:29:06 +01:00
Eric Mastro 20111c2ec1 move activeslots to separate contract 2022-12-22 10:29:06 +01:00
Eric Mastro 74c2d91b69 PR comments
- remove ActiveSlotId type and instead use an additional mapping for readability
- simplify _activeSlotsForHost for readability
2022-12-22 10:29:06 +01:00
Eric Mastro a99827ed39 Reinstate mapping index, add ActiveSlotId
Reinstate the index mapping for `activeSlots`, however with a modified data structure. The main difference comes from a change in `mySlots`: it now requires a `RequestId` as a parameter (which can be obtained using `myRequests`. This allowed for the `activeSlots` mapping to be keyed on `RequestId`, which gives a mapping of `ActiveSlotId => EnumerableSet.Bytes32`. `ActiveSlotId` is a keccak hash of `address + activeSlotIdx`, which not only allows retrieval of all active slot ids per request, but also allows clearing of all active slot ids for a request by incrementing the `activeSlotIdx`.
```
requestId => [ keccak(address + activeSlotIdx) => EnumerableSet.Bytes32 ]
```
2022-12-22 10:29:06 +01:00
Eric Mastro 5f056b055a Revert mapping index for clearing active slots
Instead, iterate all active slots and remove them individually, only if they are part of a specific request. This is only for the case of request failure.
2022-12-22 10:29:06 +01:00
Eric Mastro 48eba1fe27 Clear active slots by host
Allow for clearing of active slots by host, by incrementing an mapping index. The new index points to a fresh instance of EnumerableSet, effectively wiping it clean.
2022-12-22 10:29:06 +01:00
Eric Mastro b2de745d9a add tests for active slots 2022-12-22 10:29:06 +01:00
Eric Mastro 5b6187afc4 list active sales 2022-12-22 10:29:06 +01:00