From 082a300dd6cd66700b60c1a51ca97a3e71d9e92f Mon Sep 17 00:00:00 2001 From: Richard Ulrich Date: Wed, 9 Oct 2024 12:56:17 +0200 Subject: [PATCH] removing the obsolete network parameter, and adding a test for the burner output address --- .github/workflows/cont_integration.yml | 2 +- Dockerfile | 2 +- Makefile | 2 +- src/reserves.rs | 42 +++++++++++++++++++++++--- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 9925bce..22d0bae 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -39,7 +39,7 @@ jobs: if: matrix.rust == '1.63.0' run: | cargo update -p home:0.5.9 --precise 0.5.5 - cargo update -p tokio:1.39.3 --precise 1.38.1 + cargo update -p tokio:1.40.0 --precise 1.38.1 cargo update -p cc --precise 1.0.105 - name: Build run: cargo build diff --git a/Dockerfile b/Dockerfile index b67262c..e60c33c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.69-bookworm +FROM rust:1.70-bookworm ARG http_proxy ENV http_proxy=$http_proxy ENV https_proxy=$http_proxy diff --git a/Makefile b/Makefile index 4b46af5..121facb 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ test_63: builder_63 rm -f Cargo.lock $(DOCKER_RUN) ${TAG_63} cargo test || true $(DOCKER_RUN) ${TAG_63} cargo update -p home:0.5.9 --precise 0.5.5 || true - $(DOCKER_RUN) ${TAG_63} cargo update -p tokio:1.39.3 --precise 1.38.1 || true + $(DOCKER_RUN) ${TAG_63} cargo update -p tokio:1.40.0 --precise 1.38.1 || true $(DOCKER_RUN) ${TAG_63} cargo update -p cc --precise 1.0.105 || true $(DOCKER_RUN) ${TAG_63} cargo test diff --git a/src/reserves.rs b/src/reserves.rs index 3e9d2c2..a35d20d 100644 --- a/src/reserves.rs +++ b/src/reserves.rs @@ -26,7 +26,7 @@ use bdk::bitcoin::hash_types::{PubkeyHash, Txid}; use bdk::bitcoin::hashes::{hash160, sha256d, Hash}; use bdk::bitcoin::psbt::{Input, PartiallySignedTransaction as PSBT}; use bdk::bitcoin::sighash::EcdsaSighashType; -use bdk::bitcoin::{Network, Sequence}; +use bdk::bitcoin::Sequence; use bdk::database::BatchDatabase; use bdk::wallet::tx_builder::TxOrdering; use bdk::wallet::Wallet; @@ -173,7 +173,7 @@ where .map(|(utxo, _)| (utxo.outpoint, utxo.txout.clone())) .collect(); - verify_proof(psbt, message, outpoints, self.network()) + verify_proof(psbt, message, outpoints) } } @@ -188,7 +188,6 @@ pub fn verify_proof( psbt: &PSBT, message: &str, outpoints: Vec<(OutPoint, TxOut)>, - _network: Network, ) -> Result { let tx = psbt.clone().extract_tx(); @@ -314,7 +313,7 @@ fn challenge_txin(message: &str) -> TxIn { mod test { use super::*; use bdk::bitcoin::secp256k1::ecdsa::{SerializedSignature, Signature}; - use bdk::bitcoin::{Network, Witness}; + use bdk::bitcoin::{Address, Network, Witness}; use bdk::wallet::get_funded_wallet; use std::str::FromStr; @@ -406,7 +405,7 @@ mod test { .iter() .map(|utxo| (utxo.outpoint, utxo.txout.clone())) .collect(); - let spendable = verify_proof(&psbt, message, outpoints, Network::Testnet).unwrap(); + let spendable = verify_proof(&psbt, message, outpoints).unwrap(); assert_eq!(spendable, 50_000); } @@ -498,6 +497,39 @@ mod test { wallet.verify_proof(&psbt, message, None).unwrap(); } + #[test] + fn burner_output() { + let psbt = get_signed_proof(); + + let pkh = PubkeyHash::from_raw_hash(hash160::Hash::hash(&[0])); + let out_script_unspendable = ScriptBuf::new_p2pkh(&pkh); + assert_eq!( + psbt.unsigned_tx.output[0].script_pubkey, + out_script_unspendable + ); + + let addr_unspendable = Address::new( + Network::Bitcoin, + bdk::bitcoin::address::Payload::PubkeyHash(pkh), + ); + assert_eq!( + addr_unspendable.to_string(), + "1FYMZEHnszCHKTBdFZ2DLrUuk3dGwYKQxh" + ); + // https://mempool.space/de/address/1FYMZEHnszCHKTBdFZ2DLrUuk3dGwYKQxh + // https://bitcoin.stackexchange.com/questions/65969/invalid-public-key-was-spent-how-was-this-possible + + let addr_unspendable_testnet = Address::new( + Network::Testnet, + bdk::bitcoin::address::Payload::PubkeyHash(pkh), + ); + assert_eq!( + addr_unspendable_testnet.to_string(), + "mv4JrHNmh1dY6ZfEy7zbAmhEc3Dyr8ULqX" + ); + // this address can be discovered in the transaction in https://ulrichard.ch/blog/?p=2566 + } + #[test] #[should_panic(expected = "InvalidOutput")] fn invalid_output() {