From 33198e0ba9fb6c2110da317990b161742202814d Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Tue, 14 Jan 2025 02:02:02 +0100 Subject: [PATCH] psbt: unify seal types --- Cargo.lock | 105 +++++++++++++++++++++--------------------- Cargo.toml | 6 +++ psbt/src/csval/dbc.rs | 70 ++++++++-------------------- 3 files changed, 78 insertions(+), 103 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 892dd12..0e2b508 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -147,8 +147,7 @@ dependencies = [ [[package]] name = "bp-consensus" version = "0.12.0-beta.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1303344864858bcdbe31e36ba2285efb4cdd53e1c6b275b8840c88469a3f18f" +source = "git+https://github.com/BP-WG/bp-core?branch=refactor/consensus#1645008e3aa31c762747a159877a2cd4550de933" dependencies = [ "amplify", "chrono", @@ -161,8 +160,7 @@ dependencies = [ [[package]] name = "bp-core" version = "0.12.0-beta.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469adfa23c07f6c178392f278a32ab43bf7c370ca0d29f4865ecd568b946b5d4" +source = "git+https://github.com/BP-WG/bp-core?branch=refactor/consensus#1645008e3aa31c762747a159877a2cd4550de933" dependencies = [ "amplify", "bp-consensus", @@ -179,8 +177,7 @@ dependencies = [ [[package]] name = "bp-dbc" version = "0.12.0-beta.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c58353b119115259123518bcc1a2578b326d74dbabddb0b31c682d83509858c9" +source = "git+https://github.com/BP-WG/bp-core?branch=refactor/consensus#1645008e3aa31c762747a159877a2cd4550de933" dependencies = [ "amplify", "base85", @@ -220,8 +217,7 @@ dependencies = [ [[package]] name = "bp-seals" version = "0.12.0-beta.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6f15dc1cad42e0cc9801509500a6cee6b6f99da473513209d495707d20397b0" +source = "git+https://github.com/BP-WG/bp-core?branch=refactor/consensus#1645008e3aa31c762747a159877a2cd4550de933" dependencies = [ "amplify", "baid64", @@ -267,9 +263,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.2.5" +version = "1.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e" +checksum = "c8293772165d9345bdaaa39b45b2109591e63fe5e6fbc23c6ff930a048aa310b" dependencies = [ "shlex", ] @@ -465,9 +461,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.76" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" dependencies = [ "once_cell", "wasm-bindgen", @@ -533,9 +529,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" dependencies = [ "unicode-ident", ] @@ -557,9 +553,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] @@ -603,6 +599,12 @@ dependencies = [ "digest", ] +[[package]] +name = "rustversion" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" + [[package]] name = "same-file" version = "1.0.6" @@ -612,12 +614,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scoped-tls" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" - [[package]] name = "secp256k1" version = "0.30.0" @@ -641,22 +637,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.216" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.216" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -760,9 +756,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.91" +version = "2.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035" +checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" dependencies = [ "proc-macro2", "quote", @@ -786,7 +782,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -835,34 +831,35 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", "once_cell", + "rustversion", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", "log", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.49" +version = "0.4.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" dependencies = [ "cfg-if", "js-sys", @@ -873,9 +870,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -883,32 +880,34 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] [[package]] name = "wasm-bindgen-test" -version = "0.3.49" +version = "0.3.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d44563646eb934577f2772656c7ad5e9c90fac78aa8013d776fcdaf24625d" +checksum = "66c8d5e33ca3b6d9fa3b4676d774c5778031d27a578c2b007f905acf816152c3" dependencies = [ "js-sys", "minicov", - "scoped-tls", "wasm-bindgen", "wasm-bindgen-futures", "wasm-bindgen-test-macro", @@ -916,20 +915,20 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.49" +version = "0.3.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54171416ce73aa0b9c377b51cc3cb542becee1cd678204812e8392e5b0e4a031" +checksum = "17d5042cc5fa009658f9a7333ef24291b1291a25b6382dd68862a7f3b969f69b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "web-sys" -version = "0.3.76" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" dependencies = [ "js-sys", "wasm-bindgen", @@ -1044,5 +1043,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] diff --git a/Cargo.toml b/Cargo.toml index bfe167a..9aea57e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,3 +71,9 @@ getrandom = { version = "0.2", features = ["js"] } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = "0.3" + +[patch.crates-io] +bp-consensus = { git = "https://github.com/BP-WG/bp-core", branch = "refactor/consensus" } +bp-dbc = { git = "https://github.com/BP-WG/bp-core", branch = "refactor/consensus" } +bp-seals = { git = "https://github.com/BP-WG/bp-core", branch = "refactor/consensus" } +bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "refactor/consensus" } diff --git a/psbt/src/csval/dbc.rs b/psbt/src/csval/dbc.rs index f70a76a..2af365f 100644 --- a/psbt/src/csval/dbc.rs +++ b/psbt/src/csval/dbc.rs @@ -19,12 +19,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use bp::dbc::opret::OpretProof; use bp::dbc::tapret::TapretProof; -use bp::dbc::{self, Method}; use commit_verify::mpc; -use crate::{MmbPsbtError, MpcPsbtError, OpretKeyError, Output, Psbt, TapretKeyError}; +use crate::{MmbPsbtError, MpcPsbtError, OpretKeyError, Psbt, TapretKeyError}; #[derive(Clone, PartialEq, Eq, Debug, Display, Error, From)] #[display(doc_comments)] @@ -32,8 +30,8 @@ pub enum DbcPsbtError { /// the first output valid for a DBC commitment is not marked as a commitment host. NoHostOutput, - /// the transactions contains no output valid for {0} DBC commitment. - NoProperOutput(Method), + /// the transaction contains no output valid for a DBC commitment. + NoProperOutput, /// DBC commitment is already present. AlreadyPresent, @@ -60,62 +58,34 @@ pub enum DbcPsbtError { } impl Psbt { - #[allow(private_bounds)] - pub fn dbc_output(&self) -> Option<&Output> { - self.outputs().find(|output| match D::METHOD { - Method::OpretFirst => output.script.is_op_return(), - Method::TapretFirst => output.script.is_p2tr(), - }) - } - - #[allow(private_bounds)] - pub fn dbc_output_mut(&mut self) -> Option<&mut Output> { - self.outputs_mut().find(|output| match D::METHOD { - Method::OpretFirst => output.script.is_op_return(), - Method::TapretFirst => output.script.is_p2tr(), - }) - } - - #[allow(private_bounds)] - pub fn dbc_commit(&mut self) -> Result<(mpc::MerkleBlock, D), DbcPsbtError> { + pub fn dbc_commit(&mut self) -> Result<(mpc::MerkleBlock, Option), DbcPsbtError> { if self.are_outputs_modifiable() { return Err(DbcPsbtError::TxOutputsModifiable); } let map = self.mmb_complete()?; - let output = self.dbc_output_mut::().ok_or(DbcPsbtError::NoProperOutput(D::METHOD))?; + let output = self + .outputs_mut() + .find(|out| out.script.is_op_return() || out.script.is_p2tr()) + .ok_or(DbcPsbtError::NoProperOutput)?; for (id, msg) in map { output.set_mpc_message(id, msg)?; } - let (mpc_proof, dbc_proof) = D::dbc_commit(output)?; - Ok((mpc_proof, dbc_proof)) - } -} - -trait DbcPsbtProof: dbc::Proof { - fn dbc_commit(output: &mut Output) -> Result<(mpc::MerkleBlock, Self), DbcPsbtError>; -} - -impl DbcPsbtProof for TapretProof { - fn dbc_commit(output: &mut Output) -> Result<(mpc::MerkleBlock, Self), DbcPsbtError> { let (commitment, mpc_proof) = output.mpc_commit()?; - if !output.is_tapret_host() { - return Err(DbcPsbtError::NoHostOutput); - } - let tapret_proof = output.tapret_commit(commitment)?; - Ok((mpc_proof, tapret_proof)) - } -} - -impl DbcPsbtProof for OpretProof { - fn dbc_commit(output: &mut Output) -> Result<(mpc::MerkleBlock, Self), DbcPsbtError> { - let (commitment, mpc_proof) = output.mpc_commit()?; - if !output.is_opret_host() { - return Err(DbcPsbtError::NoHostOutput); + if output.script.is_op_return() { + if !output.is_opret_host() { + return Err(DbcPsbtError::NoHostOutput); + } + output.opret_commit(commitment)?; + Ok((mpc_proof, None)) + } else { + if !output.is_tapret_host() { + return Err(DbcPsbtError::NoHostOutput); + } + let tapret_proof = output.tapret_commit(commitment)?; + Ok((mpc_proof, Some(tapret_proof))) } - output.opret_commit(commitment)?; - Ok((mpc_proof, OpretProof::default())) } }