voidcashdocs

The transact circuit

The one zero-knowledge circuit behind every private spend - its inputs, constraints, public inputs, ExtData binding, sizes and toolchain.

Every private spend, whether a send, an exit, a payment link or its claim, is one proof of the transact circuit (circuits/crates/transact). It spends three notes and creates four, in three groups:

GroupInputsOutputsAssetWhat may leave
Main pairin[0], in[1]out[0], out[1]One private asset: HYPE or a listed tokenexit_shares of asset
Fee pairin[2]out[2]HYPEfee_shares of HYPE: a token operation's gas
Padout[3]HYPE, zero sharesNothing

The pad exists so that a transaction always inserts two pairs of leaves into the note tree. All three inputs are owned by one wallet key. The vault verifies the proof with an on-chain UltraHonk verifier.

Public inputs

In this exact order, the order PrivateVault._publicInputs builds (and the public view publicInputs(t) returns):

#Circuit nameContract fieldMeaning
0roott.rootA Merkle root the vault knows (isKnownRoot)
1-3nullifiers[3]t.nullifiersNullifiers of the three inputs: the main pair, then the fee note
4-7out_commitments[4]t.commitmentsCommitments of the four outputs: the main pair, the fee change, the pad
8exit_sharest.exitAmountBase units of exit_asset leaving the main pair
9exit_assetuint160(t.exitAsset)The asset leaving the main pair: 0 for HYPE, or when nothing leaves it
10fee_sharest.feeAmountWei of HYPE leaving the fee pair
11ext_data_hashextDataHash(t.ext)keccak256(abi.encode(ext)) mod p
12domain_hiHigh 128 bits of the vault's EIP-712 domain separator
13domain_loLow 128 bits of the domain separator

The vault computes ext_data_hash from the calldata and the domain halves from its own _domainSeparatorV4(); the prover does not choose them. The verifier's NUMBER_OF_PUBLIC_INPUTS constant is 22: these 14 plus the 8 field elements of the pairing-point object (PAIRING_POINTS_SIZE) that the proof itself carries.

Private inputs

NameTypeMeaning
assetFieldThe main pair's asset: 0 for HYPE, otherwise uint160(token)
in_nk[Field; 3]Nullifier key of each input. Index 0 and 1: the main pair; 2: the HYPE fee note
in_rho, in_r[Field; 3]Note secrets of each input
in_shares[Field; 3]Amount of each input, in its asset's base units
in_index[u32; 3]Leaf index of each input in its tree
in_path[[Field; 24]; 3]Merkle siblings of each input, bottom to top
out_stub[Field; 4]Stub of each output, H(opk, rho, r) of its owner. Index 3, the pad's, is free
out_shares[Field; 4]Amount of each output. out_shares[3] must be 0
pk_x, pk_y[u8; 32] eachThe owner's wallet key, uncompressed secp256k1, big-endian
signature[u8; 64]The wallet's Spend signature, `r

Constraints

The wallet key enters as four 128-bit limbs, x_hi, x_lo, y_hi, y_lo, taken big-endian from pk_x and pk_y.

Each note is hashed in its slot's asset, with asset_commitment (see Notes):

asset < 2^160
in_asset  = [asset, asset, 0]            0 = HYPE
out_asset = [asset, asset, 0, 0]

For each input i:

in_shares[i] < 2^120
in_index[i]  < 2^24
cm_i = asset_commitment(H(H(in_nk[i], x_hi, x_lo, y_hi, y_lo), in_rho[i], in_r[i]), in_shares[i], in_asset[i])
if in_shares[i] != 0:  merkle_root(cm_i, in_index[i], in_path[i]) == root
nullifiers[i] == H(2, in_nk[i], cm_i, in_index[i])

The three nullifiers are pairwise distinct. Without this, the same note given as in[0] and in[1] would count twice, and only the vault's own duplicate check would stop it.

For each output j:

out_shares[j] < 2^120
out_commitments[j] == asset_commitment(out_stub[j], out_shares[j], out_asset[j])
out_shares[3] == 0                                                   the pad carries nothing

Then conservation of value, per pair:

exit_shares < 2^120,  fee_shares < 2^120
in_shares[0] + in_shares[1] == out_shares[0] + out_shares[1] + exit_shares      main pair, in asset
in_shares[2]                == out_shares[2] + fee_shares                       fee pair, in HYPE

And the asset of what leaves:

if exit_shares != 0:  exit_asset == asset
else:                 exit_asset == 0

The 120-bit range checks make the sums unable to wrap the field: no sum of three amounts reaches 2^122, far below p. Without them an output of p - 1 could balance a larger second output. Every input is owned by the same wallet key, because one (pk_x, pk_y) enters every owner key. A zero-value input is a dummy and needs no membership, but its nullifier is still checked. Value cannot move between assets: the main pair balances in one asset and the fee pair in HYPE, and a token note can never hash as a HYPE note.

exit_asset does not reveal the asset of a private send, since nothing leaves the main pair. The circuit lets a HYPE main pair pay its gas from the fee pair too (fee_shares, with exit_shares = 0), as a token operation must: the SDK does so for a private HYPE send whenever the wallet holds a spare HYPE note, and such a send has the same public inputs as a token send. A HYPE send that pays its gas out of the main pair (exit_shares the gas fee, fee_shares = 0) is recognisable as HYPE.

Finally, the authorization:

transaction = H(root, nf0, nf1, nf2, cm0, cm1, cm2, cm3, exit_shares, exit_asset, fee_shares, ext_data_hash)
                                                                as 32 bytes, big-endian
struct_hash = keccak256(SPEND_TYPEHASH || transaction)          SPEND_TYPEHASH = keccak256("Spend(bytes32 transaction)")
domain_hi, domain_lo < 2^128
digest      = keccak256(0x19 || 0x01 || domain_hi (16 bytes) || domain_lo (16 bytes) || struct_hash)
ecdsa_secp256k1_verify(pk_x, pk_y, signature, digest) == true

This is the EIP-712 digest the wallet signed (see Keys). H is Poseidon2 over BN254 and merkle_root hashes the leaf up 24 levels, taking the sibling from in_path and the side from each bit of the index (see The note tree).

Checks outside the circuit

PrivateVault adds the checks that need chain state or calldata:

  • root is a known root: one of the last 64, or the final root of a full tree (UnknownRoot);
  • the three nullifiers differ and none is spent (DuplicateNullifier, NullifierAlreadySpent);
  • commitments and nullifiers are below p (NotAFieldElement), and exitAmount and feeAmount are below 2^120 (AmountTooLarge);
  • the HYPE leaving is feeAmount, plus exitAmount when exitAsset is 0, and ext.gasFee is at most that (FeeExceedsExit);
  • if HYPE leaves beyond the gas fee, ext.recipient is not zero (ZeroAddress);
  • for a token exit (exitAsset not 0): the token is listed (TokenNotListed), exitAmount is not zero (ZeroAmount), ext.recipient is not zero (ZeroAddress), and feeAmount == ext.gasFee (FeeAmountNotGasFee), so the HYPE side pays the gas and nothing else, and one operation never pays out two assets;
  • through transact: ext.caller is zero or the sender, never the vault (WrongCaller), and ext.gasFee is zero (GasFeeNotAllowed);
  • through validateUserOp: ext.caller is the vault (WrongCaller), the operation's call gas limit is at least the minimum in ext.data, and ext.gasFee covers the operation's maximum cost (GasFeeBelowCost). See Gas and ERC-4337.

An invalid proof reverts transact with InvalidProof. In validateUserOp it returns the ERC-4337 signature-failure code instead, and nothing is written.

ExtData

struct ExtData {
    address recipient;   // receives the exit, less the gas fee and the exit fee
    address caller;      // if non-zero, the only allowed submitter: the vault itself for ERC-4337
    uint256 gasFee;      // wei of HYPE leaving: the operation's gas (ERC-4337 only; zero for transact)
    bytes data;          // ERC-4337: abi.encode(minCallGasLimit)
    bytes ciphertext0;   // encrypted output note 0
    bytes ciphertext1;   // encrypted output note 1
    bytes ciphertext2;   // encrypted output note 2, the HYPE fee change
    bytes ciphertext3;   // encrypted output note 3, the pad
}

