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 082a300
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

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 082a300

Please sign in to comment.