Skip to content

feat(p2p): implement BIP-0183 (Utreexo Peer Services)#5009

Draft
luisschwab wants to merge 16 commits into
rust-bitcoin:masterfrom
luisschwab:feat/utreexo
Draft

feat(p2p): implement BIP-0183 (Utreexo Peer Services)#5009
luisschwab wants to merge 16 commits into
rust-bitcoin:masterfrom
luisschwab:feat/utreexo

Conversation

@luisschwab

@luisschwab luisschwab commented Sep 18, 2025

Copy link
Copy Markdown
Contributor

This (draft) PR implements BIP-0183: Utreexo - Peer Services on the p2p crate.

Still missing a few TODOs. I'll keep this as a draft until the Utreexo BIPs get finalized.

Changelog

  • Add NODE_UTREEXO service bit
  • Add NODE_UTREEXO_ARCHIVE service bit
  • Add CompactLeafData type
  • Add ReconstructableScriptTag type
  • Add ReconstructableScript type
  • Add TTLInfo type
  • Add UtreexoTTL type
  • Add uproof message
  • Add getuproof message
  • Add uttls message
  • Add getuttls message
  • Add usummary message
  • Add utreexotx message
  • Add uroot message
  • Add geturoot message
  • Implement Encodable for all
  • Implement Decodable for all
  • Implement Arbitrary for all
  • Add missing backticks to message command string comments

TODO

  • Add the respective fuzz targets
  • Add unit tests (pending test vector addition to BIP-0183)

@github-actions github-actions Bot added the C-p2p label Sep 18, 2025
@luisschwab luisschwab marked this pull request as draft September 18, 2025 22:37
@luisschwab

Copy link
Copy Markdown
Contributor Author

I wonder if it's correct to use Vec<u8> instead of ScriptBuf. If I use ScriptBuf I need to use a generic, which would percolate up until NetworkMessage, which would be a big breaking change.

@Davidson-Souza

Copy link
Copy Markdown

I wonder if it's correct to use Vec<u8> instead of ScriptBuf. If I use ScriptBuf I need to use a generic, which would percolate up until NetworkMessage, which would be a big breaking change.

You mean for leaf data? That is always a script pubkey, can't you use the tag for it and avoid being generic?

@luisschwab

Copy link
Copy Markdown
Contributor Author

On ReconstructableScript. If the tag is 0x00 we need to send the actual script (see https://github.com/bitcoin/bips/blob/bd1e2425872450b4b9d80cdcb47874d9659a3bda/bip-0183.md#reconstructable-script):

pub struct ReconstructableScript {
    /// The kind of locking script the UTXO is locked to.
    pub tag: ReconstructableScriptTag,
    /// The actual script, if [`ReconstructableScriptTag`] is of kind `Other`.
    pub script: Option<Vec<u8>>,
}

@Davidson-Souza

Copy link
Copy Markdown

I've implemented this. However, you can use ScriptBuff<ScriptPubkey> safely.

@apoelstra

Copy link
Copy Markdown
Member

Can you just use a Rust enum? This looks like a manual implementation of a tagged union, which is exactly what a Rust enum is.

Comment thread p2p/src/message_utreexo.rs Outdated
@luisschwab

luisschwab commented Sep 19, 2025

Copy link
Copy Markdown
Contributor Author

Can you just use a Rust enum? This looks like a manual implementation of a tagged union, which is exactly what a Rust enum is.

Makes sense, this would also prevent the illegal state where the tag is != 0x00 and a script exists.

@rockcoolsaint

Copy link
Copy Markdown
Contributor

For scripts, is the script always a ScriptPubKey (locking script)? Are there any constraints (size, canonicality) enforced?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please don't post LLM output like this. It is obviously useless to complain about unimplemented!() calls in a draft PR. I did not read the rest of your paste.

@luisschwab luisschwab force-pushed the feat/utreexo branch 6 times, most recently from 0293e71 to 14fd2a2 Compare November 1, 2025 21:08

@storopoli storopoli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some doc nits.
Where the hell are these test vectors?

Comment thread p2p/src/lib.rs Outdated
Comment thread p2p/src/lib.rs Outdated
Comment thread p2p/src/message.rs Outdated
Comment thread p2p/src/message_utreexo.rs
Comment thread p2p/src/message_utreexo.rs Outdated
Comment thread p2p/src/message_utreexo.rs
@luisschwab

Copy link
Copy Markdown
Contributor Author

Where the hell are these test vectors?

@Davidson-Souza Where the hell are these test vectors?

@luisschwab luisschwab force-pushed the feat/utreexo branch 3 times, most recently from 0d93549 to 1e2f3a0 Compare November 4, 2025 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants