Program Errors
Error codes from the zklsol program
Program Errors
Section titled “Program Errors”Error codes returned by the zklsol on-chain program.
Error Code Reference
Section titled “Error Code Reference”General Errors
Section titled “General Errors”| Code | Name | Description |
|---|---|---|
| 6000 | Unauthorized | Signer is not authorized for this operation |
| 6001 | InvalidAmount | Amount is invalid (zero or negative) |
| 6002 | InvalidDepositSize | Amount doesn’t match allowed deposit sizes |
| 6003 | MathOverflow | Arithmetic overflow occurred |
| 6004 | AccountNotInitialized | Required account not initialized |
Merkle Tree Errors
Section titled “Merkle Tree Errors”| Code | Name | Description |
|---|---|---|
| 6010 | MerkleTreeFull | Tree has reached maximum capacity |
| 6011 | InvalidMerkleDepth | Depth must be 32 |
| 6012 | InvalidMerkleRoot | Root doesn’t match on-chain state |
| 6013 | MerkleTreePaused | Tree is temporarily paused |
| 6014 | MerkleTreeClosed | Tree is permanently closed |
Proof Errors
Section titled “Proof Errors”| Code | Name | Description |
|---|---|---|
| 6020 | InvalidProof | ZK proof verification failed |
| 6021 | InvalidCommitment | Commitment format invalid |
| 6022 | CommitmentNotFound | Commitment doesn’t exist in tree |
| 6023 | ProofLengthMismatch | Proof is wrong length (expected 256 bytes) |
Nullifier Errors
Section titled “Nullifier Errors”| Code | Name | Description |
|---|---|---|
| 6030 | NullifierAlreadySpent | This deposit was already withdrawn |
| 6031 | InvalidNullifierHash | Nullifier hash format invalid |
Revert Errors
Section titled “Revert Errors”| Code | Name | Description |
|---|---|---|
| 6040 | CannotRevert | Deposit cannot be reverted |
| 6041 | AlreadyIndexed | Deposit was indexed, use normal withdraw |
| 6042 | NotDepositor | Only original depositor can revert |
| 6043 | RevertWindowExpired | Revert time window has passed |
Affiliate Errors
Section titled “Affiliate Errors”| Code | Name | Description |
|---|---|---|
| 6050 | AffiliateAlreadyExists | Affiliate code already registered |
| 6051 | AffiliateNotFound | Affiliate account doesn’t exist |
| 6052 | InvalidFeeShare | Fee share must be 0-10000 bps |
| 6053 | NoEarningsToWithdraw | No pending earnings available |
Swap Errors
Section titled “Swap Errors”| Code | Name | Description |
|---|---|---|
| 6060 | SwapFailed | Jupiter swap execution failed |
| 6061 | SlippageExceeded | Output less than minimum |
| 6062 | InvalidSwapRoute | Swap route data invalid |
| 6063 | SwapBufferNotFound | Swap buffer account missing |
LUT Errors
Section titled “LUT Errors”| Code | Name | Description |
|---|---|---|
| 6070 | LutNotFound | Address Lookup Table doesn’t exist |
| 6071 | LutNotActive | LUT is deactivated |
| 6072 | LutFull | LUT has max addresses |
| 6073 | CooldownNotComplete | Must wait before closing LUT |
Error Handling
Section titled “Error Handling”import { AnchorError } from '@coral-xyz/anchor';
try { await program.methods.withdraw(/* ... */).rpc();} catch (err) { if (err instanceof AnchorError) { switch (err.error.errorCode.code) { case 'NullifierAlreadySpent': console.log('Already withdrawn this deposit'); break; case 'InvalidProof': console.log('Proof verification failed - regenerate proof'); break; case 'InvalidMerkleRoot': console.log('Merkle root changed - refetch and retry'); break; default: console.log('Program error:', err.error.errorMessage); } } else { console.log('Transaction error:', err); }}Common Error Scenarios
Section titled “Common Error Scenarios””NullifierAlreadySpent”
Section titled “”NullifierAlreadySpent””Cause: Attempting to withdraw a deposit that was already withdrawn.
Solution:
- Check your local records - deposit may be marked spent
- If records are lost, the funds are already withdrawn
”InvalidProof”
Section titled “”InvalidProof””Cause: The ZK proof failed verification.
Solutions:
- Ensure nullifier and secret match the original deposit
- Verify Merkle proof path is current
- Check that all inputs are correctly formatted
- Regenerate proof with fresh data
”InvalidMerkleRoot”
Section titled “”InvalidMerkleRoot””Cause: The Merkle root in your proof is outdated.
Solution:
- Fetch the current Merkle root
- Regenerate the proof with the new root
- Retry within a reasonable time window
”MerkleTreeFull”
Section titled “”MerkleTreeFull””Cause: The tree has 2³² deposits (extremely rare).
Solution:
- Use a different deposit size (different tree)
- Wait for a new tree to be created
”CannotRevert”
Section titled “”CannotRevert””Cause: Deposit was indexed or nullifier was spent.
Solutions:
- If indexed: Use normal withdrawal flow
- If spent: Funds were already withdrawn
Debugging Tips
Section titled “Debugging Tips”-
Log the full error:
console.log(JSON.stringify(err, null, 2)); -
Check transaction logs:
const tx = await connection.getTransaction(signature);console.log(tx.meta.logMessages); -
Verify account states:
const nullifierPda = getNullifierHashPda(mint, depth, nullifierHash);const exists = await connection.getAccountInfo(nullifierPda);console.log('Nullifier spent:', exists !== null);