Skip to content

Conversation

@bc1cindy
Copy link

Hey guys, I talked to Davidson and we agreed I'd implement this RPC.

This PR implements the verifyutxochaintipinclusionproof RPC method to verify utreexo accumulator proofs for chain tip UTXOs. It's based on the utreexod's reference implementation and allows clients to cryptographically verify UTXO inclusion without maintaining the full UTXO set.

  • Parses hex-encoded proofs from utreexod's proveutxochaintipinclusion RPC
  • Validates proof was generated at current chain tip (rejects stale proofs with clear error)
  • Creates a temporary pollard from the current accumulator roots using Pollard::from_roots()
  • Uses pollard.verify() to cryptographically verify inclusion by reconstructing the merkle path from proven hashes through the provided proof hashes up to the known roots
  • Returns true for valid proofs, false for invalid proofs and errors for malformed input.

Running:

RPC: ./target/release/floresta-cli --network regtest verifyutxochaintipinclusionproof <proof>

Test: uv run tests/test_runner.py -k verifyutxochaintipinclusionproof

Tested with proofs generated from utreexod proveutxochaintipinclusion RPC in regtest mode.

Captura de Tela 2026-01-30 às 17 09 18 Captura de Tela 2026-01-30 às 17 07 47 Captura de Tela 2026-01-30 às 17 06 54

@bc1cindy bc1cindy marked this pull request as ready for review January 30, 2026 20:12
Copy link
Collaborator

@moisesPompilio moisesPompilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the name of this RPC be shorter, like verifyutxoproof?

@moisesPompilio moisesPompilio added enhancement New feature or request new rpc This issue/PR implements a new json-rpc endpoint documentation Improvements or additions to documentation Integration Issues related to our integration tests labels Jan 30, 2026
@Davidson-Souza
Copy link
Member

Can the name of this RPC be shorter, like verifyutxoproof?

This is the RPC's name on utreexod

@bc1cindy bc1cindy force-pushed the rpc/verifyutxochaintipinclusionproof branch 2 times, most recently from 6c51864 to 04fbc6e Compare January 31, 2026 23:55
@bc1cindy
Copy link
Author

bc1cindy commented Feb 1, 2026

thanks for the review! @moisesPompilio

done!

@bc1cindy bc1cindy force-pushed the rpc/verifyutxochaintipinclusionproof branch from 04fbc6e to f977dbc Compare February 1, 2026 22:53
@bc1cindy
Copy link
Author

bc1cindy commented Feb 1, 2026

thanks for the review! @csgui

initially, I chose to remain faithful to the utreexod RPC implementation, but the validation of the proof size is important and it doesn't exist in utreexod, as well as explicit error handling, but all done now. Also added a test for the proof size.

furthermore, I realized that pollard::from_roots received 4 roots but internally only preserved 2, and this was causing errors in the verification of some proofs, so I switched to stump.verify, which is working well.

Captura de Tela 2026-02-01 às 20 09 39 Captura de Tela 2026-02-01 às 20 06 37 Captura de Tela 2026-02-01 às 20 06 56 Captura de Tela 2026-02-01 às 20 07 42

@bc1cindy bc1cindy force-pushed the rpc/verifyutxochaintipinclusionproof branch 2 times, most recently from 04435ee to 882aec3 Compare February 1, 2026 23:43
@bc1cindy bc1cindy force-pushed the rpc/verifyutxochaintipinclusionproof branch 2 times, most recently from 8e354d2 to 93274ab Compare February 3, 2026 14:56
@bc1cindy
Copy link
Author

bc1cindy commented Feb 3, 2026

thanks guys!

addressed all feedback : added InvalidProof error variant for stale/verification failures, bounds checking with read_bounded_len / MAX_INPUTS_PER_BLOCK/MAX_PROOF_HASHES, updated docs, trailing bytes check, and expanded tests with utreexod integration (utreexod running locally, it requires bdkwallet support)

ready for re-review! @moisesPompilio @csgui

@bc1cindy bc1cindy force-pushed the rpc/verifyutxochaintipinclusionproof branch from 93274ab to 8e2deea Compare February 3, 2026 16:14
Copy link
Collaborator

