DocsProgram instructions

DocsReference23 of 33 · 6 min read

Program instructions

Every instruction of the Liora program, with its accounts, its arguments, what it checks, what it emits and what makes it fail.

The program is at 8i6Rs6mak6AoQH1Cd6asXpJoGMVqWP81iEux5kdnHbA4, version 0.2.1. It is an Anchor program: each instruction's data starts with an 8-byte discriminator, followed by its arguments in Borsh. The SDK builds all of these. This page is for reading a transaction, or for building one without the SDK.

InstructionWho signsWhat it does
depositThe depositing walletMoves public SOL into a private balance
payThe relayerPays a whitelisted recipient at a stealth address
withdrawThe relayerPays a private balance out to a public wallet
admitThe issuerAdds a recipient to the whitelist
removeThe issuerRemoves a recipient from the whitelist
initializeThe adminCreates the configuration
configureThe adminReplaces the roles and fees
hash_vectorNobodyReturns a Poseidon hash, for checking a client against the program

Every instruction that emits an event takes two more accounts at the end, event_authority and program. Anchor uses them to record the event as an inner instruction. See Events.

#deposit

Discriminator f223c68952e1f2b6.

Forwards a public SOL deposit to the Solana Privacy Program (SPP) and records it. The note that results belongs to the owner address of owner_point.

#AccountSignerWritableWhat it is
0walletYesYesThe depositing wallet. Signs the deposit and pays its network fee.
1configThe configuration account, read only.
2event_authorityThe program's event authority.
3programThe Liora program.
owner_point[u8; 32]required
The packed balance key B that will own the note.
nullifier_pk[u8; 32]required
Poseidon(nullifier secret) for that balance key.
sppbytesrequired
The SPP deposit instruction, byte for byte as it is forwarded.

Five more accounts follow, the ones the SPP deposit takes, in this order:

#Account
0The Ring's output tree, writable
1The depositing wallet, the same as wallet
2The SPP program
3The System Program
4The Ring's SOL vault

The program checks that spp is one SOL deposit of more than zero lamports, that its view tag is the owner address of owner_point, and that its owner commitment is Poseidon(identity(owner address), nullifier_pk). Then it calls SPP.

Emits DepositRecorded. Fails with InvalidSpp, InvalidOwner or InvalidField.

#pay

Discriminator 7712d841c0757adc.

Verifies the payment's proof, signs for the owners of the notes being spent, forwards the transfer to SPP, settles the two fees and emits the announcement.

#AccountSignerWritableWhat it is
0relayerYesYesThe relayer in the configuration. Pays the network fee.
1configThe configuration account, read only.
2settlementYesThe program's settlement address, which the Ring pays the fees into. Seeds: settlement.
3fee_recipientYesThe fee recipient in the configuration.
4destinationYesFor a payment, the relayer again.
5system_programThe System Program.
6event_authorityThe program's event authority.
7programThe Liora program.
ownersVec<[u8; 32]>required
1 to 3 distinct packed public keys that own the notes being spent. Change returns to the first.
announcementPaymentAnnouncementrequired
The payment's announcement. Emitted as given once the proof verifies.
proof[u8; 128]required
The Liora proof: compressed -A (32 bytes), B (64), C (32).
sppbytesrequired
The SPP transact instruction with its own proof, byte for byte as it is forwarded.

The accounts of the SPP transact call follow, in the order that call takes them. With n notes spent and m owners:

#Account
0The relayer, as fee payer of the SPP call
1The Ring's output tree, writable
2The SPP program
3The System Program
4The Ring's input tree, writable
5 to 4 + nThe nullifier account of each note spent, writable
5 + n to 4 + n + mThe owner address of each key in owners, in the same order
5 + n + mThe Ring's SOL vault
6 + n + mThe settlement address

What the program checks, in order:

  1. The destination and the root

    destination is the relayer, and announcement.whitelist_root is one of the accepted roots.

  2. The shape of the transfer

    spp is a transact instruction on the Default Ring with one input tree, 1 to 3 input slots and 2 output slots, and the only public movement in it is one SOL withdrawal of exactly the protocol fee plus the relayer fee.

  3. The owners

    Each key in owners is listed once and its owner address is the account passed for it. The owner address of the stealth address is neither the relayer nor one of the input owners.

  4. The outputs

    Exactly one output belongs to the owner address of the stealth address. Every other output belongs to the first owner.

  5. The proof

    The program computes the statement from the instruction, the accounts and the configuration, and verifies proof against it. The proof says what the statement covers.

  6. The transfer and the fees

    The program calls SPP with a signature for each owner address. The settlement address must receive exactly the two fees, and pays them on to the fee recipient and the relayer. The relayer must end the instruction at least 5,000 lamports above where it entered, which is the signature fee it had already paid.

Emits PaymentAnnouncement. Fails with RootExpired, InvalidSpp, InvalidOwner, InvalidSettlement, InvalidProof, InvalidField or Arithmetic.

#withdraw

Discriminator b712469c946da122.

Verifies the withdrawal's proof, signs for the owners, forwards the transfer to SPP and pays amount to destination beside the two fees.

#AccountSignerWritableWhat it is
0relayerYesYesThe relayer in the configuration. Pays the network fee.
1configThe configuration account, read only.
2settlementYesThe program's settlement address, which the Ring pays the withdrawal and the fees into.
3fee_recipientYesThe fee recipient in the configuration.
4destinationYesThe public wallet that receives the withdrawal. Bound into the proof.
5system_programThe System Program.
6event_authorityThe program's event authority.
7programThe Liora program.
ownersVec<[u8; 32]>required
1 to 3 distinct packed public keys that own the notes being spent. Change returns to the first.
amountu64required
The lamports paid to destination. Greater than zero.
proof[u8; 128]required
The Liora proof: compressed -A (32 bytes), B (64), C (32).
sppbytesrequired
The SPP transact instruction with its own proof, byte for byte as it is forwarded.

The remaining accounts are laid out as for pay.

The checks are those of pay with three differences. amount is greater than zero. The one public movement is a SOL withdrawal of amount plus both fees. No output may go to a new owner: every output belongs to the first owner, so a withdrawal moves value out of the Ring or back to the holder.

The proof binds destination and amount. A relayer that changed either would submit a transaction the program rejects.

Emits WithdrawalRecorded. Fails with InvalidSettlement, InvalidSpp, InvalidOwner, InvalidProof, InvalidField or Arithmetic.

#admit

Discriminator c0a9048af85ab82f.

Writes a recipient's leaf at the next free index and creates their entry account.

#AccountSignerWritableWhat it is
0issuerYesYesThe issuer in the configuration. Pays for the entry account.
1configYesThe configuration account. Receives the new root and revision.
2entryYesThe recipient's entry, created here. Seeds: entry, then the packed spend key.
3system_programThe System Program.
4event_authorityThe program's event authority. Seeds: __event_authority.
5programThe Liora program.
revisionu64required
The whitelist revision the issuer decided on. Must be the current one.
spend_point[u8; 32]required
The recipient's packed public spend key S.
affine[[u8; 32]; 4]required
S.x, S.y, V.x, V.y, each 32 big-endian bytes.
siblings[[u8; 32]; 24]required
The path of the empty leaf at the next free index, against the current root.

The program checks that revision is current, that spend_point packs the coordinates given, and that siblings open an empty leaf at the next free index under the current root. It then computes the leaf, puts the new root first in the accepted roots, keeps at most 32 of them, and raises the size, the next index and the revision by one.

The entry account's address is derived from the spend key, so a spend key can be admitted once. Admitting it a second time fails because the account exists.

Emits WhitelistChanged with admitted true. Fails with RevisionChanged, InvalidPoint, InvalidTreePath or InvalidField.

#remove

Discriminator c7ba094f6081186a.

Clears a recipient's leaf and drops every earlier root.

#AccountSignerWritableWhat it is
0issuerYesThe issuer in the configuration.
1configYesThe configuration account. Receives the new root and revision.
2entryYesThe entry being removed.
3event_authorityThe program's event authority.
4programThe Liora program.
revisionu64required
The whitelist revision the issuer decided on. Must be the current one.
siblings[[u8; 32]; 24]required
The path of the entry's leaf against the current root.

The program checks that revision is current, that the entry is active, and that siblings open the entry's leaf under the current root. It then sets the leaf to zero, replaces the accepted roots with the new root alone, lowers the size by one, raises the revision by one and marks the entry inactive. The entry account stays, with its spend key, view key, index and leaf.

Emits WhitelistChanged with admitted false. Fails with RevisionChanged, InactiveEntry or InvalidTreePath.

#initialize

Discriminator afaf6d1f0d989bed.

Creates the configuration account with the roles, the fees and the root of an empty whitelist. It runs once: the account exists afterwards.

#AccountSignerWritableWhat it is
0adminYesYesPays for the configuration account. Must be the program's upgrade authority.
1configYesThe configuration account, created here. Seeds: config.
2program_dataThe program's data account under the upgradeable loader, read for its upgrade authority.
3system_programThe System Program.
issuerpubkeyrequired
The wallet that may admit and remove recipients.
auditor[u8; 32]required
The auditor's public key A, a packed Baby Jubjub point.
fee_recipientpubkeyrequired
The wallet that receives the protocol fee.
relayerpubkeyrequired
The wallet that submits payments and withdrawals.
protocol_feeu64required
The flat protocol fee per payment or withdrawal, in lamports.
relayer_feeu64required
The flat amount the relayer is paid back per payment or withdrawal, in lamports.

The two fees may not both be zero, and the fee recipient may not be the settlement address. Fails with WrongAuthority, InvalidField, InvalidSettlement or Arithmetic.

#configure

Discriminator f5076c755fc436d9.

Replaces every role and both fees in one call. Pass the current value for anything that stays. The whitelist is untouched.

#AccountSignerWritableWhat it is
0adminYesThe admin in the configuration.
1configYesThe configuration account.
next_adminpubkeyrequired
The admin from now on. Pass the current admin to keep it.
issuerpubkeyrequired
The issuer from now on.
auditor[u8; 32]required
The auditor's public key from now on.
fee_recipientpubkeyrequired
The fee recipient from now on.
relayerpubkeyrequired
The relayer from now on.
protocol_feeu64required
The protocol fee from now on, in lamports.
relayer_feeu64required
The relayer fee from now on, in lamports.

A payment or withdrawal uses the configuration in force when it executes. Its proof binds the auditor key, the fee recipient, the relayer and both fees, so a transfer proved before a change to any of them fails with InvalidProof after it and is made again.

Fails with WrongAuthority, InvalidField, InvalidSettlement or Arithmetic, or with Anchor's ConstraintHasOne when the signer is not the admin.

#hash_vector

Discriminator a0f28d4674d81c53.

Returns, as the transaction's return data, the Poseidon hash of the values given. A client simulates it to confirm that its own Poseidon agrees with the program's. It changes nothing.

#AccountSignerWritableWhat it is
0configThe configuration account, read only.
valuesVec<[u8; 32]>required
1 to 12 field elements, each 32 big-endian bytes.

Fails with InvalidField.

#Errors

The names above are the program's own errors, listed with their codes on Errors.