-
Notifications
You must be signed in to change notification settings - Fork 9
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
Some minor cleanup #31
Changes from all commits
6ceece7
33dc91b
0340d69
f066e50
616a72e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
FROM rust:1.69-bookworm | ||
ARG http_proxy | ||
ENV http_proxy=$http_proxy | ||
ENV https_proxy=$http_proxy | ||
ENV HTTP_PROXY=$http_proxy | ||
ENV HTTPS_PROXY=$http_proxy | ||
RUN echo Acquire::http::Proxy "${http_proxy}"; > /etc/apt/apt.conf.d/70debconf | ||
|
||
RUN apt-get update \ | ||
&& apt-get install --no-install-recommends -y \ | ||
eatmydata \ | ||
&& eatmydata apt-get -y dist-upgrade \ | ||
&& eatmydata apt-get install --no-install-recommends -y \ | ||
build-essential \ | ||
bash \ | ||
ca-certificates \ | ||
clang \ | ||
curl \ | ||
emscripten \ | ||
hunspell \ | ||
libclang-dev \ | ||
libssl-dev \ | ||
llvm \ | ||
pkg-config \ | ||
syslog-ng \ | ||
sudo \ | ||
&& eatmydata apt -y autoremove \ | ||
&& eatmydata apt clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ARG UID | ||
RUN useradd -m -u $UID satoshi | ||
USER satoshi | ||
WORKDIR /home/satoshi | ||
|
||
RUN rustup component add clippy-preview \ | ||
&& rustup component add rustfmt | ||
RUN rustup target add wasm32-unknown-unknown | ||
RUN rustup target add wasm32-wasi | ||
RUN rustup target add wasm32-unknown-emscripten | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
FROM rust:1.63-buster | ||
ARG http_proxy | ||
ENV http_proxy=$http_proxy | ||
ENV https_proxy=$http_proxy | ||
ENV HTTP_PROXY=$http_proxy | ||
ENV HTTPS_PROXY=$http_proxy | ||
RUN echo Acquire::http::Proxy "${http_proxy}"; > /etc/apt/apt.conf.d/70debconf | ||
|
||
RUN apt-get update \ | ||
&& apt-get install --no-install-recommends -y \ | ||
eatmydata \ | ||
&& eatmydata apt-get -y dist-upgrade \ | ||
&& eatmydata apt-get install --no-install-recommends -y \ | ||
build-essential \ | ||
bash \ | ||
ca-certificates \ | ||
clang \ | ||
curl \ | ||
hunspell \ | ||
libclang-dev \ | ||
libssl-dev \ | ||
llvm \ | ||
pkg-config \ | ||
syslog-ng \ | ||
sudo \ | ||
&& eatmydata apt -y autoremove \ | ||
&& eatmydata apt clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ARG UID | ||
RUN useradd -m -u $UID satoshi | ||
USER satoshi | ||
WORKDIR /home/satoshi | ||
|
||
RUN rustup component add clippy-preview \ | ||
&& rustup component add rustfmt | ||
RUN rustup target add wasm32-unknown-unknown | ||
RUN rustup target add wasm32-wasi | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
TAG := bdk-reserves | ||
TAG_57 := bdk-reserves-57 | ||
TAG_63 := bdk-reserves-61 | ||
http_proxy ?= http://172.17.0.1:3128 | ||
DOCKER_RUN := docker run --interactive --rm \ | ||
-v ${PWD}:/home/satoshi \ | ||
|
||
build: builder | ||
$(DOCKER_RUN) --tty ${TAG} cargo build | ||
|
||
test: test_current test_63 | ||
|
||
test_current: builder | ||
rm -f Cargo.lock | ||
$(DOCKER_RUN) ${TAG} cargo test | ||
|
||
test_57: builder_57 | ||
#rm -f Cargo.lock | ||
#$(DOCKER_RUN) ${TAG_57} cargo update -p log:0.4.20 --precise 0.4.18 | ||
#$(DOCKER_RUN) ${TAG_57} cargo update -p tempfile --precise 3.6.0 | ||
#$(DOCKER_RUN) ${TAG_57} cargo update -p sct:0.7.1 --precise 0.7.0 | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p zip:0.6.6 --precise 0.6.3 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p rustls:0.21.10 --precise 0.21.1 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p rustls:0.21.7 --precise 0.21.1 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p rustls:0.21.4 --precise 0.21.1 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p rustls:0.21.2 --precise 0.21.1 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p rustls:0.20.9 --precise 0.20.8 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p rustls-webpki:0.100.3 --precise 0.100.1 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p rustls-webpki:0.101.4 --precise 0.101.1 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p rustls-webpki:0.101.7 --precise 0.101.1 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p crossbeam-utils:0.8.18 --precise 0.8.16 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p tokio:1.35.1 --precise 1.29.1 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p rustix:0.38.9 --precise 0.38.3 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p ring:0.17.7 --precise 0.16.20 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p byteorder:1.5.0 --precise 0.4.3 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p webpki:0.22.4 --precise 0.22.0 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p crossbeam-epoch:0.9.17 --precise 0.9.15 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo update -p byteorder:1.5.0 --precise 0.4.3 || true | ||
$(DOCKER_RUN) ${TAG_57} cargo test | ||
|
||
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 test | ||
|
||
run: builder | ||
$(DOCKER_RUN) --tty ${TAG} cargo run | ||
|
||
wasm-unknown: builder | ||
$(DOCKER_RUN) --tty ${TAG} cargo check --target wasm32-unknown-unknown --no-default-features | ||
|
||
wasm-wasi: builder | ||
$(DOCKER_RUN) --tty ${TAG} cargo check --target wasm32-wasi --no-default-features | ||
|
||
wasm-emscripten: builder | ||
$(DOCKER_RUN) --tty ${TAG} cargo check --target wasm32-unknown-emscripten --no-default-features | ||
|
||
sh: builder | ||
$(DOCKER_RUN) --tty ${TAG} sh | ||
|
||
builder: | ||
docker build --tag ${TAG} \ | ||
--build-arg http_proxy="${http_proxy}" \ | ||
--build-arg UID="$(shell id -u)" \ | ||
. | ||
|
||
builder_57: | ||
docker build --tag ${TAG_57}\ | ||
--build-arg http_proxy="${http_proxy}" \ | ||
--build-arg UID="$(shell id -u)" \ | ||
-f Dockerfile_57 \ | ||
. | ||
|
||
builder_63: | ||
docker build --tag ${TAG_63}\ | ||
--build-arg http_proxy="${http_proxy}" \ | ||
--build-arg UID="$(shell id -u)" \ | ||
-f Dockerfile_63 \ | ||
. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,8 @@ use bdk::bitcoin::blockdata::transaction::{EcdsaSighashType, OutPoint, TxIn, TxO | |
use bdk::bitcoin::consensus::encode::serialize; | ||
use bdk::bitcoin::hash_types::{PubkeyHash, Txid}; | ||
use bdk::bitcoin::hashes::{hash160, sha256d, Hash}; | ||
use bdk::bitcoin::util::address::Payload; | ||
use bdk::bitcoin::util::psbt::{Input, PartiallySignedTransaction as PSBT}; | ||
use bdk::bitcoin::{Address, Network, Sequence}; | ||
use bdk::bitcoin::{Network, Sequence}; | ||
use bdk::database::BatchDatabase; | ||
use bdk::wallet::tx_builder::TxOrdering; | ||
use bdk::wallet::Wallet; | ||
|
@@ -119,11 +118,7 @@ where | |
}; | ||
|
||
let pkh = PubkeyHash::from_hash(hash160::Hash::hash(&[0])); | ||
let out_script_unspendable = Address { | ||
payload: Payload::PubkeyHash(pkh), | ||
network: self.network(), | ||
} | ||
.script_pubkey(); | ||
let out_script_unspendable = Script::new_p2pkh(&pkh); | ||
|
||
let mut builder = self.build_tx(); | ||
builder | ||
|
@@ -192,7 +187,7 @@ pub fn verify_proof( | |
psbt: &PSBT, | ||
message: &str, | ||
outpoints: Vec<(OutPoint, TxOut)>, | ||
network: Network, | ||
_network: Network, | ||
) -> Result<u64, ProofError> { | ||
let tx = psbt.clone().extract_tx(); | ||
|
||
|
@@ -258,32 +253,14 @@ pub fn verify_proof( | |
|
||
// verify the unspendable output | ||
let pkh = PubkeyHash::from_hash(hash160::Hash::hash(&[0])); | ||
let out_script_unspendable = Address { | ||
payload: Payload::PubkeyHash(pkh), | ||
network, | ||
} | ||
.script_pubkey(); | ||
let out_script_unspendable = Script::new_p2pkh(&pkh); | ||
|
||
if tx.output[0].script_pubkey != out_script_unspendable { | ||
return Err(ProofError::InvalidOutput); | ||
} | ||
|
||
let serialized_tx = serialize(&tx); | ||
// Verify the challenge input | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering and thinking for a while, if there was a way to cheat in absence of this check. But all I came up with was something like in the tampered_proof_message() test, which shows that this kind of cheating is caught. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I was hesitant to remove a test, but I'm pretty certain this is redundant. In bip-0127 verification is done over transactions, where the synthetic witness_utxo from the psbt wouldn't be available anyway. |
||
if let Some(utxo) = &psbt.inputs[0].witness_utxo { | ||
if let Err(err) = bitcoinconsensus::verify( | ||
utxo.script_pubkey.to_bytes().as_slice(), | ||
utxo.value, | ||
&serialized_tx, | ||
0, | ||
) { | ||
return Err(ProofError::SignatureValidation(0, format!("{:?}", err))); | ||
} | ||
} else { | ||
return Err(ProofError::SignatureValidation( | ||
0, | ||
"witness_utxo not found for challenge input".to_string(), | ||
)); | ||
} | ||
|
||
// Verify other inputs against prevouts. | ||
if let Some((i, res)) = tx | ||
.input | ||
|
@@ -335,11 +312,8 @@ fn challenge_txin(message: &str) -> TxIn { | |
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
use base64ct::{Base64, Encoding}; | ||
use bdk::bitcoin::consensus::encode::deserialize; | ||
use bdk::bitcoin::hashes::sha256; | ||
use bdk::bitcoin::secp256k1::{ecdsa::SerializedSignature, Message, Secp256k1, SecretKey}; | ||
use bdk::bitcoin::{Address, EcdsaSighashType, Network, Witness}; | ||
use bdk::bitcoin::secp256k1::ecdsa::{SerializedSignature, Signature}; | ||
use bdk::bitcoin::{EcdsaSighashType, Network, Witness}; | ||
use bdk::wallet::get_funded_wallet; | ||
use std::str::FromStr; | ||
|
||
|
@@ -350,8 +324,9 @@ mod test { | |
|
||
let message = "This belongs to me."; | ||
let psbt = wallet.create_proof(message).unwrap(); | ||
let psbt_ser = serialize(&psbt); | ||
let psbt_b64 = Base64::encode_string(&psbt_ser); | ||
|
||
let psbt_b64 = psbt.to_string(); | ||
|
||
let expected = r#"cHNidP8BAH4BAAAAAmw1RvG4UzfnSafpx62EPTyha6VslP0Er7n3TxjEpeBeAAAAAAD/////2johM0znoXIXT1lg+ySrvGrtq1IGXPJzpfi/emkV9iIAAAAAAP////8BUMMAAAAAAAAZdqkUn3/QltN+0sDj9/DPySS+70/862iIrAAAAAAAAQEKAAAAAAAAAAABUQEHAAABAR9QwwAAAAAAABYAFOzlJlcQU9qGRUyeBmd56vnRUC5qIgYDKwVYB4vsOGlKhJM9ZZMD4lddrn6RaFkRRUEVv9ZEh+ME7OUmVwAA"#; | ||
|
||
assert_eq!(psbt_b64, expected); | ||
|
@@ -381,8 +356,7 @@ mod test { | |
|
||
fn get_signed_proof() -> PSBT { | ||
let psbt = "cHNidP8BAH4BAAAAAmw1RvG4UzfnSafpx62EPTyha6VslP0Er7n3TxjEpeBeAAAAAAD/////2johM0znoXIXT1lg+ySrvGrtq1IGXPJzpfi/emkV9iIAAAAAAP////8BUMMAAAAAAAAZdqkUn3/QltN+0sDj9/DPySS+70/862iIrAAAAAAAAQEKAAAAAAAAAAABUQEHAAABAR9QwwAAAAAAABYAFOzlJlcQU9qGRUyeBmd56vnRUC5qAQcAAQhrAkcwRAIgDSE4PQ57JDiZ7otGkTqz35bi/e1pexYaYKWaveuvRd4CIFzVB4sAmgtdEVz2vHzs1iXc9iRKJ+KQOQb+C2DtPyvzASEDKwVYB4vsOGlKhJM9ZZMD4lddrn6RaFkRRUEVv9ZEh+MAAA=="; | ||
let psbt = Base64::decode_vec(psbt).unwrap(); | ||
deserialize(&psbt).unwrap() | ||
PSBT::from_str(psbt).unwrap() | ||
} | ||
|
||
#[test] | ||
|
@@ -499,20 +473,12 @@ mod test { | |
let mut psbt = get_signed_proof(); | ||
psbt.inputs[1].final_script_sig = None; | ||
|
||
let secp = Secp256k1::new(); | ||
// privkey from milk sad ... | ||
let privkey = | ||
SecretKey::from_str("4dcaff8ed1975fe2cebbd7c03384902c2189a2e6de11f1bb1c9dc784e8e4d11e") | ||
.expect("valid privkey"); | ||
|
||
let invalid_message = | ||
Message::from_hashed_data::<sha256::Hash>("Invalid signing data".as_bytes()); | ||
let signature = secp.sign_ecdsa(&invalid_message, &privkey); | ||
let invalid_signature = Signature::from_str("3045022100f3b7b0b1400287766edfe8ba66bc0412984cdb97da6bb4092d5dc63a84e1da6f02204da10796361dbeaeead8f68a23157dffa23b356ec14ec2c0c384ad68d582bb14").unwrap(); | ||
let invalid_signature = SerializedSignature::from_signature(&invalid_signature); | ||
|
||
let mut invalid_witness = Witness::new(); | ||
invalid_witness.push_bitcoin_signature(&invalid_signature, EcdsaSighashType::All); | ||
|
||
let signature = SerializedSignature::from_signature(&signature); | ||
invalid_witness.push_bitcoin_signature(&signature, EcdsaSighashType::All); | ||
psbt.inputs[1].final_script_witness = Some(invalid_witness); | ||
|
||
wallet.verify_proof(&psbt, message, None).unwrap(); | ||
|
@@ -541,11 +507,7 @@ mod test { | |
let mut psbt = get_signed_proof(); | ||
|
||
let pkh = PubkeyHash::from_hash(hash160::Hash::hash(&[0, 1, 2, 3])); | ||
let out_script_unspendable = Address { | ||
payload: Payload::PubkeyHash(pkh), | ||
network: Network::Testnet, | ||
} | ||
.script_pubkey(); | ||
let out_script_unspendable = Script::new_p2pkh(&pkh); | ||
psbt.unsigned_tx.output[0].script_pubkey = out_script_unspendable; | ||
|
||
wallet.verify_proof(&psbt, message, None).unwrap(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the next release is for 0.29 I think it's ok to break the interface here by removing that parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure if/when you wanted to bump to the next BDK version, I had that in my next patch set which makes a number of more significant changes. I can include it here instead though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's in the next one, that's also fine. You mentioned before that you had something prepared with v0.29.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah my intention was to only make backwards compatible changes in this patch set