Errors
Every error the program returns, with its number, its name and exactly when it happens, plus the errors the clients raise before anything is sent.
A failed Lean Key instruction fails the whole transaction and changes nothing. There are three sources of errors: Lean Key's own custom errors, standard Solana program errors that the program returns, and errors from the programs it calls (System Program, SPL Token, Token-2022). The clients add a fourth kind: refusals before anything is signed or sent.
Custom program errors
The program's custom errors are numbered from 6001 (6000 is not used). Solana reports them in the transaction error and in the logs like this, for instruction index 1:
{"InstructionError":[1,{"Custom":6005}]}
Program TwoKhewkScEnH75rbs9nC5ScrsFQT93DrHsSSZvpVHn failed: custom program error: 0x1775
Names and messages are those in PROGRAM_ERRORS (packages/core/src/instructions.ts); "When" is what the program checks (program/Twokey/Program.lean).
| Code | Hex | Name | Message (clients) | When |
|---|---|---|---|---|
| 6001 | 0x1771 | NotOwner | The signer is not this vault's owner. | Account 0 is not the owner stored in the vault (offset 2). Checked in every instruction except InitVault, before any signature work. |
| 6002 | 0x1772 | NotVault | That account is not an open Lean Key vault. | Account 1 is not owned by this program, or is not 91 bytes, or its version byte is not 1. Also if, after InitVault's allocation, the account is not 91 bytes. |
| 6003 | 0x1773 | AlreadyOpen | A vault already exists at this address. | InitVault: the address is no longer owned by the System Program, or already holds data. Every vault, open or closed, gives this. |
| 6004 | 0x1774 | BadAddress | The vault address does not match its seeds. | InitVault: the vault account's address is not the SHA-256 derivation of "vault", owner, vault_id, bump and the program id. A wrong bump or a keypair address gives this. |
| 6005 | 0x1775 | BadSignature | The hash signature does not match the vault's current one-time key. | The WOTS+ signature does not verify for the intent the program rebuilt, under the vault's stored pk_hash. Any changed field (amount, destination, asset, next key), a signature for an older key index, a signature from another seed or for another vault, and the clients' all-zero placeholder all give this. |
| 6006 | 0x1776 | BelowRent | The vault must keep its rent-exempt minimum. | WithdrawSol: the vault holds less than its rent-exempt minimum, or the amount is more than the balance above it. CloseVault: the vault holds less than its minimum. |
| 6007 | 0x1777 | TransferHook | Mints with a transfer hook are not supported in v1. | WithdrawToken: the mint has a Token-2022 TransferHook extension (type 14) whose program id is not all zero. |
| 6008 | 0x1778 | BadTokenAccount | A token account is not what the intent needs: wrong token program, too short, a different mint, or not owned by the vault. | The vault's token account is not owned by the given token program, is shorter than 165 bytes, holds another mint than account 4 (WithdrawToken), or does not name the vault as its owner. Also WithdrawToken when the destination token account is not owned by the token program. |
| 6009 | 0x1779 | BadMint | The mint is not a mint of this token program, is too short, or has a malformed transfer-hook extension. | WithdrawToken: the mint account is not owned by the given token program, is shorter than 82 bytes, or has a TransferHook extension entry shorter than 64 bytes or running past the end of the account. A mint that differs from the token account's mint is 6008, not 6009. |
| 6010 | 0x177a | ZeroAmount | The amount must be greater than zero. | WithdrawSol or WithdrawToken with amount 0. |
| 6011 | 0x177b | ZeroNextKey | The next key hash must not be empty. | next_pk_hash (or InitVault's pk_hash_0) is 32 zero bytes. |
Standard program errors
lean-svm returns Solana's standard program errors as a value in the high 32 bits of the return register. Solana reports them by name:
{"InstructionError":[1,"MissingRequiredSignature"]}
| Name | Returned value | When Lean Key returns it |
|---|---|---|
| InvalidInstructionData | 0x0000000300000000 | Empty instruction data; an unknown first byte; a data length that is not exactly 42, 665, 666 or 657 for its instruction. |
| InvalidAccountData | 0x0000000400000000 | An account that must be writable is not (owner in InitVault, vault, destination, token accounts); an account repeats another where that is not allowed (only the destination may repeat the owner). |
| IncorrectProgramId | 0x0000000700000000 | InitVault's account 2 is not the System Program; the token program account is neither SPL Token nor Token-2022. |
| MissingRequiredSignature | 0x0000000800000000 | Account 0 (the owner) did not sign. |
| NotEnoughAccountKeys | 0x0000000b00000000 | The number of accounts is not exactly 3, 3, 6, 5 or 3 for the instruction, more or fewer. |
| UnsupportedSysvar | 0x0000001100000000 | The Rent or Clock sysvar cannot be read, or the rent exemption threshold is neither 2.0 nor 1.0. |
| ArithmeticOverflow | 0x0000001800000000 | A checked 64-bit sum or product would overflow: the destination's new balance, the next key index, or the rent computation. |
Errors from called programs
These come from the System Program or the token program during a cross-program invocation, and Solana reports them as that program's errors.
| Situation | Typical cause |
|---|---|
InitVault rent top-up fails | The owner does not have enough lamports to fund the vault's rent-exempt minimum. |
WithdrawToken transfer fails | The vault's token account holds fewer tokens than the amount; the destination token account is for another mint; decimals does not match the mint; an account is frozen. |
CloseTokenAccount fails | The token account still holds tokens. |
The model the proofs are about folds all token-program refusals into one error; see Trust boundaries.
Errors from the clients
The CLI, the extension and the site use packages/core, which refuses many requests before any one-time key is used. None of these sends a transaction.
| Message | Meaning |
|---|---|
Refused before signing, no one-time key used: … | The simulation with the placeholder signature stopped somewhere other than BadSignature (6005), so the real signature would not help. The reason follows (for example NotOwner (6001)). |
This vault's owner is X, not Y. | The owner you gave is not the vault's owner. |
The vault is at key #k, not #j. Refresh and try again. | The key index you saw is out of date. |
Only N lamports are above the vault's rent-exempt minimum. | Amount larger than the withdrawable balance. |
The destination is an empty account: send at least N lamports so it is rent-exempt. | The runtime would reject a new account left below its rent minimum. |
The vault holds none of this token. / The vault holds N base units of this token. | No such token account, or not enough. |
The vault's token account is frozen by the mint's freeze authority. / The recipient's token account is frozen. | The transfer would fail in the token program. |
This Token-2022 mint has a transfer hook. Lean Key refuses those. | The program would refuse it (6007). |
Withdraw the tokens first: only an empty token account can be closed. | The token program would refuse the close. |
This vault is already closed. | CloseVault on a vault whose closed flag is set. |
Key #k of this vault already signed a different intent. … | The journal rule: this key index already signed another intent that has not landed. Only that one can be sent. See Recovery and safety. |
Signed, but the simulation failed: … Retry the same intent once the cause is fixed. | The key was used and the intent is in the journal, but the transaction would fail, so it was not sent. |
The transaction expired before it landed. Nothing moved; it can be sent again. | The blockhash expired. Only the same intent can be sent again. |
Reading an error
explainError in packages/core/src/decode.ts turns a transaction error and its logs into one line, for example BadSignature (6005): The hash signature does not match the vault's current one-time key. The CLI prints this after error: and exits with status 1. With --json it prints the same line as JSON:
{"error":"Signed, but the simulation failed: BadSignature (6005): The hash signature does not match the vault's current one-time key. Retry the same intent once the cause is fixed."}