diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index 73b60795..b66bf887 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -35,7 +35,7 @@ parse_human, key: cache-${{ matrix.target }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }} - uses: actions-rs/toolchain@v1 with: - toolchain: 1.64 + toolchain: 1.65.0 override: true profile: minimal - name: fuzz diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e93abf96..5b086dad 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -104,6 +104,8 @@ jobs: cargo update -p proc-macro2 --precise 1.0.65 # 1.8.0 requires cargo 1.60+ cargo update -p regex --precise 1.7.0 + # 1.5.0 uses edition 2021 + cargo update -p byteorder --precise 1.4.3 fi for f in $FEATURES; do echo "Features: $f" && cargo test --no-default-features --features="$f"; done cd simplicity-sys diff --git a/fuzz/generate-files.sh b/fuzz/generate-files.sh index cfeb6add..aee7506e 100755 --- a/fuzz/generate-files.sh +++ b/fuzz/generate-files.sh @@ -74,7 +74,7 @@ $(for name in $(listTargetNames); do echo "$name,"; done) key: cache-\${{ matrix.target }}-\${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }} - uses: actions-rs/toolchain@v1 with: - toolchain: 1.64 + toolchain: 1.65.0 override: true profile: minimal - name: fuzz diff --git a/src/bit_machine/mod.rs b/src/bit_machine/mod.rs index 39cf132e..396e1645 100644 --- a/src/bit_machine/mod.rs +++ b/src/bit_machine/mod.rs @@ -20,10 +20,10 @@ mod frame; +use crate::analysis; use crate::dag::{DagLike, NoSharing}; use crate::jet::{Jet, JetFailed}; use crate::node::{self, RedeemNode}; -use crate::{analysis, types}; use crate::{Cmr, FailEntropy, Value}; use frame::Frame; use std::fmt; @@ -255,25 +255,15 @@ impl BitMachine { self.copy(size_a); } node::Inner::InjL(left) => { - let padl_b_c = - if let types::CompleteBound::Sum(b, _) = &ip.arrow().target.bound() { - ip.arrow().target.bit_width() - b.bit_width() - 1 - } else { - unreachable!() - }; - + let (b, _c) = ip.arrow().target.split_sum().unwrap(); + let padl_b_c = ip.arrow().target.bit_width() - b.bit_width() - 1; self.write_bit(false); self.skip(padl_b_c); call_stack.push(CallStack::Goto(left)); } node::Inner::InjR(left) => { - let padr_b_c = - if let types::CompleteBound::Sum(_, c) = &ip.arrow().target.bound() { - ip.arrow().target.bit_width() - c.bit_width() - 1 - } else { - unreachable!() - }; - + let (_b, c) = ip.arrow().target.split_sum().unwrap(); + let padr_b_c = ip.arrow().target.bit_width() - c.bit_width() - 1; self.write_bit(true); self.skip(padr_b_c); call_stack.push(CallStack::Goto(left)); @@ -313,13 +303,7 @@ impl BitMachine { } node::Inner::Take(left) => call_stack.push(CallStack::Goto(left)), node::Inner::Drop(left) => { - let size_a = - if let types::CompleteBound::Product(a, _) = &ip.arrow().source.bound() { - a.bit_width() - } else { - unreachable!() - }; - + let size_a = ip.arrow().source.split_product().unwrap().0.bit_width(); self.fwd(size_a); call_stack.push(CallStack::Back(size_a)); call_stack.push(CallStack::Goto(left)); @@ -327,17 +311,10 @@ impl BitMachine { node::Inner::Case(..) | node::Inner::AssertL(..) | node::Inner::AssertR(..) => { let choice_bit = self.read[self.read.len() - 1].peek_bit(&self.data); - let (size_a, size_b) = if let types::CompleteBound::Product(sum_a_b, _c) = - &ip.arrow().source.bound() - { - if let types::CompleteBound::Sum(a, b) = &sum_a_b.bound() { - (a.bit_width(), b.bit_width()) - } else { - unreachable!() - } - } else { - unreachable!() - }; + let (sum_a_b, _c) = ip.arrow().source.split_product().unwrap(); + let (a, b) = sum_a_b.split_sum().unwrap(); + let size_a = a.bit_width(); + let size_b = b.bit_width(); match (ip.inner(), choice_bit) { (node::Inner::Case(_, right), true) diff --git a/src/human_encoding/error.rs b/src/human_encoding/error.rs index 2b67e867..5fa90b56 100644 --- a/src/human_encoding/error.rs +++ b/src/human_encoding/error.rs @@ -88,13 +88,13 @@ impl ErrorSet { pub fn add, E: Into>(&mut self, position: P, err: E) { self.errors .entry(Some(position.into())) - .or_insert(vec![]) + .or_default() .push(err.into()); } /// Adds an error to the error set. pub fn add_no_position>(&mut self, err: E) { - self.errors.entry(None).or_insert(vec![]).push(err.into()); + self.errors.entry(None).or_default().push(err.into()); } /// Merges another set of errors into the current set. @@ -115,7 +115,7 @@ impl ErrorSet { for (pos, errs) in &other.errors { self.errors .entry(*pos) - .or_insert(vec![]) + .or_default() .extend(errs.iter().cloned()); } } diff --git a/src/merkle/amr.rs b/src/merkle/amr.rs index 34010c35..465d022a 100644 --- a/src/merkle/amr.rs +++ b/src/merkle/amr.rs @@ -60,7 +60,7 @@ impl Amr { /// Produce a CMR for an injl combinator pub fn injl(ty: &FinalArrow, child: Amr) -> Self { let a = &ty.source; - let (b, c) = ty.target.split().unwrap(); + let (b, c) = ty.target.split_sum().unwrap(); Self::INJL_IV .update(a.tmr().into(), b.tmr().into()) .update(c.tmr().into(), child) @@ -69,7 +69,7 @@ impl Amr { /// Produce a CMR for an injr combinator pub fn injr(ty: &FinalArrow, child: Amr) -> Self { let a = &ty.source; - let (b, c) = ty.target.split().unwrap(); + let (b, c) = ty.target.split_sum().unwrap(); Self::INJR_IV .update(a.tmr().into(), b.tmr().into()) .update(c.tmr().into(), child) @@ -77,7 +77,7 @@ impl Amr { /// Produce a CMR for a take combinator pub fn take(ty: &FinalArrow, child: Amr) -> Self { - let (a, b) = ty.source.split().unwrap(); + let (a, b) = ty.source.split_product().unwrap(); let c = &ty.target; Self::TAKE_IV .update(a.tmr().into(), b.tmr().into()) @@ -86,7 +86,7 @@ impl Amr { /// Produce a CMR for a drop combinator pub fn drop(ty: &FinalArrow, child: Amr) -> Self { - let (a, b) = ty.source.split().unwrap(); + let (a, b) = ty.source.split_product().unwrap(); let c = &ty.target; Self::DROP_IV .update(a.tmr().into(), b.tmr().into()) @@ -105,8 +105,8 @@ impl Amr { } fn case_helper(iv: Amr, ty: &FinalArrow, left: Amr, right: Amr) -> Self { - let (sum_a_b, c) = ty.source.split().unwrap(); - let (a, b) = sum_a_b.split().unwrap(); + let (sum_a_b, c) = ty.source.split_product().unwrap(); + let (a, b) = sum_a_b.split_sum().unwrap(); let d = &ty.target; iv.update(a.tmr().into(), b.tmr().into()) .update(c.tmr().into(), d.tmr().into()) @@ -148,7 +148,7 @@ impl Amr { /// Produce a CMR for a disconnect combinator pub fn disconnect(ty: &FinalArrow, right_arrow: &FinalArrow, left: Amr, right: Amr) -> Self { let a = &ty.source; - let (b, d) = ty.target.split().unwrap(); + let (b, d) = ty.target.split_product().unwrap(); let c = &right_arrow.source; Self::DISCONNECT_IV .update(a.tmr().into(), b.tmr().into()) diff --git a/src/types/final_data.rs b/src/types/final_data.rs index 30b7f36b..7239af05 100644 --- a/src/types/final_data.rs +++ b/src/types/final_data.rs @@ -61,7 +61,7 @@ impl Eq for Final {} impl PartialOrd for Final { fn partial_cmp(&self, other: &Self) -> Option { - self.tmr.partial_cmp(&other.tmr) + Some(self.cmp(other)) } } impl Ord for Final { @@ -213,13 +213,19 @@ impl Final { self.bound == CompleteBound::Unit } - /// Accessor for both children of the type, if they exist. - pub fn split(&self) -> Option<(Arc, Arc)> { + /// Return both children, if the type is a sum type + pub fn split_sum(&self) -> Option<(Arc, Arc)> { match &self.bound { - CompleteBound::Unit => None, - CompleteBound::Sum(left, right) | CompleteBound::Product(left, right) => { - Some((Arc::clone(left), Arc::clone(right))) - } + CompleteBound::Sum(left, right) => Some((left.clone(), right.clone())), + _ => None, + } + } + + /// Return both children, if the type is a product type + pub fn split_product(&self) -> Option<(Arc, Arc)> { + match &self.bound { + CompleteBound::Product(left, right) => Some((left.clone(), right.clone())), + _ => None, } } }