bitcoindevkit / bdk-reserves

Proof-of-reserves for bitcoin-dev-kit
Other
15 stars 9 forks source link

Upgrade bdk to 0.20.0 #8

Closed afilini closed 2 years ago

afilini commented 2 years ago

The only notable change in this release is that by default bdk tries to prevent fee-sniping attacks by setting the nlocktime to the current height, so it's now necessary to set it at zero explicitly to get deterministic proof of reserves.

On top of this, the new default behavior is to remove partial signatures after finalizing a tx, which should shrink down the size of proofs quite a bit as you can see in the test updated here: https://github.com/bitcoindevkit/bdk-cli/pull/108

This is a draft for now while we wait for the release, there's a one-week window to report bugs so if you notice anything wrong here let us know.

ulrichard commented 2 years ago

With the following changes, most tests pass:

From 5c1d91080fef8675ae61e0332d49fe4f55d4f39d Mon Sep 17 00:00:00 2001
From: Richard Ulrich <richard.ulrich@seba.swiss>
Date: Mon, 11 Jul 2022 13:29:52 +0200
Subject: [PATCH] testing

---
 Cargo.toml          | 1 +
 tests/multi_sig.rs  | 1 +
 tests/single_sig.rs | 1 +
 3 files changed, 3 insertions(+)

diff --git a/Cargo.toml b/Cargo.toml
index a33beb7..6598e6f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,5 +15,6 @@ bitcoinconsensus = "0.19.0-3"
 log = "^0.4"

 [dev-dependencies]
+bdk = { git = "https://github.com/bitcoindevkit/bdk.git", branch = "release/0.20.0", default-features = true }
 rstest = "^0.11"
 bdk-testutils = "^0.4"
diff --git a/tests/multi_sig.rs b/tests/multi_sig.rs
index e2e6e00..965009a 100644
--- a/tests/multi_sig.rs
+++ b/tests/multi_sig.rs
@@ -128,6 +128,7 @@ fn test_proof_multisig(

     let signopts = SignOptions {
         trust_witness_utxo: true,
+        remove_partial_sigs: false,
         ..Default::default()
     };
     let finalized = wallet1.sign(&mut psbt, signopts.clone())?;
diff --git a/tests/single_sig.rs b/tests/single_sig.rs
index 4dd9b41..72f4a91 100644
--- a/tests/single_sig.rs
+++ b/tests/single_sig.rs
@@ -23,6 +23,7 @@ fn test_proof(#[case] descriptor: &'static str) -> Result<(), ProofError> {
     let finalized = wallet.sign(
         &mut psbt,
         SignOptions {
+            remove_partial_sigs: false,
             trust_witness_utxo: true,
             ..Default::default()
         },
-- 
2.30.2

but the following still fails. I didn't investigate so far.

---- test_proof::case_3 stdout ----
-------------- TEST START --------------
thread 'test_proof::case_3' panicked at 'called `Result::unwrap()` on an `Err` value: Generic("TxBuilder requested timelock of `0`, but at least `100000` is required to spend from this script")', /home/richi/src/github/bdk-reserves/src/reserves.rs:137:49
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
afilini commented 2 years ago

The last error means you have a timelock in your script and in order to spend correctly from it you need to set the nLockTime to 100000, but with my changes I'm always forcing it to zero and that's why it fails.

I can change it so that I don't force bdk to use zero, just tell the library to use zero for anti fee sniping (essentially disabling it).

ulrichard commented 2 years ago

Thanks for the work, and sorry for the delay. During the family holiday, my computer time was limited.