voidcashdocs

Notes, commitments and nullifiers

What a note contains, how its commitment and nullifier are computed, how notes are encrypted, and how a shield completes a note from its stub.

A note is a private amount of one asset owned by one key: HYPE, or an ERC-20 token the vault lists (today only VOID). The chain never sees a note: it stores only the note's commitment in the note tree, next to an encrypted copy of the note for its owner. Spending a note publishes its nullifier, which marks it spent without saying which commitment it was.

Structure

FieldTypeMeaning
opkfield elementOwner key, from the registry: H(nk, x_hi, x_lo, y_hi, y_lo). See Keys
rhofield elementRandom value chosen by the note's creator
rfield elementRandom blinding value
sharesbelow 2^120The note's amount in the asset's base units: wei of HYPE, or a token's smallest unit. The circuit calls it shares; one share is one base unit
asset0 or below 2^1600 for HYPE, otherwise the token's address as a number, uint160(token)

The app draws rho and r as 64 random bytes each, reduced mod p. To spend a note, its owner also needs the leaf index and the nullifier key nk, which are not part of the note.

Hashes

H is Poseidon2 over the BN254 scalar field, the sponge that Noir's Poseidon2::hash(inputs, inputs.len()) computes (noir-lang/poseidon v0.3.0). The circuit (circuits/crates/note), the vault (NoteHash.sol, through the hasher contract) and the SDK (hash.ts, through bb.js) use the same definitions.

p      = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001   (BN254 scalar field)

opk    = H(nk, x_hi, x_lo, y_hi, y_lo)    owner key: nk and the wallet key's four 128-bit limbs
stub   = H(opk, rho, r)
cm     = H(1, stub, shares)               HYPE note: 1 = DOMAIN_NOTE
cm     = H(3, stub, shares, asset)        token note: 3 = DOMAIN_ASSET_NOTE, asset = uint160(token)
nf     = H(2, nk, cm, index)              2 = DOMAIN_NULLIFIER, index = leaf index in its tree
node   = H(left, right)                   Merkle tree node

The leading constants 1, 2 and 3 are domain tags: they separate HYPE commitments, nullifiers and token commitments. A HYPE note keeps the three-input hash it had before tokens existed, so every note created before the vault's v2 upgrade stays valid. A token note hashes four inputs under its own tag, so it can never be read as a HYPE note or as a note of another token. The circuit's asset_commitment(stub, shares, asset) picks the hash: the HYPE one when asset is 0, the token one otherwise.

The vault computes the four-input hash through a separate contract, Poseidon2Hash4 (0xdf0EDcbbBBdd91ec58a7dBbc2b7457d553Aa2bc0), because the three-input hasher has no hash_4. The vault's constructor refuses a four-input hasher whose hash_4(1, 2, 3, 4) differs from Noir's value for the same inputs (WrongHasher).

The vault rejects a stub, commitment or nullifier that is not below p (NotAFieldElement), so no alias x + p can stand for a value already used. It rejects an amount of 2^120 wei or more (AmountTooLarge).

Shielded notes: completing a stub

shield(stub, ciphertext) is payable and takes only the stub. The owner chooses stub = H(opk, rho, r); the vault completes the commitment with the HYPE sent:

cm = H(1, stub, msg.value)

So the depositor commits to the owner and the secrets, and the amount comes from the transaction itself: a shield cannot create a note worth more than it paid. The vault emits Shielded(from, index, amount) and NoteAdded(index, cm, ciphertext) for the same leaf.

The app writes the amount into the ciphertext too. A wallet that decrypts a shielded note with an amount of 0 takes the amount from the Shielded event with the same transaction hash and leaf index instead, whatever the log order. Either way it accepts the note only if the recomputed commitment matches.

Who shielded (from) and how much is public. Which later spend consumed the note is not, because rho and r are secret. A shield can create a note for any keys: the app uses this to let anyone pay a private address with public HYPE.

Shielding a token

shieldToken(token, amount, stub, ciphertext) does the same for a listed token. The caller first approves the vault for amount; the vault pulls it with transferFrom and completes the commitment with the token's address:

cm = H(3, stub, amount, uint160(token))

The vault refuses the shield unless its balance of the token grew by exactly amount (TokenAmountMismatch), so a token that charges a fee on transfer cannot back a note with less than it claims. It emits TokenShielded(from, token, index, amount), NoteAdded(index, cm, ciphertext) and TokenBookUpdated. A wallet that decrypts a token shield's note with an amount of 0, or with no asset, takes them from the TokenShielded event with the same transaction hash and leaf index, and accepts the note only if the recomputed commitment matches.

shield and shieldToken are the only ways in. The vault's receive function accepts HYPE only from the EntryPoint, so a plain transfer of HYPE to the vault reverts. A token transferred to the vault directly creates no note.

Dummies

A transact always has exactly three inputs and four outputs:

SlotAssetRole
Inputs 0 and 1, outputs 0 and 1The main pair's asset, HYPE or a tokenThe value being moved
Input 2, output 2HYPEThe fee pair: a HYPE note that pays a token operation's gas, and its change
Output 3HYPEThe pad: a note of zero shares, so that a transaction inserts two pairs of leaves

Missing notes are dummies:

  • Dummy input: shares = 0, random nk, rho and r, index 0, owned by the same wallet key as the real input. A dummy in the main pair is hashed in the main pair's asset, a dummy fee input as HYPE. The circuit skips the membership check for a zero-value input, but still requires its nullifier to be H(2, nk, cm, 0). With a random nk the nullifier is unique, and on-chain it looks like any other.
  • Dummy output: a random stub with shares = 0, and 306 random bytes as its ciphertext.

A random ciphertext has the right length but can be told apart from a real one, whose first 32 bytes are an X25519 public key. In the main pair the app creates a dummy output only for an exit, which is public anyway; every other spend has two real outputs there. The pad is always a dummy. A token operation spends a real HYPE note in the fee pair and returns its change to the spender as a real note, and so does a private HYPE send when the wallet holds a spare HYPE note. A HYPE operation that pays its gas from the main pair (an exit, or a send without a spare note) has a dummy input and a dummy output in the fee pair.

All three nullifiers of a transaction must be different (DuplicateNullifier, checked by the vault and by the circuit) and unspent (NullifierAlreadySpent).

Encryption

Every note created by shield or transact carries a ciphertext for its owner, emitted in NoteAdded(index, commitment, ciphertext). The app encrypts to the owner's X25519 viewing key (packages/sdk/src/encryption.ts):

shared  = X25519(ephemeral secret, recipient view public key)
key     = HKDF-SHA256(ikm = shared, salt = ephemeral public key, info = "voidcash/v1/note-key", 32 bytes)
tag     = SHA-256(shared || "voidcash/v1/view-tag")[0]
nonce   = 24 random bytes
body    = XChaCha20-Poly1305(key, nonce).encrypt(rho || r || shares || asset || memo)
          rho, r, shares 32 bytes each, big-endian; asset 20 bytes (zero for HYPE); memo 117

ciphertext = ephemeral public key (32) || tag (1) || nonce (24) || body (96 + 20 + 117 + 16)   = 306 bytes
PartPurpose
Ephemeral public keyFresh for each note, so two notes to the same key share nothing visible
View tag (1 byte)Lets a wallet skip 255 of 256 foreign notes without trying to decrypt them
rho, r, sharesEverything needed to rebuild the note. opk is implied by the viewing key
Asset (20 bytes)The token's address, or zero for HYPE
Memo (117 bytes)In the sender's own change note, what the spend did. All zero in every other note

Every ciphertext the app writes is 306 bytes, HYPE notes and random dummies included, so the length never shows the asset. Ciphertexts written before the vault's v2 upgrade have no asset field and are 286 bytes: a wallet still decrypts them, as HYPE notes.

A wallet ignores a ciphertext of any other length, and accepts a decrypted note only if the commitment it recomputes with the decrypted asset, asset_commitment(H(opk, rho, r), shares, asset), equals the commitment in the event, so a bogus ciphertext cannot fake a note or claim another asset. The vault does not check ciphertexts. In a transact they are bound to the proof through extDataHash (see The circuit), so a bundler cannot swap them, but a sender can still put garbage in them. The recipient then cannot find that note.

The spend memo

Every spend creates a change note back to the spender, even when the change is zero, and its memo records the spend:

memo = kind (1) || address (20) || rho (32) || r (32) || shares (32)

kind 1  sent        address = the recipient; rho, r, shares = the recipient's note
kind 2  unshielded  address = the recipient of the exit; the rest zero
kind 3  retired     never written; kept so the other codes stay as they are
kind 4  link        address = the link key's address; nonce in place of rho; r zero; shares = the amount
kind 5  paid        address = a stand-in for a private address; rho, r, shares = the payee's note

The stand-in address of a private address is the last 20 bytes of keccak256(opk || viewKey), which names no account. Only the spender's viewing key opens the memo, so their history, rebuilt on any device from the signature, shows whom each spend paid. The recipient's note carries an all-zero memo of the same length: it learns nothing about the sender, and every output ciphertext on-chain has the same length.

In a send the recipient's note is the first output and the change note the second, so the recipient's note is the leaf just before the change note. The memo's amounts are in the asset of the change note that carries it, which is the asset sent. A token operation's fee change (output 2) carries no memo.

Payment links (kind 4) and private addresses (kind 5) hold HYPE only.

Two spends write no memo: claiming a payment link into one's own balance and collecting a private address. Both outputs of those go to the claimer's own keys.

Proof of payment

For a private send (kind 1), the memo holds the opening of the recipient's note. The sender can share it as a receipt:

voidcash-receipt-v1.{chainId}.{vault}.{txHash}.{index}.{recipient}.{rho}.{r}.{shares}[.{asset}]
                                                              rho, r, shares, asset in hex

A receipt for a token note carries the token as a tenth part. A HYPE receipt keeps the nine parts it always had, so receipts made before tokens existed verify as before.

Anyone can check it against the chain, as the app does at /verify:

The transaction's receipt holds a NoteAdded event from the vault at index.

The recipient's registered opk is read with keysOf(recipient) at the transaction's block.

asset_commitment(H(opk, rho, r), shares, asset) equals that event's commitment, with asset 0 when the receipt names none.

A valid receipt proves that the transaction created a note of shares base units of that asset owned by the recipient's registered key, and nothing else. Spending the note, or telling when it is spent, needs the recipient's nk.

Faerie gold and positional nullifiers

A faerie gold attack gives a recipient two notes that look valid but can only be spent once. If the nullifier depended only on the note's contents, a sender could create two notes with the same stub and amount. Both would have the same commitment and the same nullifier, and spending one would kill the other.

The nullifier binds the leaf index, nf = H(2, nk, cm, index). Two identical commitments at different leaves have different nullifiers, and both can be spent.

The circuit's index is the leaf index inside its tree (below 2^24), not an absolute position. A note that a sender deliberately re-creates with the same stub and amount at the same index of a later tree would share a nullifier with the first one. The wallet computes each note's nullifier and checks it against NullifierSpent events, so it shows such a note as spent once either copy is spent.

On this page