Skip to content

[Bug]: ASP fails to synchronize with blockchain and causes notes to be lost #1

@KevinMB0220

Description

@KevinMB0220

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

  1. 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)
  2. 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).

  3. 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:

  1. Match discriminators for shielded_swap, shielded_mint, and shielded_burn in addition to shielded_deposit.
  2. Parse the transaction data for these instructions to extract all new commitments.
  3. Insert these commitments into the database sequentially, matching the exact order they are added by the smart contract.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions