webb-tools/webb.js

[Bug] VAnchor proof fails with non-input leaves

AhmedKorim opened this issue · 0 comments

Describe the bug

VAnchor proof is invalid while prooving against non-input leaves

  • When the proof is valid?

    • With default input utxos
      Given the input Utxos, all are default, the root setup is [ActiveChain TreeRoot, Neighboring Tree Root], and the
      amounts match the role Sum(I) + Public amount = Sum(O).

    • All input commitments are on the leaves

To Reproduce
Steps to reproduce the behavior:
1- Construct a Merkle tree with already existing commitments.
2- Generate a valid VAnchor setup
- Sum of Input amount + public amount =Sum of output amount
- While the input has a non-default UTXO the commitment of that output should be in the MerkleTree

Expected behavior

  • The proof should pass given a valid proof setup
  • Valid roots, The root sets' first element matches the root of the supplied leaves, And the second element is the neighbor MT root
  • Input Utxos commitments are in the tree with the right indices specified
  • Sum(input Utxos) + public amount = Sum(output Utxos)
  • the proof shouldn't just be valid if the input commitment (input Utxos) is the only leaves existing on the tree

Additional context
Tests
Check the branch ahmed/fix-vanchor-n-plus-withdraw

DApp flow
Deposit flow (2-2-2 fixtures)

  • Crate a two empty Utxo for input amont =0 index =0
  • Create the output Utxos [Utxo with full amount , Default Utxo]
  • Fetch the tree root, the neighbour root and construct the root setup
  • Use empty leaves map to generate the proof - After insertion Mutate the Non-default utxo index
    This is always passing

Withdraw flow (2-2-2 fixtures)

  • For a given note - Fetch the leaves up to the leave
  • Construct a Merkle tree and inset the leaves to get the Merkle root
  • Fetch the neighbor root from the chain
  • The output is calculated based on the amount to withdraw Input + (-amount) = Output
    This is passing for the first time only