Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(chain): Add verify_tx for TxGraph #1339

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ValuedMammal
Copy link
Contributor

@ValuedMammal ValuedMammal commented Feb 12, 2024

Reintroduce a way to verify a transaction.

This adds a new feature to bdk_chain that uses feature bitcoin/bitcoinconsensus, and exposes the same through bdk wallet as bdk_chain/bitcoinconsensus.

closes #1180

Notes to the reviewers

Changelog notice

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

@ValuedMammal ValuedMammal changed the title [chain] Add verify_tx for TxGraph [chain, wallet] Add verify_tx for TxGraph Feb 16, 2024
@evanlinjin
Copy link
Member

I can't decide whether we need this in bdk_chain or even in bdk_wallet. On one hand, the bitcoinconsensus API is not difficult so the caller can just import it directly and use it without much difficulty...

Would love some input on this.

@ValuedMammal
Copy link
Contributor Author

Right, I'm curious if anyone has specifically asked for this functionality in bdk.

@nondiremanuel nondiremanuel added the discussion There's still a discussion ongoing label Mar 12, 2024
@nondiremanuel nondiremanuel added this to the 1.1.0 milestone Mar 12, 2024
@notmandatory
Copy link
Member

How about leaving it as a draft until we are ready to scope out a 1.1 release. Maybe by then we'll have a use case, if not we can close it. There is a scenario described in #352 where this verify functionality could be used.

@notmandatory notmandatory added module-wallet api A breaking API change labels Mar 16, 2024
@notmandatory
Copy link
Member

Ok per @LLFourn comments in #1180 I think this should stay in the 1.0.0-alpha milestone.

@LLFourn
Copy link
Contributor

LLFourn commented Mar 17, 2024

@notmandatory I don't really have an opinion on this being in any milestone. My opinion is that the main issue is fixing RBF design. Being able to verify a transaction is also a nice to have but if no one needs it then it doesn't have to be in v1.0.0.

@nondiremanuel nondiremanuel removed this from the 1.1.0 milestone Mar 21, 2024
@f321x
Copy link

f321x commented Jul 8, 2024

I currently use verify_tx in an onchain trading pipeline concept to verify bond transactions that are signed but not published (except cheating occurs). While it may is possible to use bitcoinconsensus the verify_tx function was convenient to use and the bdk docs were understandable as a new bdk user.

Also the old verify_tx was not compatible with the async Esplora backend feature of bdk, maybe it makes sense to consider this in the new implementation from the beginning.

@notmandatory notmandatory added this to the 1.1.0 milestone Aug 22, 2024
* Add feature `bitcoinconsensus` to Cargo.toml
Check we can verify a transaction when `TxGraph` has knowledge
of the coins being spent. Also check that verification fails
either due to missing prevouts or a malformed input.
* Add feature `bitcoinconsensus` to Cargo.toml
@ValuedMammal ValuedMammal changed the title [chain, wallet] Add verify_tx for TxGraph feat(chain): Add verify_tx for TxGraph Sep 30, 2024
@ValuedMammal
Copy link
Contributor Author

Rebased on 4942cc6

@LLFourn
Copy link
Contributor

LLFourn commented Sep 30, 2024

Dunno if we should expand the scope of this PR but I'd expect there to be a way to construct a tx_graph such that every tx is verified in so far as the input spks are already available. Probably want to make this available for bdk_wallet too. We'd need some way to insert the transactions in topological order so that ancestors are inserted before children.

I'd guess this is actually what a user wants here to just have blanket protection against a malicious server trying to make it appear as though inputs that have not been spent are in fact spent.

@tnull
Copy link
Contributor

tnull commented Oct 1, 2024

Dunno if we should expand the scope of this PR but I'd expect there to be a way to construct a tx_graph such that every tx is verified in so far as the input spks are already available. Probably want to make this available for bdk_wallet too. We'd need some way to insert the transactions in topological order so that ancestors are inserted before children.

I'd guess this is actually what a user wants here to just have blanket protection against a malicious server trying to make it appear as though inputs that have not been spent are in fact spent.

Want to note that you probably don't want to lean to much on bitcoinconsensus as it unfortunately fails to build on WASM and mobile platforms (rust-bitcoin/rust-bitcoinconsensus#32). I don't think this is a blocker for this PR, but BDK's core functionalities probably can't make use of it for this reason unfortunately.

@ValuedMammal
Copy link
Contributor Author

We'd need some way to insert the transactions in topological order so that ancestors are inserted before children.

For this we could implement a simplified version of Core's mining logic for package selection (miner.cpp) and leverage the existing features of TxGraph to walk ancestors and descendants. I think it would also be useful for sorting wallet transactions - for example using Wallet::transactions_sort_by and sorting by chain position may not be as effective at sorting same-block transactions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api A breaking API change discussion There's still a discussion ongoing module-wallet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Reintroduce a way verify a transaction
7 participants