function extDataHash(ExtData memory ext) public pure returns (uint256) {
    return uint256(keccak256(abi.encode(ext))) % NoteHash.FIELD;
}

Everything in ExtData is bound to the proof and to the wallet's signature, so no submitter can change it:

FieldWhat binding it prevents
recipientRedirecting an exit
callerSubmitting an ERC-4337 proof some other way, for example straight to transact
gasFeeRaising the gas fee a user pays
dataLowering the minimum call gas, which would let a bundler starve the execution step that pays an exit
ciphertext0 to ciphertext3Replacing the encrypted notes, which would make them unfindable for their owners

Sizes

MeasureValue
Circuit size87,298 gates, in a domain of 2^17
ACIR2,144 opcodes
Public inputs14 field elements, 448 bytes
Proof9,152 bytes
A transact that verifies the real proof and updates stateabout 5.1M gas (5,139,206 for a token unshield in the end-to-end test)

The circuit grew by one Merkle path and two outputs and still fits 2^17, so the same reference string serves.

Measured numbers are listed with the rest in Constants.

Proof system and toolchain

ComponentVersionWhere it is pinned
nargo1.0.0circuits/scripts/toolchain.sh
bb (Barretenberg)5.2.1circuits/scripts/toolchain.sh
@noir-lang/noir_js1.0.0packages/sdk/package.json, packages/mcp/package.json
@aztec/bb.js5.2.1packages/sdk/package.json, packages/mcp/package.json
noir-lang/poseidonv0.3.0circuits/crates/*/Nargo.toml
noir-lang/keccak256v0.1.3circuits/crates/transact/Nargo.toml
Solidity (verifier)0.8.38, 10,000 optimizer runscontracts/foundry.toml

toolchain.sh downloads nargo and bb from their GitHub releases into circuits/.toolchain/bin and checks each download against its release SHA-256 digest; the versions are never resolved by bbup. The checks behind these versions are recorded in docs/elysium/dependency-check.md.

The proof system is UltraHonk. It needs no circuit-specific trusted setup: it uses Barretenberg's universal CRS (common reference string). The verifier is generated with the EVM target (bb write_vk -t evm, bb write_solidity_verifier -t evm): the zero-knowledge variant with a keccak transcript. It is deployed as HonkVerifier (0x29688590CA80928f8f0039334D9f723180cd482a):

Verifier constantValue
VK_HASH0x078b97d5f97a98f75ff6ba5ffddaf4f675624b082d2e489bce86ee88b3dbb39a
N, LOG_N131072 (2^17), 17
NUMBER_OF_PUBLIC_INPUTS22
NUM_SMALL_IPA_OPENING_CLAIMS5: the small-subgroup IPA also opens the grand sum at 1

HonkVerifier calls two linked libraries, RelationsLib and ZKTranscriptLib. The deploy scripts refuse a verifier source without NUM_SMALL_IPA_OPENING_CLAIMS = 5, or whose keccak256 differs from the pinned bb 5.2.1 output. Before the vault is deployed they check that the deployed verifier is the 10,000-run build of that source and that it accepts the repository's fixture proof.

Where proving happens

Proofs are built on the user's device. The app runs noir_js to solve the witness and bb.js (UltraHonkBackend, verifierTarget: "evm") to prove, in the browser, loading 2^17 CRS points. The page is cross-origin isolated (Cross-Origin-Opener-Policy: same-origin, Cross-Origin-Embedder-Policy: require-corp) so bb.js can use WebAssembly threads. The witness, which holds nk, the note secrets and the signature, never leaves the device.

The CRS files (g1_compressed.dat, g2.dat, grumpkin_g1_v2.dat) are served by the app itself from /crs. They match SHA-256 hashes pinned in apps/web/scripts/fetch-crs.mjs, which can re-check them. Otherwise bb.js would fetch them from Aztec's CDN, which would see the user's IP each time they prepare a private transaction.

The verifier is an immutable of the vault's implementation. A changed circuit needs a new verifier, and so a new implementation behind the same vault proxy; see The vault.

On this page