From 9374196844f2e399444bcb054143f4a6410c72cf Mon Sep 17 00:00:00 2001 From: Christian Lewe Date: Fri, 30 Aug 2024 16:15:42 +0200 Subject: [PATCH] chore: Update rust-simplicity --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/named.rs | 17 +++++++---------- src/value.rs | 33 ++++++++++++++++++--------------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d7988a..851dac6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -510,7 +510,7 @@ dependencies = [ [[package]] name = "simplicity-lang" version = "0.2.0" -source = "git+https://github.com/BlockstreamResearch/rust-simplicity?rev=f6e7ecfc43852064780bba6f019b6532d572f166#f6e7ecfc43852064780bba6f019b6532d572f166" +source = "git+https://github.com/BlockstreamResearch/rust-simplicity?rev=794918783291465a109bdaf2ef694f86467c477e#794918783291465a109bdaf2ef694f86467c477e" dependencies = [ "bitcoin", "bitcoin_hashes", @@ -526,7 +526,7 @@ dependencies = [ [[package]] name = "simplicity-sys" version = "0.2.0" -source = "git+https://github.com/BlockstreamResearch/rust-simplicity?rev=f6e7ecfc43852064780bba6f019b6532d572f166#f6e7ecfc43852064780bba6f019b6532d572f166" +source = "git+https://github.com/BlockstreamResearch/rust-simplicity?rev=794918783291465a109bdaf2ef694f86467c477e#794918783291465a109bdaf2ef694f86467c477e" dependencies = [ "bitcoin_hashes", "cc", diff --git a/Cargo.toml b/Cargo.toml index 879640e..fdcf0e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ pest = "2.1.3" pest_derive = "2.7.1" serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.105" -simplicity-lang = { git = "https://github.com/BlockstreamResearch/rust-simplicity", rev = "f6e7ecfc43852064780bba6f019b6532d572f166" } +simplicity-lang = { git = "https://github.com/BlockstreamResearch/rust-simplicity", rev = "794918783291465a109bdaf2ef694f86467c477e" } miniscript = "11.0.0" either = "1.12.0" itertools = "0.13.0" diff --git a/src/named.rs b/src/named.rs index 96e69ee..e98a6c0 100644 --- a/src/named.rs +++ b/src/named.rs @@ -112,12 +112,12 @@ pub fn to_witness_node(node: &ConstructNode, values: &WitnessValues) -> Arc>>, witness: &WitnessName, - ) -> Result>, Self::Error> { + ) -> Result, Self::Error> { let maybe_value = self .values .get(witness) .map(StructuralValue::from) - .map(Arc::::from); + .map(simplicity::Value::from); Ok(maybe_value) } @@ -137,13 +137,13 @@ pub fn to_witness_node(node: &ConstructNode, values: &WitnessValues) -> Arc>, J, &Option>>, - &Option>, + &Option, >, ) -> Result, Self::Error> { let inner = inner .map(Arc::as_ref) .map(WitnessNode::::cached_data) - .map_witness(Option::>::clone); + .map_witness(Option::::clone); Ok(WitnessData::from_inner(&self.inference_context, inner).unwrap()) } } @@ -228,7 +228,7 @@ impl CoreConstructible for ConstructData { Arrow::fail(inference_context, entropy).into() } - fn const_word(inference_context: &types::Context, word: Arc) -> Self { + fn const_word(inference_context: &types::Context, word: simplicity::Value) -> Self { Arrow::const_word(inference_context, word).into() } @@ -282,7 +282,7 @@ pub trait CoreExt: CoreConstructible + Sized { /// ------------------- /// comp unit (const v) : A → B /// ``` - fn unit_const_value(inference_context: &types::Context, value: Arc) -> Self { + fn unit_const_value(inference_context: &types::Context, value: simplicity::Value) -> Self { Self::comp( &Self::unit(inference_context), &Self::const_word(inference_context, value), @@ -586,10 +586,7 @@ impl PairBuilder

{ /// --------------------------- /// comp unit (const v) : A → B /// ``` - pub fn unit_const_value( - inference_context: &types::Context, - value: Arc, - ) -> Self { + pub fn unit_const_value(inference_context: &types::Context, value: simplicity::Value) -> Self { Self(P::unit_const_value(inference_context, value)) } } diff --git a/src/value.rs b/src/value.rs index 5674e5c..32e76e4 100644 --- a/src/value.rs +++ b/src/value.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use either::Either; use miniscript::iter::{Tree, TreeLike}; +use simplicity::types::Final as SimType; use simplicity::Value as SimValue; use crate::array::{BTreeSlice, Partition}; @@ -708,7 +709,7 @@ impl Value { /// Structure of a Simfony value. /// 1:1 isomorphism to Simplicity. #[derive(Clone, Eq, PartialEq, Hash)] -pub struct StructuralValue(Arc); +pub struct StructuralValue(SimValue); impl AsRef for StructuralValue { fn as_ref(&self) -> &SimValue { @@ -716,7 +717,7 @@ impl AsRef for StructuralValue { } } -impl From for Arc { +impl From for SimValue { fn from(value: StructuralValue) -> Self { value.0 } @@ -724,10 +725,12 @@ impl From for Arc { impl TreeLike for StructuralValue { fn as_node(&self) -> Tree { - match self.as_ref() { - SimValue::Unit => Tree::Nullary, - SimValue::Left(l) | SimValue::Right(l) => Tree::Unary(Self(l.clone())), - SimValue::Product(l, r) => Tree::Binary(Self(l.clone()), Self(r.clone())), + use simplicity::dag::{Dag, DagLike}; + + match (&self.0).as_dag_node() { + Dag::Nullary => Tree::Nullary, + Dag::Unary(l) => Tree::Unary(Self(l.shallow_clone())), + Dag::Binary(l, r) => Tree::Binary(Self(l.shallow_clone()), Self(r.shallow_clone())), } } } @@ -757,20 +760,20 @@ impl ValueConstructible for StructuralValue { Self(SimValue::product(left.0, right.0)) } - fn left(left: Self, _right: Self::Type) -> Self { - Self(SimValue::left(left.0)) + fn left(left: Self, right: Self::Type) -> Self { + Self(SimValue::left(left.0, right.into())) } - fn right(_left: Self::Type, right: Self) -> Self { - Self(SimValue::right(right.0)) + fn right(left: Self::Type, right: Self) -> Self { + Self(SimValue::right(left.into(), right.0)) } - fn none(_inner: Self::Type) -> Self { - Self(SimValue::left(SimValue::unit())) + fn none(inner: Self::Type) -> Self { + Self(SimValue::none(inner.into())) } fn some(inner: Self) -> Self { - Self(SimValue::right(inner.0)) + Self(SimValue::some(inner.0)) } fn tuple>(elements: I) -> Self { @@ -819,8 +822,8 @@ impl ValueConstructible for StructuralValue { impl From for StructuralValue { fn from(value: bool) -> Self { match value { - false => Self(SimValue::left(SimValue::unit())), - true => Self(SimValue::right(SimValue::unit())), + false => Self(SimValue::left(SimValue::unit(), SimType::unit())), + true => Self(SimValue::right(SimType::unit(), SimValue::unit())), } } }