Docs · Reference
Circuits and their public inputs
The 26 Groth16 circuits of the mesa program: which instruction verifies each, the notes it spends and creates, what it proves, its public inputs in order and its constraint count.
Every Mesa instruction that moves notes verifies a proof from one of 26 circuits. This page lists each circuit for someone who generates Mesa proofs or checks them. The instructions that carry the proofs are in Program instructions.
What a Mesa proof is
An instruction that moves notes carries two Groth16 proofs over BN254.
- The Mesa proof proves the rule of the action: who may spend the notes going in, and what every Mesa note coming out must hold. The
mesaprogram verifies it against the verifying key of the circuit the instruction selects. - The pool's proof is the Solana Privacy Program's own. It proves that the spent notes exist in the state tree, that their nullifiers are correct, and that value is conserved per asset. The Privacy Program verifies it when
mesacallstransactby CPI, signed by the Mesa authority.
The Mesa proof is 128 bytes in the instruction's arguments: a 32 bytes, b 64 and c 32, each a compressed point. The pool's proof is 192 bytes and travels inside the transact data that mesa forwards unchanged.
Both proofs bind the same transaction. The transact data carries a private transaction hash that commits to the notes spent and created. The program combines it with the public transfers it builds itself into one transaction hash, and that hash goes into the Mesa proof's public input. A Mesa proof therefore verifies only together with the exact notes and public transfers it was made for.
A public transfer is a leg of the Privacy Program's transact that moves an amount between a note and one of the Mesa authority's token accounts. A withdraw leg takes value out of a note into a token account, and a deposit leg puts value from a token account into a note. The program derives each leg's mint, token account and amount from its own accounts, so the prover cannot choose them.
How public inputs reach the verifier
Each circuit has one public input on the wire, public_hash. It is the hash of the circuit's public inputs, in the order this page lists them, together with the transaction hash:
transaction_hash = hash(private_tx_hash, public transfers)
public_hash = hash(public inputs in order, transaction_hash)The program never reads public inputs from the client. It computes each one from its own accounts, the clock, the oracle and the instruction's arguments, hashes them, and verifies the proof against that hash. The tables below say where each value comes from.
In the tables, Field is a BN254 field element passed as 32 bytes, and u32 and u64 are integers.
What mesa_identity is
The Mesa authority is the program address derived from the seed authority. Every Mesa note is owned by it: a note's owner is a holder key pair bound to the authority's identity.
mesa_identity is that identity as a field element. The program computes it from the authority's address on every instruction, and it is the first public input of every circuit. Each circuit requires the owner of every Mesa note it spends, and of every Mesa note it creates, to carry this identity. A proof made for any other owner does not verify.
Spend authorization
An account has a spend secret s and a spend key S = Poseidon(s). Every balance, share and position note stores
auth = Poseidon(S, nonce)with a fresh random nonce for each note. A circuit that spends on the owner's behalf takes s and the note's nonce as private inputs and requires Poseidon(Poseidon(s), nonce) to equal the note's auth.
An action note stores recipient_auth, the auth given to everything the action settles into. reclaim and reclaim_pair check the spend secret against it.
When a circuit creates a note for the owner, the new auth is a private input that the client computes from S and a new nonce. The circuit writes it into the note and does not check it.
The settle circuits, renew and liquidate_perp take no spend secret. Each fixes where every output goes, so the caller chooses nothing. liquidate_borrow takes the liquidator's spend secret, for the liquidator's own balance, and none for the position.
Where proofs are generated
Mesa proofs are generated where the keys are: in the browser, or in a Node process. The circuits compile to one WASM package built for each of the two, with the same exports. The pool's proof comes from the Privacy Rings prover.
For each circuit the package exports a builder named after it in camel case with the suffix Transaction, from depositTransaction to liquidatePerpTransaction:
export function placeLockTransaction(inputs: PlaceLock, sender: Uint8Array | number[], payer: string): ProgramTransaction;
export interface ProgramTransaction {
finalizedTx: FinalizedTransaction;
proofInputs: Record<string, string>;
publicHash: Uint8Array;
}inputs holds the circuit's private and public inputs. The builder lays out the transaction and returns finalizedTx, the notes and transfers for the pool's proof, proofInputs, the encoded inputs of the Mesa circuit, and publicHash, the value the program will recompute.
ProvingSession holds one circuit and its proving key, decoded once, and proves any number of times:
export class ProvingSession {
constructor(circuit_xbc: Bytes, pk_bytes: Bytes, sources?: string | null);
prove(inputs: any, options: any): ProofBundle;
}
export function programProof(proof: Uint8Array | number[], public_inputs: Uint8Array | number[], expected_hash: Uint8Array | number[]): ProgramProof;
export interface ProgramProof {
publicInputs: [Uint8Array];
compressedProof: CompressedProof;
}prove returns a ProofBundle with the proof and its public input. programProof checks that public input against the publicHash of the built transaction and returns the proof as the a, b, c the instruction carries.
The package also exports a decoder for each kind of note, balanceDataUtxo, shareDataUtxo, actionDataUtxo and positionDataUtxo, and poseidon2, the hash the circuits use. The SDK wraps all of this in one call per action.
Codes and fixed point
Action codes. An action's code, and a position's, is a u32: the kind in the low byte, the side in byte 1, the target id in bytes 2 and 3.
| Kind | Action | Target |
|---|---|---|
1 | Order | Spot market |
2 | Supply | Pool |
3 | Redeem | Pool |
4 | Borrow | Pool |
5 | Perp open | Perp market |
6 | Perp close | Perp market |
7 | Vault deposit | Vault |
8 | Vault withdraw | Vault |
Side 0 is buy or long and side 1 is sell or short.
Target codes. A target_code public input has the same layout. The program sets the kind and the target id from the pool or perp market account it was given and leaves the side byte 0, except in liquidate_perp.
Share targets. A share note's target is (target_kind << 16) | target_id, with target kind 2 for a pool and 4 for a vault.
Prices and indexes. A price is quote atoms per base atom scaled by 10^12. For a borrow it is the price of the collateral asset in the pool's asset. For a perp it is the price of the market's base asset in its quote asset. The program reads it from a Pyth price account, checks the feed and that it is no older than max_oracle_age, and scales it. An index is a pool's borrow_index or a perp market's funding_index, passed as a u64. The funding index is stored with an offset of 2^62, so it is never negative.
Collateral asset. collateral_asset is the hash of the collateral mint. For a borrow the program takes the mint from the pool's collateral list at the collateral_index given in the instruction's arguments. For a perp it is the market's quote mint.
Health checks
The circuits that open, renew, change or liquidate a position share four checks. All amounts are atoms, and every product is computed in 128 bits.
Accrued debt. A borrow's debt at the current index is
accrued = ceil(debt · index / entry)where debt and entry are the position's fields. The prover supplies accrued and the circuit checks accrued · entry ≥ debt · index and (accrued − 1) · entry < debt · index.
Borrow at entry.
collateral · price · collateral_factor_bps ≥ debt · 10^12 · 10^4Borrow after entry.
collateral · price · threshold_bps ≥ accrued · 10^12 · 10^4Perp at entry. Both must hold.
collateral · max_leverage · 10^12 ≥ size · price
collateral · 10^12 · 10^4 ≥ size · price · maint_margin_bpsPerp after entry.
collateral · 10^12 · 10^4 + pnl − owed ≥ size · price · threshold_bps
pnl = size · (price − entry) · 10^4 for a long, negated for a short
owed = size · (index − funding) · 10^4 for a long, negated for a shortsize is the position's debt field, entry its entry price and funding the funding index at entry. The circuit moves each negative term to the other side, so both sides stay unsigned.
The circuits
| Circuit | Instruction | Used for |
|---|---|---|
deposit | deposit | Rings notes into a balance |
withdraw | withdraw | A balance out to a Rings address |
consolidate | consolidate | Two balances into one |
place_lock | place | Order, supply, perps vault deposit |
place_share | place | Redeem, vault withdraw |
place_pair | place | Liquidity vault deposit of two assets |
place_open | place | Borrow, perp open |
place_close | place | Perp close |
settle | settle | A filled order |
settle_refund | settle | An unfilled order, a perp close that moves nothing |
settle_supply | settle | Supply, perps vault deposit |
settle_payout | settle | Redeem, borrow, perps vault withdraw, perp close with a gain |
settle_loss | settle | Perp close with a loss |
settle_pair | settle | Liquidity vault deposit |
settle_split | settle | Liquidity vault withdraw |
reclaim | reclaim | An action that never opened, or opened as Invalid |
reclaim_pair | reclaim | The same, for a deposit of two assets |
reclaim_share | reclaim | A redeem or vault withdraw that was Refused, never opened, or opened as Invalid |
reclaim_position | reclaim | A perp close that was Refused, never opened, or opened as Invalid |
renew | renew | A position's next deadline |
adjust_repay | repay | Part of a borrow's debt |
adjust_collateral | repay | Collateral added or removed |
close_position | close_position | A borrow repaid in full |
close_refused | close_position | A position whose borrow or perp open never took effect |
liquidate_borrow | liquidate | A lapsed, unhealthy borrow |
liquidate_perp | liquidate | A lapsed, unhealthy perp |
Account circuits
deposit
Verified by deposit, which the depositing wallet signs.
It takes in up to two plain Rings notes of one asset. It creates a balance note holding amount of that asset, and returns the rest to the wallet as Rings notes.
It proves that:
amountis not zero.- The notes spent are owned by the identity in
owner_pk_field. - The balance note's owner carries
mesa_identity.
It takes no spend secret. The wallet's signature authorizes the spend.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
owner_pk_field | Field | The identity of the wallet that signed the instruction |
8,865 constraints.
withdraw
Verified by withdraw.
It takes in one balance note. It creates a plain Rings note holding amount, owned by recipient, and a balance note with the rest for the same owner.
It proves that:
amountis not zero.- The balance note's owner carries
mesa_identity. - The spend secret matches the balance note's
auth. - The Rings note goes to the public
recipient.
It needs the owner's spend secret.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
recipient | Field | The hash of the recipient's Rings address, from the recipient_owner_hash and recipient_viewing_pubkey arguments |
8,190 constraints.
consolidate
Verified by consolidate.
It takes in two balance notes and creates one balance note holding the sum.
It proves that:
- Both notes hold the same asset and their owners carry
mesa_identity. - One spend secret matches the
authof both. - The new note's owner carries
mesa_identity.
It needs the owner's spend secret.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
9,568 constraints.
Place circuits
place selects the circuit from its kind argument. Each place circuit binds an action to the current batch and to a commitment: the hash of the action note's data, which the program stores in the action's account and checks again when the action opens.
All five share these checks:
- The action's
batchequals the publicbatch. - The hash of the action equals the public
commitment. - The owner of the action note and the action's
recipientboth carrymesa_identity. - The spend secret matches the
authof every note spent.
All five need the owner's spend secret.
place_lock
Selected by kind 1 (order), 2 (supply) or 7 (vault deposit of one asset, into a perps vault).
It takes in one balance note. It creates an action note holding the action's amount, and a balance note with the rest.
Beyond the shared checks, it proves that:
- The action's kind is
1,2or7. - The action's
amountis not zero. - The action's
assetis the asset of the balance spent.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
batch | u64 | The current batch number, from the clock |
commitment | Field | The commitment argument, stored in the action's account |
10,675 constraints.
place_share
Selected by kind 3 (redeem) or 8 (vault withdraw).
It takes in one share note. It creates an action note that holds no value, and the share note again with its shares reduced by the action's amount.
Beyond the shared checks, it proves that:
- The action's kind is
3or8. - The action's
amountis not zero and not more than the note'sshares. - The share note's
targetis the pool, for a redeem, or the vault, for a vault withdraw, that the action's code names. - The action's
assetis the asset of the share note.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
batch | u64 | The current batch number, from the clock |
commitment | Field | The commitment argument, stored in the action's account |
10,804 constraints.
place_pair
Selected by kind 0x87: a vault deposit of two assets into a spot liquidity vault. The action's own code carries kind 7.
It takes in a base balance note and a quote balance note. It creates two action notes with the same action data, one holding amount_b of the base asset and one holding amount of the quote asset, and a balance note with the rest of each.
Beyond the shared checks, it proves that:
- The action's kind is
7. amountandamount_bare not zero.- The action's
assetis the quote asset. - One spend secret matches the
authof both balance notes.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
batch | u64 | The current batch number, from the clock |
commitment | Field | The commitment argument, stored in the action's account |
16,453 constraints.
place_open
Selected by kind 4 (borrow) or 5 (perp open).
It takes in one balance note of the collateral asset. It creates a position note holding the collateral, an action note that holds no value, and a balance note with the rest.
Beyond the shared checks, it proves that:
- The balance spent holds the asset in
collateral_asset. - The action's kind and target id equal those in
target_code. - The collateral is not zero, the action's
amountis zero and itsamount_b, the debt or the size, is not zero. - The position's
codeequals the action's code, itsdebtequals the action'samount_b, itsdeadlineequals the publicdeadline, and itsactivationequals the publiccommitment. - The owner of the position note and the position's
homeboth carrymesa_identity. - For a borrow: the side is
0, the position'sentryand the action'sparamequalindex, the position'sfundingis zero, and the borrow is healthy at entry. - For a perp open: the side is
0or1, the position'sentryand the action'sparamequaloracle_price, the position'sfundingequalsindex, and the perp is healthy at entry.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
batch | u64 | The current batch number, from the clock |
commitment | Field | The commitment argument, stored in the action's account |
target_code | u32 | Kind 4 and the pool's id, or kind 5 and the perp market's id |
collateral_asset | Field | The hash of the collateral mint |
oracle_price | u64 | The Pyth price, scaled |
index | u64 | The pool's borrow_index, or the perp market's funding_index |
param_a | u64 | The pool's collateral_factor_bps, or the perp market's max_leverage |
param_b | u64 | 0 for a borrow, or the perp market's maint_margin_bps |
deadline | u64 | The end of the next heartbeat epoch: genesis_ts + (e + 2) · heartbeat, with e the current epoch |
22,878 constraints.
place_close
Selected by kind 6 (perp close).
It takes in one perp position note. It creates an action note holding all of the position's collateral.
Beyond the shared checks, it proves that:
- The position's kind is
5. - The action's code is the position's code with kind
6: the same side and the same perp market. - The action's
assetis the collateral asset and itsamountis the whole collateral. - The action's
amount_bis the position's size, itsparamthe position's entry price and itslimitthe position's funding index at entry.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
batch | u64 | The current batch number, from the clock |
commitment | Field | The commitment argument, stored in the action's account |
10,712 constraints.
Settle circuits
settle selects the circuit from the opened action's kind and from the amounts the program computes for it out of the batch's results. A perp open settles with no proof and moves no notes.
All seven share these checks:
- The action note's owner carries
mesa_identity. - The hash of the action equals the public
commitment, which the program reads from the action's account. - The address every output goes to has the owner and the viewing key named in the action as
recipient, and carriesmesa_identity. - Every output takes the action's
recipient_authas itsauth.
None of the seven takes a spend secret. The caller needs the action note's contents and its holder keys, which the batch's timelock ciphertext releases when the batch opens.
settle
Used for a spot order that fills, in whole or in part.
It takes in the action note. It creates a balance note of the asset bought, holding from_vault, and a balance note of the asset sold, holding what is left of the locked amount after to_vault.
Beyond the shared checks, it proves that to_vault and from_vault are not zero. Its public transfers are a withdraw leg of to_vault in the asset sold and a deposit leg of from_vault in the asset bought.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
commitment | Field | The action account's commitment |
to_vault | u64 | The amount the order pays at the clearing price |
from_vault | u64 | The amount the order receives, after the fee |
12,693 constraints.
settle_refund
Used for a spot order that fills nothing, and for a perp close whose result is zero in both directions.
It takes in the action note and creates one balance note holding everything the action locked. It has no public transfers.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
commitment | Field | The action account's commitment |
8,422 constraints.
settle_supply
Used for a pool supply and for a perps vault deposit.
It takes in the action note. It creates a share note with the public share_target and shares.
Beyond the shared checks, it proves that to_vault and shares are not zero. Its public transfer is a withdraw leg of to_vault in the pool's or the vault's asset.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
commitment | Field | The action account's commitment |
to_vault | u64 | The action's amount |
share_target | u32 | The pool or vault, as a share target |
shares | u64 | The shares minted for amount, at the share price the batch recorded |
10,002 constraints.
settle_payout
Used for a pool redeem, a borrow, a perps vault withdraw, and a perp close with a gain.
It takes in the action note. It creates one balance note holding what the action locked plus from_vault.
Beyond the shared checks, it proves that from_vault is not zero. Its public transfer is a deposit leg of from_vault in the pool's asset or the perp market's quote asset.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
commitment | Field | The action account's commitment |
from_vault | u64 | Redeem: the shares' value at the batch's share price. Borrow: the action's amount_b. Vault withdraw: the shares' part of the vault. Perp close: the gain |
9,938 constraints.
settle_loss
Used for a perp close with a loss.
It takes in the action note. It creates one balance note holding the collateral left after to_vault.
Beyond the shared checks, it proves that to_vault is not zero. Its public transfer is a withdraw leg of to_vault in the perp market's quote asset.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
commitment | Field | The action account's commitment |
to_vault | u64 | The loss the close pays to the perps vault |
9,867 constraints.
settle_pair
Used for a deposit of two assets into a spot liquidity vault.
It takes in the two action notes that place_pair created. It creates a share note with the public share_target and shares, and a balance note for what is left of each asset.
Beyond the shared checks, it proves that:
- Both action notes carry the same action, and the quote note holds the action's
asset. used_base,used_quoteandsharesare not zero.
Its public transfers are a withdraw leg of used_base in the base asset and a withdraw leg of used_quote in the quote asset.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
commitment | Field | The action account's commitment |
used_base | u64 | The base amount the vault takes, at the reserves the batch recorded |
used_quote | u64 | The quote amount the vault takes |
share_target | u32 | The vault, as a share target |
shares | u64 | The shares minted |
16,349 constraints.
settle_split
Used for a withdraw from a spot liquidity vault.
It takes in the action note. It creates a balance note of the base asset holding base_out and a balance note of the quote asset holding quote_out.
Beyond the shared checks, it proves that base_out and quote_out are not zero. Its public transfers are a deposit leg of each.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
commitment | Field | The action account's commitment |
base_out | u64 | The shares' part of the vault's base reserve, as the batch recorded it |
quote_out | u64 | The shares' part of the vault's quote reserve |
13,127 constraints.
Reclaim circuits
reclaim accepts an action that is still Sealed, or was opened as Invalid, once the batch's open window has ended. It also accepts a redeem, a vault withdraw or a perp close that its batch Refused, as soon as the target has cleared. It selects reclaim_share for an action that locked shares, reclaim_position for a perp close, reclaim_pair when the transaction spends two notes, and reclaim otherwise.
All four need the owner's spend secret.
reclaim
It takes in the action note and creates one balance note holding everything the action locked.
It proves that:
- The action note's owner carries
mesa_identity. - The hash of the action equals the public
commitment. - The spend secret matches the action's
recipient_auth. - The action's kind is not redeem (
3), perp close (6) or vault withdraw (8). A redeem and a vault withdraw return as shares, throughreclaim_share, and a perp close returns as its position, throughreclaim_position. - The balance note's owner carries
mesa_identity.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
commitment | Field | The action account's commitment |
8,877 constraints.
reclaim_pair
It takes in the two action notes that place_pair created. It creates a balance note of the base asset and a balance note of the quote asset, each holding what its action note locked.
It proves what reclaim proves, for both action notes under the one action.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
commitment | Field | The action account's commitment |
12,720 constraints.
reclaim_share
It takes in the action note of a redeem or a vault withdraw. It creates one share note of the same pool or vault, holding the number of shares the action locked.
It proves that:
- The action note's owner carries
mesa_identity. - The hash of the action equals the public
commitment. - The action's kind is redeem (
3) or vault withdraw (8). - The spend secret matches the action's
recipient_auth. - The share note's target is the action's target and its share count is the action's
amount. - The share note's owner carries
mesa_identity.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
commitment | Field | The action account's commitment |
8,848 constraints.
reclaim_position
It takes in the action note of a perp close and creates the position note the close spent: the same collateral, market, side, size, entry price and entry funding index, with a new deadline.
It proves that:
- The action note's owner carries
mesa_identity. - The hash of the action equals the public
commitment. - The action's kind is perp close (
6), with a nonzero collateral and size, and the action note holds itsamount. - The spend secret matches the action's
recipient_auth. - The position's code is the action's code with the kind set to perp open (
5), its size is the action'samount_b, itsentrythe action'sparamand itsfundingthe action'slimit. - The position's
deadlineis the publicdeadlineand itsactivationis the publiccommitment. - The position's owner and its
homecarrymesa_identity.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
commitment | Field | The action account's commitment |
deadline | u64 | The end of the heartbeat epoch after the current one, computed by the program |
The instruction carries the restored position's timelock ciphertext, sealed to that deadline, as renew does.
10,403 constraints.
Position circuits
renew
Verified by renew.
It takes in one position note, a borrow or a perp, and creates the same position note with its deadline set to new_deadline. Collateral, debt, entry, funding, activation, auth, home and the owner are unchanged.
It proves that:
- The position's owner carries
mesa_identity. - The collateral is the asset in
collateral_asset. - The position's kind and target id equal those in
target_code. - The position's
deadlineequalsold_deadline, andnew_deadlineis later. - The position is healthy after entry at
oracle_price,indexandthreshold_bps.
It takes no spend secret. The caller needs the position's contents and its holder keys: the owner has them, and so does a watcher the position is enrolled with.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
target_code | u32 | Kind 4 and the pool's id, or kind 5 and the perp market's id |
collateral_asset | Field | The hash of the collateral mint |
oracle_price | u64 | The Pyth price, scaled |
index | u64 | The pool's borrow_index, or the perp market's funding_index |
threshold_bps | u64 | The pool's liq_threshold_bps, or the perp market's maint_margin_bps |
old_deadline | u64 | The old_deadline argument |
new_deadline | u64 | The end of the next heartbeat epoch, from the clock |
34,376 constraints.
adjust_repay
Verified by repay with mode 0.
It takes in a borrow position note and a balance note. It creates the position note with less debt and a new deadline, and a balance note with the rest.
It proves that:
- Both notes' owners carry
mesa_identity, and one spend secret matches theauthof both. - The position's kind is
4and its target id equals the one intarget_code. - The collateral is the asset in
collateral_asset. repaidis not zero and is less than the accrued debt.- The new position's
debtis the accrued debt lessrepaid, itsentryisindex, and itsdeadlineisnew_deadline. - With the new debt, the borrow is healthy after entry.
Its public transfer is a withdraw leg of repaid in the pool's asset, from the balance note to the pool. It needs the owner's spend secret.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
target_code | u32 | Kind 4 and the pool's id |
collateral_asset | Field | The hash of the collateral mint |
oracle_price | u64 | The Pyth price, scaled |
index | u64 | The pool's borrow_index |
threshold_bps | u64 | The pool's liq_threshold_bps |
new_deadline | u64 | The end of the next heartbeat epoch, from the clock |
repaid | u64 | The repaid argument |
18,978 constraints.
adjust_collateral
Verified by repay with mode 1.
It takes in a position note, a borrow or a perp, and a balance note of the collateral asset. It creates the position note with more or less collateral and a new deadline, and the balance note with the difference. The amount moved is a private input.
It proves that:
- Both notes' owners carry
mesa_identity, and one spend secret matches theauthof both. - Both notes hold the asset in
collateral_asset. - The position's kind and target id equal those in
target_code. - Collateral is either added or removed, and the amount is not zero.
- The collateral left in the position is not zero.
- With the new collateral, the position is healthy after entry.
- The new position's
deadlineisnew_deadline.
It has no public transfers. It needs the owner's spend secret.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
target_code | u32 | Kind 4 and the pool's id, or kind 5 and the perp market's id |
collateral_asset | Field | The hash of the collateral mint |
oracle_price | u64 | The Pyth price, scaled |
index | u64 | The pool's borrow_index, or the perp market's funding_index |
threshold_bps | u64 | The pool's liq_threshold_bps, or the perp market's maint_margin_bps |
new_deadline | u64 | The end of the next heartbeat epoch, from the clock |
46,255 constraints.
close_position
Verified by close_position with mode 0.
It takes in a borrow position note and a balance note. It creates a balance note holding all of the position's collateral, and a balance note with what is left after the repayment.
It proves that:
- Both notes' owners carry
mesa_identity, and one spend secret matches theauthof both. - The position's kind is
4and its target id equals the one intarget_code. repaidequals the position's accrued debt atindex.- The collateral balance's owner carries
mesa_identity.
Its public transfer is a withdraw leg of repaid in the pool's asset, from the balance note to the pool. It needs the owner's spend secret.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
target_code | u32 | Kind 4 and the pool's id |
index | u64 | The pool's borrow_index |
repaid | u64 | The repaid argument |
16,819 constraints.
close_refused
Verified by close_position with mode 1, for a position whose borrow or perp open the batch Refused, or that was never opened or opened as Invalid.
It takes in the position note and creates a balance note holding all of its collateral. Nothing is repaid.
It proves that:
- The position's owner and the balance note's owner carry
mesa_identity. - The position's
activationequalsrefused_activation. - The spend secret matches the position's
auth.
It has no public transfers. It needs the owner's spend secret.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
refused_activation | Field | The commitment of the action account given, which the program requires to be in the Refused state |
8,209 constraints.
Liquidation circuits
liquidate refuses unless the clock is past the old_deadline argument, and selects the circuit from its kind argument. The liquidator reads the position's contents and holder keys from its last timelock ciphertext, which opens at that deadline. See Liquidation.
liquidate_borrow
It takes in the lapsed borrow position note and a balance note of the liquidator's, in the pool's asset. It creates three balance notes: the seized collateral for the liquidator, the rest of the collateral for the position's owner, and the liquidator's balance less the repayment.
It proves that:
- The owners of both notes spent, and of every note created, carry
mesa_identity. - The liquidator's spend secret matches the
authof the liquidator's balance note. - The position's kind is
4, its target id equals the one intarget_code, its collateral is the asset incollateral_asset, and itsdeadlineequalsold_deadline. repaidequals the position's accrued debt atindex.- The position is unhealthy:
collateral · price · liq_threshold_bps < repaid · 10^12 · 10^4. - The amount seized is
ceil(repaid · (10^4 + liq_bonus_bps) · 10^12 / (10^4 · price)), or the whole collateral when that is more than the position holds. - The rest of the collateral goes to the address with the owner and the viewing key the position names as
home, and takes the position's ownauth.
Its public transfer is a withdraw leg of repaid in the pool's asset, from the liquidator's balance note to the pool. It needs the liquidator's spend secret and not the position owner's.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
target_code | u32 | Kind 4 and the pool's id |
collateral_asset | Field | The hash of the collateral mint |
oracle_price | u64 | The Pyth price, scaled |
index | u64 | The pool's borrow_index |
liq_threshold_bps | u64 | The pool's liq_threshold_bps |
liq_bonus_bps | u64 | The pool's liq_bonus_bps |
old_deadline | u64 | The old_deadline argument |
repaid | u64 | The amount argument |
30,495 constraints.
liquidate_perp
It takes in the lapsed perp position note. It creates one balance note for the liquidator holding the bonus. The rest of the collateral goes to the perps vault.
It proves that:
- The position's owner and the liquidator's balance note's owner carry
mesa_identity. - The position's
codeequalstarget_code, side included, and its kind is5. - The position's size equals
size, its collateral is the asset incollateral_asset, and itsdeadlineequalsold_deadline. - The position is unhealthy: the after entry check for a perp fails at
oracle_price,indexandmaint_margin_bps. - The bonus is
floor(collateral · liq_bonus_bps / 10^4), andto_vaultis the collateral less the bonus. to_vaultis not zero.
Its public transfer is a withdraw leg of to_vault in the perp market's quote asset, from the position note to the perps vault. It takes no spend secret.
| Public input | Type | Set from |
|---|---|---|
mesa_identity | Field | The Mesa authority's identity |
target_code | u32 | Kind 5, the side argument and the perp market's id |
collateral_asset | Field | The hash of the perp market's quote mint |
oracle_price | u64 | The Pyth price, scaled |
index | u64 | The perp market's funding_index |
maint_margin_bps | u64 | The perp market's maint_margin_bps |
liq_bonus_bps | u64 | The perp market's liq_bonus_bps |
old_deadline | u64 | The old_deadline argument |
to_vault | u64 | The amount argument |
size | u64 | The size argument, which the program also takes off the market's open interest for that side |
39,969 constraints.
Keys
Verifying keys. Each circuit has its own Groth16 verifying key, and all 26 are constants compiled into the mesa program. No account holds one and no instruction replaces one, so the keys in force are those of the deployed program. Config also records vk_set_id, 32 bytes set by the admin that name the key set.
Proving keys. A prover needs two files per circuit: the compiled circuit, circuit.xbc, and its proving key, pk.bin. Each WASM package carries proving-keys.json, the SHA-256 of every circuit's proving key, and exports checkProvingKey to validate key bytes against it before use. circuitDigest returns the digest of a circuit.xbc, which is the same for every build of one circuit.