Commitments
A commitment is the only thing an order puts on-chain while the batch takes orders.
bytes32 commitment = keccak256(abi.encode(
trader, // address, msg.sender at commit and reveal
batch, // uint256, the batch you are committing into
market, // uint256, market id
side, // uint8, 0 buy, 1 sell
amount, // uint256, USDG for a buy, shares for a sell, raw units
limitPx, // uint256, USDG raw per 1e18 share raw
salt // bytes32, 32 random bytes
));
Why each field is there
- trader so a commitment copied from the mempool cannot be revealed by anyone else.
- batch so it cannot be carried into a later batch at a better moment.
- salt because the rest of the order has few possible values. Without 32 random bytes, a watcher could hash every plausible market, side and round size and find yours. The app generates the salt with the browser's cryptographic random source and never sends it anywhere.
Keep the salt
If you lose the salt you cannot reveal, and the bond is forfeited at the end of the batch. The app keeps the preimage in your browser's storage and offers it as a file.
Limits
- 8 commitments per trader per batch.
- The commit bond is fixed at 1 USDG and is taken from free USDG, whatever the order's side. A seller needs a little USDG too, which is exactly what keeps buyers and sellers indistinguishable at commit time.