Skip to content

Commit 2805f68

Browse files
committed
Merge #35: bump rust-simplicity to 0.7; update simplicity pset run
23a150c bump rust-simplicity to 0.7; update `simplicity pset run` (Andrew Poelstra) Pull request description: 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. ACKs for top commit: delta1: ACK 23a150c Tree-SHA512: 23768c22795a81ac453dc667b6bbba257129936d80cf670f40135a421085eac774d5aecd3ca0175f4690bad6f45771b08bd6aac6795c6e867974ff4cec346531
2 parents 3108313 + 23a150c commit 2805f68

File tree

3 files changed

+52
-57
lines changed

3 files changed

+52
-57
lines changed

Cargo.lock

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ serde_yaml = "0.8.8"
3131
hex = "0.3.2"
3232

3333
elements = { version = "0.25.2", features = [ "serde", "base64" ] }
34-
simplicity = { package = "simplicity-lang", version = "0.5.0", features = [ "base64", "serde" ] }
34+
simplicity = { package = "simplicity-lang", version = "0.7.0", features = [ "base64", "serde" ] }
3535
thiserror = "2.0.17"
3636

3737
[lints.clippy]

src/actions/simplicity/pset/run.rs

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
use serde::Serialize;
55

66
use crate::hal_simplicity::Program;
7-
use crate::simplicity::bit_machine::{BitMachine, ExecTracker};
8-
use crate::simplicity::jet;
9-
use crate::simplicity::{Cmr, Ihr};
7+
use crate::simplicity::bit_machine::{BitMachine, ExecTracker, FrameIter, NodeOutput};
8+
use crate::simplicity::Value;
9+
use crate::simplicity::{jet, node};
1010

1111
use super::{execution_environment, PsetError};
1212

@@ -37,8 +37,8 @@ pub struct JetCall {
3737
pub source_ty: String,
3838
pub target_ty: String,
3939
pub success: bool,
40-
pub input_hex: String,
41-
pub output_hex: String,
40+
pub input_value: String,
41+
pub output_value: String,
4242
#[serde(skip_serializing_if = "Option::is_none")]
4343
pub equality_check: Option<(String, String)>,
4444
}
@@ -52,56 +52,44 @@ pub struct RunResponse {
5252
struct JetTracker(Vec<JetCall>);
5353

5454
impl<J: jet::Jet> ExecTracker<J> for JetTracker {
55-
fn track_left(&mut self, _: Ihr) {}
56-
fn track_right(&mut self, _: Ihr) {}
57-
fn track_jet_call(
55+
fn visit_node(
5856
&mut self,
59-
jet: &J,
60-
input_buffer: &[simplicity::ffi::ffi::UWORD],
61-
output_buffer: &[simplicity::ffi::ffi::UWORD],
62-
success: bool,
57+
node: &simplicity::RedeemNode<J>,
58+
mut input: FrameIter,
59+
output: NodeOutput,
6360
) {
64-
// The word slices are in reverse order for some reason.
65-
// FIXME maybe we should attempt to parse out Simplicity values here which
66-
// can often be displayed in a better way, esp for e.g. option types.
67-
let mut input_hex = String::new();
68-
for word in input_buffer.iter().rev() {
69-
for byte in word.to_be_bytes() {
70-
input_hex.push_str(&format!("{:02x}", byte));
71-
}
61+
if let node::Inner::Jet(jet) = node.inner() {
62+
let input_value = Value::from_padded_bits(&mut input, &node.arrow().source)
63+
.expect("valid value from bit machine");
64+
65+
let (success, output_value) = match output {
66+
NodeOutput::NonTerminal => unreachable!(),
67+
NodeOutput::JetFailed => (false, Value::unit()),
68+
NodeOutput::Success(mut iter) => (
69+
true,
70+
Value::from_padded_bits(&mut iter, &node.arrow().target)
71+
.expect("valid value from bit machine"),
72+
),
73+
};
74+
75+
let jet_name = jet.to_string();
76+
let equality_check = if jet_name.strip_prefix("eq_").is_some() {
77+
let (left, right) = input_value.as_product().unwrap();
78+
Some((left.to_value().to_string(), right.to_value().to_string()))
79+
} else {
80+
None
81+
};
82+
83+
self.0.push(JetCall {
84+
jet: jet_name,
85+
source_ty: jet.source_ty().to_final().to_string(),
86+
target_ty: jet.target_ty().to_final().to_string(),
87+
success,
88+
input_value: input_value.to_string(),
89+
output_value: output_value.to_string(),
90+
equality_check,
91+
});
7292
}
73-
74-
let mut output_hex = String::new();
75-
for word in output_buffer.iter().rev() {
76-
for byte in word.to_be_bytes() {
77-
output_hex.push_str(&format!("{:02x}", byte));
78-
}
79-
}
80-
81-
let jet_name = jet.to_string();
82-
let equality_check = match jet_name.as_str() {
83-
"eq_1" => None, // FIXME parse bits out of input
84-
"eq_2" => None, // FIXME parse bits out of input
85-
x if x.strip_prefix("eq_").is_some() => {
86-
let split = input_hex.split_at(input_hex.len() / 2);
87-
Some((split.0.to_owned(), split.1.to_owned()))
88-
}
89-
_ => None,
90-
};
91-
self.0.push(JetCall {
92-
jet: jet_name,
93-
source_ty: jet.source_ty().to_final().to_string(),
94-
target_ty: jet.target_ty().to_final().to_string(),
95-
success,
96-
input_hex,
97-
output_hex,
98-
equality_check,
99-
});
100-
}
101-
102-
fn track_dbg_call(&mut self, _: &Cmr, _: simplicity::Value) {}
103-
fn is_track_debug_enabled(&self) -> bool {
104-
false
10593
}
10694
}
10795

0 commit comments

Comments
 (0)