Skip to content

Commit

Permalink
removing the obsolete network parameter, and adding a test for the bu…
Browse files Browse the repository at this point in the history
…rner output address
  • Loading branch information
ulrichard committed Oct 9, 2024
1 parent 62ddcb1 commit 7367bd8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
42 changes: 37 additions & 5 deletions src/reserves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -188,7 +188,6 @@ pub fn verify_proof(
psbt: &PSBT,
message: &str,
outpoints: Vec<(OutPoint, TxOut)>,
_network: Network,
) -> Result<u64, ProofError> {
let tx = psbt.clone().extract_tx();

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 7367bd8

Please sign in to comment.