Bug: ASP fails to synchronize with blockchain and causes notes to be lost
Description
The Anonymous Service Provider (ASP) is currently failing to synchronize properly with the Solana blockchain, leading to a critical issue where user notes (commitments) become permanently unusable ("lost") in the frontend interface.
After a deep evaluation of the architecture, it was found that the root cause lies in the ASP's Solana indexer (asp/src/sync/solana.rs).
Root Cause
-
Incomplete Transaction Indexing: The process_transaction function in the ASP currently only listens for the global:shielded_deposit Anchor discriminator.
// asp/src/sync/solana.rs
let preimage = b"global:shielded_deposit";
let disc = hashv(&[preimage]).to_bytes()[..8].to_vec();
It completely ignores other critical instructions that generate new commitments, specifically:
shielded_swap (generates new_commitment and change_commitment)
shielded_mint (generates 3 new commitments)
shielded_burn (generates 2 new commitments)
-
Merkle Tree Desynchronization: Because the ASP ignores these events, it fails to insert the newly created commitments into its local SQLite database (sunset_asp.db). The ASP calculates the next leaf_index based on its database count (state.db.get_leaf_count()). Since it misses events, the ASP's leaf count falls behind the next_leaf_index on the smart contract. When the ASP attempts to assign an index for a new transaction, it uses an outdated index, causing the Solana transaction to revert (duplicate index error).
-
Why Notes are Lost:
- When a user performs a swap or mint, the frontend SDK optimistically saves the pending notes in
localStorage without a leafIndex.
- The SDK subsequently calls
syncNotes() to ask the ASP for the assigned leafIndex of these new notes.
- Because the ASP ignored the on-chain event, it returns a null/undefined response.
- In ZK cryptography, a note without its exact
leafIndex in the Merkle tree is completely unspendable. The UI cannot use these notes, rendering the funds effectively "lost" from the user's perspective.
Proposed Solution
Update the synchronization logic in asp/src/sync/solana.rs to:
- Match discriminators for
shielded_swap, shielded_mint, and shielded_burn in addition to shielded_deposit.
- Parse the transaction data for these instructions to extract all new commitments.
- Insert these commitments into the database sequentially, matching the exact order they are added by the smart contract.
Bug: ASP fails to synchronize with blockchain and causes notes to be lost
Description
The Anonymous Service Provider (ASP) is currently failing to synchronize properly with the Solana blockchain, leading to a critical issue where user notes (commitments) become permanently unusable ("lost") in the frontend interface.
After a deep evaluation of the architecture, it was found that the root cause lies in the ASP's Solana indexer (
asp/src/sync/solana.rs).Root Cause
Incomplete Transaction Indexing: The
process_transactionfunction in the ASP currently only listens for theglobal:shielded_depositAnchor discriminator.It completely ignores other critical instructions that generate new commitments, specifically:
shielded_swap(generatesnew_commitmentandchange_commitment)shielded_mint(generates 3 new commitments)shielded_burn(generates 2 new commitments)Merkle Tree Desynchronization: Because the ASP ignores these events, it fails to insert the newly created commitments into its local SQLite database (
sunset_asp.db). The ASP calculates the nextleaf_indexbased on its database count (state.db.get_leaf_count()). Since it misses events, the ASP's leaf count falls behind thenext_leaf_indexon the smart contract. When the ASP attempts to assign an index for a new transaction, it uses an outdated index, causing the Solana transaction to revert (duplicate index error).Why Notes are Lost:
localStoragewithout aleafIndex.syncNotes()to ask the ASP for the assignedleafIndexof these new notes.leafIndexin the Merkle tree is completely unspendable. The UI cannot use these notes, rendering the funds effectively "lost" from the user's perspective.Proposed Solution
Update the synchronization logic in
asp/src/sync/solana.rsto:shielded_swap,shielded_mint, andshielded_burnin addition toshielded_deposit.