The program has 15 instructions.
| Instruction | Arguments | Signers | Does |
|---|
initialize | args: ConfigArgs | admin | Creates the Config. Sent once by the program's upgrade authority. |
set_config | args: ConfigArgs | admin | Changes the Config. |
create_model | args: CreateModelArgs | owner, upload_key | Creates a Model in Uploading, binds its Weights accounts and funds the upload key. |
write_weights | offset: u32, bytes: bytes | upload_key | Writes ciphertext bytes into one Weights account. |
seal_model | ciphertext_sha256: [u8; 32] | owner | Fixes the ciphertext hash and moves the model to Sealed. |
set_price | price: u64, price_mint: pubkey, operator_share_bps: u16 | owner | Sets a model's price, price mint and operator share. |
retire_model | | owner | Moves a model to Retired. No new calls open. |
register_enclave | encryption_key: [u8; 32], endpoint: string | operator, signing_key | Creates an Enclave from a current attestation record. |
refresh_enclave | endpoint: string | signing_key | Copies the enclave's current attestation record into its Enclave account and sets its endpoint. |
grant_by_owner | wrapped_key: bytes | owner, payer | Writes a Grant from the owner to an enclave and moves the model to Live. |
grant_by_enclave | wrapped_key: bytes | signing_key, payer | Writes a Grant from an enclave that holds one to another enclave. |
revoke_grant | | owner | Marks a Grant revoked. No new calls open on it. |
open_call | nonce: u64, input_hash: [u8; 32] | caller | Creates a Call and moves the model's price into its escrow. |
settle_call | output_hash: [u8; 32], signature: [u8; 64], ed25519_instruction_index: u16 | payer | Checks the enclave's signature, writes the Receipt and pays out the escrow. |
refund_call | | actor | Returns the escrow of a call past its deadline to the caller. |
Every instruction ends with two accounts that Anchor's event CPI needs: event_authority, the PDA ["__event_authority"], and program, the voynich program itself. Accounts are passed in the order of each table. An optional account that is left out is passed as the program's own address.
The errors named below are in Errors. The events are in Events.
initialize#
Creates the Config. It can be sent once, by the program's upgrade authority.
| Argument | Type |
|---|
attestation_program | pubkey |
record_layout_version | u8 |
fee_recipient | pubkey |
protocol_share_bps | u16 |
call_deadline_slots | u64 |
| Account | Writable | Signer | Optional | Address | Is |
|---|
admin | yes | yes | | | The program's upgrade authority. Becomes the Config's admin and pays its rent. |
config | yes | | | PDA ["config"] | The Config, created here. |
program_account | | | | 65H3C7T6C2DmbkR9ssBBmNtqpybWcYwotkkETL4E7RSS | The Voynich program. |
program_data | | | | | The program's ProgramData account, which names the upgrade authority. |
system_program | | | | 11111111111111111111111111111111 | The System program. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
- Checks. The signer is the program's upgrade authority (
Unauthorized). The attestation program and the fee recipient are not the default address, the layout version is above 0, the protocol share is at most 10,000 and the deadline is above 0 slots (InvalidConfig).
- Effects. The Config holds the admin and the five values. Emits
ConfigChanged.
set_config#
Changes the Config's five values. The admin stays.
| Argument | Type |
|---|
attestation_program | pubkey |
record_layout_version | u8 |
fee_recipient | pubkey |
protocol_share_bps | u16 |
call_deadline_slots | u64 |
| Account | Writable | Signer | Optional | Address | Is |
|---|
admin | | yes | | | The Config's admin. |
config | yes | | | PDA ["config"] | The protocol's Config. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
- Checks. The signer is the Config's admin (
Unauthorized). The values pass the same checks as in initialize (InvalidConfig).
- Effects. The Config holds the new values. Calls that are already open keep the fee recipient, the protocol share and the deadline they opened with. Emits
ConfigChanged.
create_model#
Creates a Model in Uploading, binds its Weights accounts to it and moves the upload funding to the upload key.
| Argument | Type |
|---|
name | string |
manifest | bytes |
size_bytes | u64 |
cipher | string |
nonce_prefix | [u8; 16] |
allowed_measurements | Vec<[u8; 48]> |
price | u64 |
price_mint | pubkey |
operator_share_bps | u16 |
upload_funding_lamports | u64 |
| Account | Writable | Signer | Optional | Address | Is |
|---|
owner | yes | yes | | | The model's owner. Pays the Model's rent and the upload funding. |
upload_key | yes | yes | | | A fresh key that will write the ciphertext: system-owned, holding no data, different from the owner. |
config | | | | PDA ["config"] | The protocol's Config. |
model | yes | | | PDA ["model", args.name] | The Model, created here. |
system_program | | | | 11111111111111111111111111111111 | The System program. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
manifest is the manifest's compact UTF-8 JSON, as told in The manifest on chain. After these, the transaction passes the model's Weights accounts in order, each writable, as remaining accounts.
- Checks. The name is 1 to 32 bytes of lowercase letters and digits in groups joined by single hyphens; the manifest is 1 to 4,096 bytes;
size_bytes is above 16; cipher is xchacha20poly1305-64k-v1; there are 1 to 8 allowed measurements; the operator share plus the protocol share is at most 10,000; the upload key is not the owner, is owned by the System program and holds no data (InvalidModel). There are 1 to 8 Weights accounts, each owned by the program, writable, rent-exempt, listed once, at most 10 MiB, with its first 56 bytes zero, and their ciphertext sizes add up to size_bytes (InvalidWeights).
- Effects. The Model exists with status
Uploading. Each Weights account has its header. upload_funding_lamports moves from the owner to the upload key. Emits ModelCreated.
write_weights#
Writes ciphertext bytes into one Weights account. Signed by the upload key alone, so an upload needs no wallet prompt per write.
| Argument | Type |
|---|
offset | u32 |
bytes | bytes |
| Account | Writable | Signer | Optional | Address | Is |
|---|
upload_key | | yes | | | The model's upload key. |
model | | | | PDA ["model", model.name] | The Model. |
weights | yes | | | | The Weights account written to. It is one of the model's. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
offset counts from the start of that account's ciphertext, not from the start of the model's.
- Checks. The signer is the model's upload key (
Unauthorized). The model is Uploading (ModelNotUploading). The account is one of the model's Weights accounts (InvalidWeights). bytes is not empty and offset plus the length is at most the account's size (InvalidWrite).
- Effects. The bytes are in the account and
written_bytes is the highest end written so far. Writes may land in any order. Writing a range again replaces it. Emits WeightsWritten.
seal_model#
Fixes the ciphertext hash. From here the bytes cannot change.
| Argument | Type |
|---|
ciphertext_sha256 | [u8; 32] |
| Account | Writable | Signer | Optional | Address | Is |
|---|
owner | | yes | | | The model's owner. |
model | yes | | | PDA ["model", model.name] | The Model. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
After these, the transaction passes every Weights account of the model in order as remaining accounts.
- Checks. The signer is the model's owner (
Unauthorized). The model is Uploading (ModelNotUploading). The accounts are the model's Weights accounts in order (InvalidWeights). Every account's written_bytes equals its size (UploadIncomplete). The SHA-256 of their ciphertext in order equals ciphertext_sha256 (CiphertextHashMismatch).
- Effects. The Model holds the hash and the sealing slot, its status is
Sealed and its upload key is cleared, so nothing can write to its Weights accounts again. Emits ModelSealed.
set_price#
Sets the price, the price mint and the operator share.
| Argument | Type |
|---|
price | u64 |
price_mint | pubkey |
operator_share_bps | u16 |
| Account | Writable | Signer | Optional | Address | Is |
|---|
owner | | yes | | | The model's owner. |
config | | | | PDA ["config"] | The protocol's Config. |
model | yes | | | PDA ["model", model.name] | The Model. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
price_mint is an SPL Token mint, or the default (all-zero) address for SOL.
- Checks. The signer is the model's owner (
Unauthorized). The operator share plus the protocol share is at most 10,000 (InvalidModel).
- Effects. New calls open at the new price, mint and share. Open calls keep theirs. Emits
ModelPriceChanged.
retire_model#
Closes a model to new calls.
| Account | Writable | Signer | Optional | Address | Is |
|---|
owner | | yes | | | The model's owner. |
config | | | | PDA ["config"] | The protocol's Config. |
model | yes | | | PDA ["model", model.name] | The Model. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
- Checks. The signer is the model's owner (
Unauthorized).
- Effects. The model's status is
Retired. open_call, grant_by_owner and grant_by_enclave refuse it. Calls that are open settle until their deadline and refund after it. Emits ModelStatusChanged.
register_enclave#
Creates an Enclave from a current attestation record.
| Argument | Type |
|---|
encryption_key | [u8; 32] |
endpoint | string |
| Account | Writable | Signer | Optional | Address | Is |
|---|
operator | yes | yes | | | The operator's wallet. Pays the Enclave's rent and receives the operator share of its calls. |
signing_key | | yes | | | The enclave's signing key, the key the attestation record names. |
config | | | | PDA ["config"] | The protocol's Config. |
attestation_record | | | | | The enclave's attestation record. |
enclave | yes | | | PDA ["enclave", signing_key] | The Enclave, created here. |
system_program | | | | 11111111111111111111111111111111 | The System program. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
- Checks. The endpoint is 1 to 256 bytes and starts with
http:// or https://, and the encryption key is not all zero (InvalidEnclave). The record is owned by the configured attestation program, sits at the address derived from the signing key, has the configured layout, names the signing key, and is unexpired at the current slot (InvalidAttestation). The signing key signs the transaction, so only the enclave that holds it can register it.
- Effects. The Enclave holds both keys, the operator, the endpoint, the record's address and the record's hardware type, measurement, recorded slot and expiry slot. Emits
EnclaveChanged.
refresh_enclave#
Copies the enclave's current attestation record into its Enclave account and sets its endpoint. An enclave sends it after it attests again.
| Argument | Type |
|---|
endpoint | string |
| Account | Writable | Signer | Optional | Address | Is |
|---|
signing_key | | yes | | | The enclave's signing key. |
config | | | | PDA ["config"] | The protocol's Config. |
attestation_record | | | | | The enclave's attestation record. |
enclave | yes | | | PDA ["enclave", signing_key] | The Enclave. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
- Checks. The signer is the enclave's signing key (
Unauthorized). The endpoint is valid (InvalidEnclave). The record is valid and unexpired (InvalidAttestation).
- Effects. The Enclave holds the record's current hardware type, measurement, recorded slot and expiry slot, and the endpoint given. Emits
EnclaveChanged.
grant_by_owner#
Writes a Grant from the owner to an enclave.
| Argument | Type |
|---|
wrapped_key | bytes |
| Account | Writable | Signer | Optional | Address | Is |
|---|
owner | | yes | | | The model's owner. |
payer | yes | yes | | | Pays the Grant's rent. |
config | | | | PDA ["config"] | The protocol's Config. |
model | yes | | | PDA ["model", model.name] | The Model. |
target_enclave | | | | PDA ["enclave", target_enclave.signing_key] | The Enclave the grant is made to. |
target_attestation_record | | | | | That enclave's attestation record. |
grant | yes | | | PDA ["grant", model, target_enclave] | The Grant, created here or written over. |
system_program | | | | 11111111111111111111111111111111 | The System program. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
- Checks. The signer is the model's owner (
Unauthorized). The model is Sealed or Live (ModelNotSealed). The record passed is the one the target Enclave names and still states the Enclave's hardware type and measurement (InvalidEnclave), and it is valid and unexpired (InvalidAttestation). The measurement is in the model's allowed measurements (MeasurementNotAllowed). The wrapped key is 105 bytes and starts with byte 1 (InvalidWrappedKey).
- Effects. The Grant holds the wrapped key, the owner as
granted_by and the current slot, and is not revoked. A Grant that existed for this model and enclave is written over, which also lifts a revocation. The model's status is Live. Emits GrantChanged and ModelStatusChanged.
grant_by_enclave#
Writes a Grant from an enclave that holds one to another enclave. The owner does not sign.
| Argument | Type |
|---|
wrapped_key | bytes |
| Account | Writable | Signer | Optional | Address | Is |
|---|
signing_key | | yes | | | The signing key of the enclave that passes the key on. |
payer | yes | yes | | | Pays the Grant's rent. |
config | | | | PDA ["config"] | The protocol's Config. |
model | yes | | | PDA ["model", model.name] | The Model. |
source_enclave | | | | PDA ["enclave", signing_key] | The Enclave that passes the key on. |
source_grant | | | | PDA ["grant", model, source_enclave] | Its own Grant for this model, not revoked. |
source_attestation_record | | | | | Its attestation record. |
target_enclave | | | | PDA ["enclave", target_enclave.signing_key] | The Enclave the grant is made to. |
target_attestation_record | | | | | That enclave's attestation record. |
grant | yes | | | PDA ["grant", model, target_enclave] | The Grant, created here or written over. |
system_program | | | | 11111111111111111111111111111111 | The System program. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
- Checks. The signer is the source enclave's signing key (
Unauthorized). The model is Live (ModelNotLive). The source and the target are different enclaves (InvalidEnclave). The source holds a Grant for this model that is not revoked (GrantRequired). Both records are the ones their Enclaves name, are valid and are unexpired (InvalidEnclave, InvalidAttestation). Both measurements are in the model's allowed measurements (MeasurementNotAllowed). The wrapped key is 105 bytes and starts with byte 1 (InvalidWrappedKey).
- Effects. The Grant holds the wrapped key, the source Enclave's address as
granted_by and the current slot. Emits GrantChanged.
revoke_grant#
Marks a Grant revoked.
| Account | Writable | Signer | Optional | Address | Is |
|---|
owner | | yes | | | The model's owner. |
model | | | | PDA ["model", model.name] | The Model. |
grant | yes | | | PDA ["grant", model, grant.enclave] | The Grant to revoke. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
- Checks. The signer is the model's owner (
Unauthorized). The Grant belongs to the model.
- Effects. The Grant's
revoked is true. open_call refuses the enclave for this model, and the enclave cannot pass the key on. Calls already open with it settle. Emits GrantChanged.
open_call#
Creates a Call and moves the model's price into its escrow.
| Argument | Type |
|---|
nonce | u64 |
input_hash | [u8; 32] |
| Account | Writable | Signer | Optional | Address | Is |
|---|
caller | yes | yes | | | The caller. Pays the price and the Call's rent. |
config | | | | PDA ["config"] | The protocol's Config. |
model | | | | PDA ["model", model.name] | The Model. |
enclave | | | | PDA ["enclave", enclave.signing_key] | The Enclave chosen to answer. |
attestation_record | | | | | The enclave's attestation record. |
grant | | | | PDA ["grant", model, enclave] | That enclave's Grant for the model, not revoked. |
call | yes | | | PDA ["call", caller, nonce] | The Call, created here. |
mint | | | yes | | The model's price mint. Only for a price in a mint. |
caller_tokens | yes | | yes | | The caller's token account for the mint. Only for a price in a mint. |
escrow_tokens | yes | | yes | | The Call's associated token account for the mint, created here. Only for a price in a mint. |
token_program | | | yes | TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA | The SPL Token program. Only for a price in a mint. |
associated_token_program | | | yes | ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL | The Associated Token program. Only for a price in a mint. |
system_program | | | | 11111111111111111111111111111111 | The System program. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
nonce is any number the caller has not used before: it gives the Call its address, ["call", caller, nonce]. For a price in SOL the five token accounts and programs are left out.
- Checks. The model is
Live (ModelNotLive). The enclave's Grant for the model is not revoked (GrantRequired). The record is the one the Enclave names, valid and unexpired (InvalidEnclave, InvalidAttestation), and its measurement is allowed (MeasurementNotAllowed). The operator share plus the protocol share is at most 10,000 (InvalidConfig). For a price in a mint: the mint is the model's price mint, the caller's token account holds that mint, and the escrow account is the Call's associated token account (InvalidTokenAccount).
- Effects. The Call holds the caller, the model, the enclave, the input hash, the price and mint, the owner, the operator, the fee recipient and both shares as they are now, the opening slot and the deadline slot (the opening slot plus the Config's
call_deadline_slots). The price moves from the caller into the escrow. Emits CallOpened.
settle_call#
Checks the enclave's signature, writes the Receipt and pays out the escrow, in one instruction.
| Argument | Type |
|---|
output_hash | [u8; 32] |
signature | [u8; 64] |
ed25519_instruction_index | u16 |
| Account | Writable | Signer | Optional | Address | Is |
|---|
payer | yes | yes | | | Pays the Receipt's rent and the transaction fee. The enclave's runtime sends it. |
config | | | | PDA ["config"] | The protocol's Config. |
model | yes | | | PDA ["model", model.name] | The Model. |
enclave | yes | | | PDA ["enclave", enclave.signing_key] | The Enclave that answered. |
attestation_record | | | | | The enclave's attestation record. |
call | yes | | | PDA ["call", call.caller, call.nonce] | The Call being settled. |
receipt | yes | | | PDA ["receipt", call] | The Receipt, created here. |
caller | yes | | | | The call's caller. |
owner | yes | | | | The owner recorded in the call. |
operator | yes | | | | The operator recorded in the call. |
fee_recipient | yes | | | | The fee recipient recorded in the call. |
instructions | | | | Sysvar1nstructions1111111111111111111111111 | The Instructions sysvar. |
escrow_tokens | yes | | yes | | The Call's associated token account. Only for a price in a mint. |
owner_tokens | yes | | yes | | The owner's associated token account. Only for a price in a mint. |
operator_tokens | yes | | yes | | The operator's associated token account. Only for a price in a mint. |
protocol_tokens | yes | | yes | | The fee recipient's associated token account. Only for a price in a mint. |
caller_tokens | yes | | yes | | A token account of the caller's for the mint. Only for a price in a mint. |
token_program | | | yes | TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA | The SPL Token program. Only for a price in a mint. |
system_program | | | | 11111111111111111111111111111111 | The System program. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
The transaction carries an Ed25519 program instruction before settle_call, and ed25519_instruction_index is its index. That instruction verifies exactly one signature and carries the signature, the enclave's signing key and the 114-byte receipt message in its own data.
- Checks. The call is
Open (CallNotOpen). The current slot is at most the deadline slot (CallDeadlinePassed). The record is the one the Enclave names, valid and unexpired (InvalidEnclave, InvalidAttestation), and its measurement is allowed (MeasurementNotAllowed). The Ed25519 instruction at the index matches the signature, the enclave's signing key and the message built from the Call's address, its input hash and output_hash (InvalidSignature). The caller, owner, operator and fee recipient are the ones the Call recorded (InvalidRecipient). For a price in a mint: the escrow, owner, operator and protocol accounts are associated token accounts of the right wallet and mint (InvalidTokenAccount). The escrow holds the price (InsufficientEscrow).
- Effects. The operator receives
price × operator_share_bps / 10,000, rounded down. The fee recipient receives price × protocol_share_bps / 10,000, rounded down. The owner receives the rest. The Receipt holds the call, model, enclave, both hashes, the signature, the slot and the three payments. The Call's status is Settled, and the model's and the enclave's calls_settled rise by one. For a price in a mint, the escrow token account is closed and its rent returns to the caller. Emits CallSettled.
refund_call#
Returns the escrow of a call that did not settle by its deadline. Anyone can send it; the escrow goes to the caller.
| Account | Writable | Signer | Optional | Address | Is |
|---|
actor | | yes | | | Whoever sends the refund: the caller or anyone else. |
call | yes | | | PDA ["call", call.caller, call.nonce] | The Call being refunded. |
caller | yes | | | | The call's caller. Receives the escrow. |
escrow_tokens | yes | | yes | | The Call's associated token account. Only for a price in a mint. |
caller_tokens | yes | | yes | | A token account of the caller's for the mint. Only for a price in a mint. |
token_program | | | yes | TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA | The SPL Token program. Only for a price in a mint. |
event_authority | | | | PDA ["__event_authority"] | The program's event authority. |
program | | | | | The Voynich program. |
- Checks. The call is
Open (CallNotOpen). The current slot is past the deadline slot (CallNotRefundable). The caller account is the Call's caller (InvalidRecipient). For a price in a mint: the escrow is the Call's associated token account and the destination is a token account of the caller's for the mint (InvalidTokenAccount).
- Effects. The whole price returns to the caller. The Call's status is
Refunded. For a price in a mint, the escrow token account is closed and its rent returns to the caller. Emits CallRefunded.