Midnight

The form contract

form.compact, the Compact contract every form deploys: its public state, its circuits, and the checks each one makes.

packages/contract/contract/form.compact is written in Compact (language 0.28, compiler 0.36.1). Every form deploys its own copy. Everything in its ledger is public; "sealed" below means set once when it's deployed, not secret.

Public state

FieldTypeSet byWhat it is
formIdBytes<32>deploySHA-256 of mitome:form: and the form's id
ownerKeyJubjubPointdeployThe workspace key that signs owner actions
checkerKeysVector<2, JubjubPoint>deployKeys whose passes it accepts (Mitome's checker in the first)
rulesHashBytes<32>deploySHA-256 of the form's checks; all zeros for a form without checks
opensAt, closesAtUint<64>deployUnix seconds; 0 means no limit
phaseOPEN, PAUSED, CLOSEDowner actionCLOSED is final
receiptsMap<Field, Bytes<32>>answersNullifier → the answer's one-time Ed25519 key
countCounteranswersHow many answers
answerKeysSet<Bytes<32>>deploy, owner actionsThe team's X25519 keys answers are sealed to (1 to 8)
ownerNonceCounterowner actionsStops a signed action being replayed
drawnFieldowner actionA fair draw's sealed fingerprint; 0 until drawn, and only set once. See The fair draw

Two "answer keys" live here, and they're different: answerKeys are your team's encryption keys; each value in receipts is a one-time signing key made for one answer.

Private inputs (witnesses)

WitnessHolds
secretKey()The person's 32-byte secret for this form, made in and kept by their browser
pass()The checker's signature, the rules it covers, the checker's slot and a nullifier seed

Witness values are untrusted until the circuit checks them, and none of them is ever disclosed.

Circuits

CircuitWho calls itChecks, in order (and the message if one fails)Then
submitChecked(answerKey)the personform is open ("This form is not accepting answers"), has opened ("This form isn't open yet"), hasn't closed ("This form has closed"); the form has checks; the pass is for these rules ("This pass is for different rules"); the pass names a filled checker slot ("Unknown checker") and that checker signed it, verified in the circuit ("This pass is not valid"); no receipt yet ("You have already answered this form")records nullifier → answerKey, count + 1
submitOpen(answerKey)the personopen, opened, not closed; the form has no checks ("This form requires a pass"); no receipt yetrecords nullifier → answerKey, count + 1
setPhase(next, sig)relayedthe workspace signed it ("Only the form owner can do this"); not closed for goodsets the phase
addAnswerKey(key, sig)relayedsigned; a usable key; not already there; fewer than 8adds it
removeAnswerKey(key, sig)relayedsigned; present; at least one staysremoves it
recordDraw(fingerprint, sig)relayedsigned; the form has a closing time ("Only a form with a closing time can hold a draw") that has passed ("The draw happens after the form closes"); not drawn yet ("The draw is already recorded"); not a zero fingerprint ("Not a draw fingerprint")sets drawn

The pass is verified with Midnight's built-in jubjubSchnorrVerify over four fields: the contract's own address, the rules, the person's subject key, and the nullifier seed. Both checker slots are read and one is chosen inside the proof, so the chain never learns which checker vouched.

Owner actions are signed over the contract's address, the action, its value and the current ownerNonce, and the nonce goes up each time. No owner secret is a witness, so Mitome's server can prove and submit an action the workspace signed, but can't make one.

Pure helpers

subjectKey(secret) and nullifier(seed, instance) use transientHash (Poseidon) rather than SHA-256. One SHA-256 inside the answer circuit costs a 10.8 MB proving key; Poseidon brought the circuit from 23.5 MB and 55 s in the browser down to 4 MB and about 12 s. The trade-off: transientHash isn't promised to stay the same across compiler versions, so each form stays on the toolchain it was deployed with.

Tested

41 simulator tests cover deploy, every circuit's success and failure paths, open and close times, and the privacy rules: the person's secret, subject key and seed never appear in public state; answers from either checker slot look identical on chain; the same person's answers to two forms have unrelated nullifiers. Six more tests run on a real local network: deploy, a walletless answer paid by the sponsor, a proof sent 30 seconds after it was made, a stale proof rebuilt, two answers at once, and how often proofs go stale. CI compiles the contract and runs the simulator tests on every push to main and every pull request.

On this page