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
| Field | Type | Set by | What it is |
|---|---|---|---|
formId | Bytes<32> | deploy | SHA-256 of mitome:form: and the form's id |
ownerKey | JubjubPoint | deploy | The workspace key that signs owner actions |
checkerKeys | Vector<2, JubjubPoint> | deploy | Keys whose passes it accepts (Mitome's checker in the first) |
rulesHash | Bytes<32> | deploy | SHA-256 of the form's checks; all zeros for a form without checks |
opensAt, closesAt | Uint<64> | deploy | Unix seconds; 0 means no limit |
phase | OPEN, PAUSED, CLOSED | owner action | CLOSED is final |
receipts | Map<Field, Bytes<32>> | answers | Nullifier → the answer's one-time Ed25519 key |
count | Counter | answers | How many answers |
answerKeys | Set<Bytes<32>> | deploy, owner actions | The team's X25519 keys answers are sealed to (1 to 8) |
ownerNonce | Counter | owner actions | Stops a signed action being replayed |
drawn | Field | owner action | A 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)
| Witness | Holds |
|---|---|
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
| Circuit | Who calls it | Checks, in order (and the message if one fails) | Then |
|---|---|---|---|
submitChecked(answerKey) | the person | form 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 person | open, opened, not closed; the form has no checks ("This form requires a pass"); no receipt yet | records nullifier → answerKey, count + 1 |
setPhase(next, sig) | relayed | the workspace signed it ("Only the form owner can do this"); not closed for good | sets the phase |
addAnswerKey(key, sig) | relayed | signed; a usable key; not already there; fewer than 8 | adds it |
removeAnswerKey(key, sig) | relayed | signed; present; at least one stays | removes it |
recordDraw(fingerprint, sig) | relayed | signed; 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.
Why Midnight
Each form is its own Midnight contract. People prove they may answer, once, with a zero-knowledge proof made in their own browser, and pay nothing.
Proofs in the browser, no wallet
How a person's browser builds, proves and seals an answer to Midnight without a wallet, a proof server or tokens, and how Mitome pays for it.