From 26f8701a8c0e672524bb6d9b26d89e7cca824484 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Tue, 26 Aug 2025 15:45:17 +0200 Subject: [PATCH 1/4] bump rust-elements dep to 0.26.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index fcce1038..fb3b78d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ base64 = ["bitcoin/base64", "elements/base64"] [dependencies] bitcoin = "0.32.0" -elements = "0.25.0" +elements = "0.26.0" bitcoin-miniscript = { package = "miniscript", version = "12.0" } simplicity = { package = "simplicity-lang", version = "0.3.0", optional = true } From c4d17b0530da041ed50a9a35f1da83994e172a25 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Tue, 26 Aug 2025 15:58:18 +0200 Subject: [PATCH 2/4] bump version 0.4.0 -> 0.5.0 Signed-off-by: Riccardo Casatta --- CHANGELOG.md | 8 ++++++++ Cargo-latest.lock | 18 +++++++++++++++--- Cargo.toml | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f30d1b6..b391d6bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# 0.5.0 - Aug 26, 2025 + +- bump rust elements dep to 0.26.0 +- get CI up to date; pin nightly rust version; fix some clippy lints [#98](https://github.com/ElementsProject/elements-miniscript/pull/98) +- Pegin desc wildcard [#96](https://github.com/ElementsProject/elements-miniscript/pull/96) +- Remove inner checksum in pegin descriptor [#95](https://github.com/ElementsProject/elements-miniscript/pull/95) +- simplicity: swap program and witness data in satisfaction [#94](https://github.com/ElementsProject/elements-miniscript/pull/94) + # 0.4.0 - Oct 8, 2024 - Use rust-bitcoin 0.32.0 and rust-elements 0.25.0 [#90](https://github.com/ElementsProject/elements-miniscript/pull/90) diff --git a/Cargo-latest.lock b/Cargo-latest.lock index e64fbe7a..cb35a504 100644 --- a/Cargo-latest.lock +++ b/Cargo-latest.lock @@ -259,6 +259,18 @@ name = "elements" version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81b2569d3495bfdfce36c504fd4d78752ff4a7699f8a33e6f3ee523bddf9f6ad" +dependencies = [ + "bech32 0.11.0", + "bitcoin 0.32.7", + "secp256k1-zkp", + "serde_json", +] + +[[package]] +name = "elements" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26f0d9d44c103b7df345677d60264db216f3031a79423f7b3d4891f9d83eac75" dependencies = [ "bech32 0.11.0", "bitcoin 0.32.7", @@ -269,11 +281,11 @@ dependencies = [ [[package]] name = "elements-miniscript" -version = "0.4.0" +version = "0.5.0" dependencies = [ "base64 0.13.1", "bitcoin 0.32.7", - "elements", + "elements 0.26.0", "getrandom", "miniscript", "rand", @@ -696,7 +708,7 @@ dependencies = [ "bitcoin 0.32.7", "bitcoin_hashes 0.14.0", "byteorder", - "elements", + "elements 0.25.2", "getrandom", "hex-conservative 0.1.2", "miniscript", diff --git a/Cargo.toml b/Cargo.toml index fb3b78d5..b6026c66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elements-miniscript" -version = "0.4.0" +version = "0.5.0" authors = ["Andrew Poelstra , Sanket Kanjalkar "] repository = "https://github.com/ElementsProject/elements-miniscript" description = "Elements Miniscript: Miniscript, but for elements" From f79d75e3eb5c1b4e94864c0e63401b8122538ef3 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Mon, 1 Sep 2025 16:55:17 +0200 Subject: [PATCH 3/4] downgrade elements to 0.25.3 and use patch --- Cargo.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b6026c66..0e74e113 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ base64 = ["bitcoin/base64", "elements/base64"] [dependencies] bitcoin = "0.32.0" -elements = "0.26.0" +elements = "0.25.3" bitcoin-miniscript = { package = "miniscript", version = "12.0" } simplicity = { package = "simplicity-lang", version = "0.3.0", optional = true } @@ -112,3 +112,6 @@ unnecessary_wraps = "warn" unsafe_derive_deserialize = "warn" unused_async = "warn" unused_self = "warn" + +[patch.crates-io] +elements = { git = "https://github.com/ElementsProject/rust-elements", rev = "3dc8cd2872524d50e067bee512342c620578cd07" } \ No newline at end of file From 2138d94f48a390086eadbb4cc240c914717d3e27 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Mon, 1 Sep 2025 17:19:26 +0200 Subject: [PATCH 4/4] temporary compile fix create a dummy elements env just to compile --- Cargo.toml | 2 +- src/descriptor/tr.rs | 97 ++++++++++++++++++++++++++++++-------------- 2 files changed, 68 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0e74e113..b69b945f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ base64 = ["bitcoin/base64", "elements/base64"] bitcoin = "0.32.0" elements = "0.25.3" bitcoin-miniscript = { package = "miniscript", version = "12.0" } -simplicity = { package = "simplicity-lang", version = "0.3.0", optional = true } +simplicity = { package = "simplicity-lang", version = "0.5.0", optional = true } # Do NOT use this as a feature! Use the `serde` feature instead. actual-serde = { package = "serde", version = "1.0", optional = true } diff --git a/src/descriptor/tr.rs b/src/descriptor/tr.rs index 36b49889..05bb3936 100644 --- a/src/descriptor/tr.rs +++ b/src/descriptor/tr.rs @@ -165,7 +165,9 @@ impl TapTree { ), TapTree::Leaf(ms) => TapTree::Leaf(Arc::new(ms.translate_pk(t)?)), #[cfg(feature = "simplicity")] - TapTree::SimplicityLeaf(sim) => TapTree::SimplicityLeaf(Arc::new(sim.translate(&mut SimTranslator(t))?)) + TapTree::SimplicityLeaf(sim) => { + TapTree::SimplicityLeaf(Arc::new(sim.translate(&mut SimTranslator(t))?)) + } }; Ok(frag) } @@ -296,7 +298,7 @@ impl Tr { TapLeafScript::Miniscript(ms) => ms.sanity_check()?, // TODO: Add sanity check for Simplicity policies #[cfg(feature = "simplicity")] - TapLeafScript::Simplicity(..) => {}, + TapLeafScript::Simplicity(..) => {} } } Ok(()) @@ -446,7 +448,7 @@ pub enum TapLeafScript<'a, Pk: MiniscriptKey, Ext: Extension> { Miniscript(&'a Miniscript), /// Simplicity leaf #[cfg(feature = "simplicity")] - Simplicity(&'a simplicity::Policy) + Simplicity(&'a simplicity::Policy), } impl<'a, Pk: MiniscriptKey, Ext: Extension> TapLeafScript<'a, Pk, Ext> { @@ -509,12 +511,14 @@ impl<'a, Pk: MiniscriptKey, Ext: Extension> TapLeafScript<'a, Pk, Ext> { // We mark the witness size as malleable since it depends on the chosen spending path // TODO: Add method to simplicity::Policy and use it here #[cfg(feature = "simplicity")] - TapLeafScript::Simplicity(..) => Err(Error::AnalysisError(crate::AnalysisError::Malleable)) + TapLeafScript::Simplicity(..) => { + Err(Error::AnalysisError(crate::AnalysisError::Malleable)) + } } } /// Return an iterator over the plain public keys (and not key hash values) of the leaf script. - pub fn iter_pk(&self) -> Box + 'a> { + pub fn iter_pk(&self) -> Box + 'a> { match self { TapLeafScript::Miniscript(ms) => Box::new(ms.iter_pk()), #[cfg(feature = "simplicity")] @@ -529,9 +533,7 @@ impl<'a, Pk: ToPublicKey, Ext: ParseableExt> TapLeafScript<'a, Pk, Ext> { match self { TapLeafScript::Miniscript(ms) => ms.encode(), #[cfg(feature = "simplicity")] - TapLeafScript::Simplicity(sim) => { - Script::from(sim.cmr().as_ref().to_vec()) - } + TapLeafScript::Simplicity(sim) => Script::from(sim.cmr().as_ref().to_vec()), } } @@ -551,15 +553,44 @@ impl<'a, Pk: ToPublicKey, Ext: ParseableExt> TapLeafScript<'a, Pk, Ext> { TapLeafScript::Miniscript(ms) => ms.satisfy(satisfier), #[cfg(feature = "simplicity")] TapLeafScript::Simplicity(sim) => { + let env = dummy_env(); let satisfier = crate::simplicity::SatisfierWrapper::new(satisfier); - let program = sim.satisfy(&satisfier).map_err(|_| Error::CouldNotSatisfy)?; - let (program_bytes, witness_bytes) = program.encode_to_vec(); + let program = sim + .satisfy(&satisfier, &env) + .map_err(|_| Error::CouldNotSatisfy)?; + let (program_bytes, witness_bytes) = program.to_vec_with_witness(); Ok(vec![witness_bytes, program_bytes]) } } } } +#[cfg(feature = "simplicity")] +fn dummy_env() -> simplicity::jet::elements::ElementsEnv> { + use elements::hashes::Hash; + + let ctrl_blk: [u8; 33] = [ + 0xc0, 0xeb, 0x04, 0xb6, 0x8e, 0x9a, 0x26, 0xd1, 0x16, 0x04, 0x6c, 0x76, 0xe8, 0xff, 0x47, + 0x33, 0x2f, 0xb7, 0x1d, 0xda, 0x90, 0xff, 0x4b, 0xef, 0x53, 0x70, 0xf2, 0x52, 0x26, 0xd3, + 0xbc, 0x09, 0xfc, + ]; + let env = simplicity::jet::elements::ElementsEnv::new( + Arc::new(simplicity::elements::Transaction { + version: 0, + lock_time: simplicity::elements::LockTime::ZERO, + input: vec![], + output: vec![], + }), + vec![], + 0, + simplicity::Cmr::unit(), + simplicity::elements::taproot::ControlBlock::from_slice(&ctrl_blk).unwrap(), + None, + simplicity::elements::BlockHash::all_zeros(), + ); + env +} + /// Iterator over the leaves of a tap tree. /// /// Each leaf consists is a pair of (depth, script). @@ -594,9 +625,7 @@ where self.stack.push((depth + 1, r)); self.stack.push((depth + 1, l)); } - TapTree::Leaf(ref ms) => { - return Some((depth, TapLeafScript::Miniscript(ms))) - }, + TapTree::Leaf(ref ms) => return Some((depth, TapLeafScript::Miniscript(ms))), #[cfg(feature = "simplicity")] TapTree::SimplicityLeaf(ref sim) => { return Some((depth, TapLeafScript::Simplicity(sim))) @@ -790,7 +819,9 @@ impl Liftable for TapTree { } TapTree::Leaf(ref leaf) => leaf.lift(), #[cfg(feature = "simplicity")] - TapTree::SimplicityLeaf(..) => panic!("FIXME: Cannot lift Simplicity policy to Miniscript semantic policy"), + TapTree::SimplicityLeaf(..) => { + panic!("FIXME: Cannot lift Simplicity policy to Miniscript semantic policy") + } } } @@ -816,15 +847,11 @@ impl ForEachKey for Tr { where Pk: 'a, { - let script_keys_res = self - .iter_scripts() - .all(|(_d, script)| { - match script { - TapLeafScript::Miniscript(ms) => ms.for_each_key(&mut pred), - #[cfg(feature = "simplicity")] - TapLeafScript::Simplicity(sim) => crate::simplicity::for_each_key(sim, &mut pred), - } - }); + let script_keys_res = self.iter_scripts().all(|(_d, script)| match script { + TapLeafScript::Miniscript(ms) => ms.for_each_key(&mut pred), + #[cfg(feature = "simplicity")] + TapLeafScript::Simplicity(sim) => crate::simplicity::for_each_key(sim, &mut pred), + }); script_keys_res && pred(&self.internal_key) } } @@ -970,7 +997,11 @@ mod tests { assert!(!tr.for_each_key(|k| k.starts_with("acc"))); } - fn verify_from_str(desc_str: &str, internal_key: &str, scripts: &[TapLeafScript]) { + fn verify_from_str( + desc_str: &str, + internal_key: &str, + scripts: &[TapLeafScript], + ) { let desc = Tr::::from_str(desc_str).unwrap(); assert_eq!(desc_str, &desc.to_string()); assert_eq!(internal_key, &desc.internal_key); @@ -992,8 +1023,9 @@ mod tests { // Miniscript key spend let ms = Miniscript::::from_str("pk(a)").unwrap(); verify_from_str( - "eltr(internal,pk(a))#vadmk9gd", "internal", - &[TapLeafScript::Miniscript(&ms)] + "eltr(internal,pk(a))#vadmk9gd", + "internal", + &[TapLeafScript::Miniscript(&ms)], ); #[cfg(feature = "simplicity")] @@ -1001,14 +1033,19 @@ mod tests { // Simplicity key spend let sim = simplicity::Policy::Key("a".to_string()); verify_from_str( - "eltr(internal,sim{pk(a)})#duhmnzmm", "internal", - &[TapLeafScript::Simplicity(&sim)] + "eltr(internal,sim{pk(a)})#duhmnzmm", + "internal", + &[TapLeafScript::Simplicity(&sim)], ); // Mixed Miniscript and Simplicity verify_from_str( - "eltr(internal,{pk(a),sim{pk(a)}})#7vmfhpaj", "internal", - &[TapLeafScript::Miniscript(&ms), TapLeafScript::Simplicity(&sim)] + "eltr(internal,{pk(a),sim{pk(a)}})#7vmfhpaj", + "internal", + &[ + TapLeafScript::Miniscript(&ms), + TapLeafScript::Simplicity(&sim), + ], ); } }