Closed Gauthamastro closed 1 year ago
The idea behind the Off-chain worker of the OCEX pallet is to keep the operator of the orderbook accountable by ensuring the periodic snapshot of user balances of every trading pair. The off-chain worker will loop through all the users and verify the balances. The enclaves will register new CIDs for each trading pair periodically which should be pinned by the off-chain workers. They can unpin the previous CID to conserve space
In this way, in case the fraud by the operator of the orderbook, the users can issue a dispatchable call that gets the latest balance from the last snapshot via off-chain workers and credit the user on-chain, hence the user is secured from operator fraud.
User story
OCEX pallet will allow enclave to store balance snapshots of each trading pair registered on-chain. The balance snapshots are stored in IPFS, and only the CIDs of those storages are stored in the OCEX Pallet.
Logic Flow
Enclave sends a vector of CIDs to the OCEX pallet --> Off-chain workers take these CIDs and pins the data locally on each full node registered with the OCEX pallet --> Off-chain workers check the integrity of the snapshot --> submits their vote of approval on the snapshot. --> once the OCEX pallet receives enough votes, CIDs are considered accepted.
If the operator of the exchange is found to be compromised, or blockchain is not receiving CIDs for a certain period of time or on-chain governance decides to do an emergency shutdown of the off-chain orderbook. The confirmed snapshots are used to recover user funds.
This feature lays the crux of the security of Polkadex Orderbook where user funds are secured by on-chain validators and not by the operator.
Implementation Details
The off-chain worker of the OCEX pallet will embed an IPFS node and track CIDs registered by Enclaves.