From 23a150c54da237fe9b0a1b2565cee883145f13c6 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Thu, 18 Dec 2025 15:15:24 +0000 Subject: [PATCH] bump rust-simplicity to 0.7; update `simplicity pset run` We retain the existing "only log jets in `simplicity pset run`" behavior, although we now have the ability to log every node. My expectation is that in practice users will usually only care about the flow of data between jets. We can add extensions later to improve this. Meanwhile, this greatly improves the output; rather than doing a hex dump we output a full value decode which distinguishes left and right sums and so on. We also split up the inputs to the eq_1 and eq_2 jets which we previously didn't do because they'd be less than one hex nybble. --- Cargo.lock | 15 +++-- Cargo.toml | 2 +- src/actions/simplicity/pset/run.rs | 92 +++++++++++++----------------- 3 files changed, 52 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e9c912..2af6f28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -296,6 +296,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "ghost-cell" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8449d342b1c67f49169e92e71deb7b9b27f30062301a16dbc27a4cc8d2351b7" + [[package]] name = "hal" version = "0.10.0" @@ -811,15 +817,16 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "simplicity-lang" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525879699aba1f7f75c0d97355475072adeb0ed0530df4e18f23235252475e68" +checksum = "70e57bd4d84853974a212eab24ed89da54f49fbccf5e33e93bcd29f0a6591cd5" dependencies = [ "bitcoin", "bitcoin_hashes 0.14.0", "byteorder", "elements", "getrandom", + "ghost-cell", "hex-conservative 0.2.1", "miniscript", "santiago", @@ -829,9 +836,9 @@ dependencies = [ [[package]] name = "simplicity-sys" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3abf9c7d64c5bf45bb2fb966f3b0637d8c13c8d5cdfbd7587900421cb7584c49" +checksum = "875630d128f19818161cefe0a3d910b6aae921d8246711db574a689cb2c11747" dependencies = [ "bitcoin_hashes 0.14.0", "cc", diff --git a/Cargo.toml b/Cargo.toml index 4601593..db830fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ serde_yaml = "0.8.8" hex = "0.3.2" elements = { version = "0.25.2", features = [ "serde", "base64" ] } -simplicity = { package = "simplicity-lang", version = "0.5.0", features = [ "base64", "serde" ] } +simplicity = { package = "simplicity-lang", version = "0.7.0", features = [ "base64", "serde" ] } thiserror = "2.0.17" [lints.clippy] diff --git a/src/actions/simplicity/pset/run.rs b/src/actions/simplicity/pset/run.rs index 211a0a2..5105fd3 100644 --- a/src/actions/simplicity/pset/run.rs +++ b/src/actions/simplicity/pset/run.rs @@ -4,9 +4,9 @@ use serde::Serialize; use crate::hal_simplicity::Program; -use crate::simplicity::bit_machine::{BitMachine, ExecTracker}; -use crate::simplicity::jet; -use crate::simplicity::{Cmr, Ihr}; +use crate::simplicity::bit_machine::{BitMachine, ExecTracker, FrameIter, NodeOutput}; +use crate::simplicity::Value; +use crate::simplicity::{jet, node}; use super::{execution_environment, PsetError}; @@ -37,8 +37,8 @@ pub struct JetCall { pub source_ty: String, pub target_ty: String, pub success: bool, - pub input_hex: String, - pub output_hex: String, + pub input_value: String, + pub output_value: String, #[serde(skip_serializing_if = "Option::is_none")] pub equality_check: Option<(String, String)>, } @@ -52,56 +52,44 @@ pub struct RunResponse { struct JetTracker(Vec); impl ExecTracker for JetTracker { - fn track_left(&mut self, _: Ihr) {} - fn track_right(&mut self, _: Ihr) {} - fn track_jet_call( + fn visit_node( &mut self, - jet: &J, - input_buffer: &[simplicity::ffi::ffi::UWORD], - output_buffer: &[simplicity::ffi::ffi::UWORD], - success: bool, + node: &simplicity::RedeemNode, + mut input: FrameIter, + output: NodeOutput, ) { - // The word slices are in reverse order for some reason. - // FIXME maybe we should attempt to parse out Simplicity values here which - // can often be displayed in a better way, esp for e.g. option types. - let mut input_hex = String::new(); - for word in input_buffer.iter().rev() { - for byte in word.to_be_bytes() { - input_hex.push_str(&format!("{:02x}", byte)); - } + if let node::Inner::Jet(jet) = node.inner() { + let input_value = Value::from_padded_bits(&mut input, &node.arrow().source) + .expect("valid value from bit machine"); + + let (success, output_value) = match output { + NodeOutput::NonTerminal => unreachable!(), + NodeOutput::JetFailed => (false, Value::unit()), + NodeOutput::Success(mut iter) => ( + true, + Value::from_padded_bits(&mut iter, &node.arrow().target) + .expect("valid value from bit machine"), + ), + }; + + let jet_name = jet.to_string(); + let equality_check = if jet_name.strip_prefix("eq_").is_some() { + let (left, right) = input_value.as_product().unwrap(); + Some((left.to_value().to_string(), right.to_value().to_string())) + } else { + None + }; + + self.0.push(JetCall { + jet: jet_name, + source_ty: jet.source_ty().to_final().to_string(), + target_ty: jet.target_ty().to_final().to_string(), + success, + input_value: input_value.to_string(), + output_value: output_value.to_string(), + equality_check, + }); } - - let mut output_hex = String::new(); - for word in output_buffer.iter().rev() { - for byte in word.to_be_bytes() { - output_hex.push_str(&format!("{:02x}", byte)); - } - } - - let jet_name = jet.to_string(); - let equality_check = match jet_name.as_str() { - "eq_1" => None, // FIXME parse bits out of input - "eq_2" => None, // FIXME parse bits out of input - x if x.strip_prefix("eq_").is_some() => { - let split = input_hex.split_at(input_hex.len() / 2); - Some((split.0.to_owned(), split.1.to_owned())) - } - _ => None, - }; - self.0.push(JetCall { - jet: jet_name, - source_ty: jet.source_ty().to_final().to_string(), - target_ty: jet.target_ty().to_final().to_string(), - success, - input_hex, - output_hex, - equality_check, - }); - } - - fn track_dbg_call(&mut self, _: &Cmr, _: simplicity::Value) {} - fn is_track_debug_enabled(&self) -> bool { - false } }