@moisesPompilio moisesPompilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now we don't use simple assert statements in the integration tests; we have to use the asserts from FlorestaTestFramework. I marked some asserts and suggested how they should use the FlorestaTestFramework asserts, but check FlorestaTestFramework for which ones you need to use instead of the simple assert calls you added.

@bc1cindy bc1cindy force-pushed the rpc/verifyutxochaintipinclusionproof branch 3 times, most recently from 73ca04f to 79589d2 Compare February 6, 2026 16:06
@bc1cindy
Copy link
Author

bc1cindy commented Feb 6, 2026

hey @moisesPompilio

I improved the test as a full integration using the existing frameworks. Utreexod is instantiated via add_node() (no external dependency), coinbase txids are obtained via getblock/getblockhash (no bdkwallet), and shutil.rmtree cleans up data between runs. It runs on CI without manual setup.

@bc1cindy bc1cindy force-pushed the rpc/verifyutxochaintipinclusionproof branch from 79589d2 to 1a23b57 Compare February 6, 2026 19:28
@bc1cindy
Copy link
Author

bc1cindy commented Feb 6, 2026

applied CI lint fix

@bc1cindy bc1cindy force-pushed the rpc/verifyutxochaintipinclusionproof branch from 1a23b57 to f573885 Compare February 6, 2026 21:24
@bc1cindy
Copy link
Author

bc1cindy commented Feb 6, 2026

thanks! @moisesPompilio

sugestions applied

@bc1cindy bc1cindy force-pushed the rpc/verifyutxochaintipinclusionproof branch 2 times, most recently from ff1081d to 0fdd2e0 Compare February 6, 2026 23:02
@bc1cindy
Copy link
Author

bc1cindy commented Feb 6, 2026

updated commit descriptions

@bc1cindy bc1cindy force-pushed the rpc/verifyutxochaintipinclusionproof branch 2 times, most recently from 8d469cd to 7fc11ea Compare February 11, 2026 00:17
@bc1cindy
Copy link
Author

extracted ChainTipInclusionProof struct with Decodable impl into block_proof.rs and added 3 unit tests

updated integration test bash tests/run.sh -k verifyutxochaintipinclusionproof

Implements utreexo accumulator proof UTXO verification for chain tip, based on the utreexod's reference implementation. This allows clients to cryptographically verify UTXO inclusion without maintaining the full UTXO set.

- Parses hex-encoded proofs from utreexod's proveutxochaintipinclusion
- Validates proof was generated at current chain tip (rejects stale proofs)
- Verifies cryptographic proof against the accumulator state
- Makes MAX_INPUTS_PER_BLOCK and MAX_PROOF_HASHES public for DoS bounds
- Adds InvalidProof error variant with appropriate HTTP/JSON-RPC codes

Returns true for valid proofs, false for well-formed but invalid proofs. Malformed or stale proofs return specific error types.
@bc1cindy bc1cindy force-pushed the rpc/verifyutxochaintipinclusionproof branch from 7fc11ea to 139aaa5 Compare February 11, 2026 03:26
Adds CLI command to verify utreexo proofs, making the RPC accessible via floresta-cli.

Includes comprehensive documentation with usage examples showing both valid and invalid proof scenarios to help users understand expected behavior.
End-to-end test using florestad and utreexod that validates:
- Input rejection: invalid hex, oversized proofs, empty input, truncated data
- Valid proofs: generates and verifies proofs for all mined coinbase UTXOs
- Invalid proofs: tampered data returns false, trailing bytes and wrong
  block hash return appropriate errors

Also adds RPC bindings for both floresta (verifyutxochaintipinclusionproof) and utreexo (proveutxochaintipinclusion) in the test framework.
@bc1cindy bc1cindy force-pushed the rpc/verifyutxochaintipinclusionproof branch from 139aaa5 to e7f3f40 Compare February 11, 2026 03:39
@bc1cindy
Copy link
Author

verbosity added

thanks! @jaoleal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request Integration Issues related to our integration tests new rpc This issue/PR implements a new json-rpc endpoint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants