How a position becomes a note
The rule
A position on Gyges is a note: a Poseidon hash stored in a Merkle tree on Elysium. Its size, side, entry and liquidation price never appear on chain. What the chain keeps is the commitment, a nullifier when the note is spent, the signed mark the transaction used, your encrypted copy of the note and the risk engine's encrypted copy.
What is inside a note
The note is the tuple below. Prices are integers with six decimals, sizes with eight, USDC with six. nf is fresh randomness that becomes the nullifier when the note is spent; secret stays in your browser. The label is the deposit label the association set screens, and it follows the money from deposit to payout.
position = Poseidon8(market, side, size, entry, margin,
fundingIdx, label, owner)
owner = Poseidon2(nf, Poseidon2(secret, 0))
cash note = Poseidon2(Poseidon2(amount, label),
Poseidon2(nullifier, secret))The engine's copy of a position carries Poseidon2(secret, 0) but not secret: it can prove a liquidation, and it cannot close your position or take its payout.
Open
Opening spends a margin note and creates a position note. Your browser builds the Groth16 proof with snarkjs. Public inputs are the Merkle root, the nullifier of the margin note, the new commitment, the signed mark, the hash of your copy, the engine's key and the engine's copy of the note. The whole margin note becomes the position's margin. The circuit checks that the entry is the signed mark, that leverage is at most 5x and that the notional is at most the per-position cap.
Close
Closing proves ownership of a position note, takes a signed mark at most 10 seconds old and the current funding index, and creates a payout note worth margin + PnL - funding - fee, never below zero. The fee is the opening fee, 0.06% of the entry notional, settled here. The circuit has no witness for any other amount. The payout amount is hidden; only the book's aggregate liability moves.
Ciphertexts
Each position is encrypted twice. Your copy is sealed in your browser to your view key: a fresh X25519 key per note, HKDF-SHA256 into a key for that one note, then XChaCha20-Poly1305. It holds the note's fields with Poseidon2(secret, 0), never secret, so it can show and prove a position but not close it. A close adds a sealed copy of the payout note: value, label and Poseidon2(nullifier, secret). Both copies are bound to the proof by hash and stored in the Opened and Closed events.
The engine's copy is encrypted inside the open proof. The circuit does an ECDH on BabyJubJub between a fresh ephemeral key and the engine's key, then encrypts nine fields with the Poseidon cipher: market, side, size, entry, margin, funding index, label, nf and Poseidon2(secret, 0). The result goes on chain in the Opened event as twelve field elements: the ephemeral key (2) and the ciphertext (10).
shared = esk * engineKey (BabyJubJub)
ephKey = esk * Base8
engineCt = PoseidonEncrypt(fields, shared, nonce 0)
engineNote = [ephKey.x, ephKey.y, engineCt[0..9]]The engine's key is fixed in GygesBook at deploy (engineKeyX, engineKeyY), and the contract puts it into every proof itself. An open proof only exists if the engine's copy decrypts with that key to exactly the committed note, so nobody can open a position the engine cannot read.