Skip to content

Commit

Permalink
chore: Update simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
uncomputable committed Sep 3, 2024
1 parent 23d64b6 commit 6df65cc
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 38 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ lto = true

[dependencies]
itertools = "0.13.0"
simfony = { git = "https://github.com/BlockstreamResearch/simfony", branch = "master" }
simfony = { git = "https://github.com/BlockstreamResearch/simfony", rev = "c75cd2abe0b7dce2284b5e96d28a63e767b034d8" }
leptos = { version = "0.6.14", features = ["csr"] }
console_error_panic_hook = "0.1.7"
hex-conservative = "0.1.1"
Expand Down
4 changes: 2 additions & 2 deletions src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl Runner {
};
self.input.push(Task::Execute(s_state));
}
Inner::Witness(value) => self.output.push(Arc::new(ExtValue::from(value.as_ref()))),
Inner::Witness(value) => self.output.push(Arc::new(ExtValue::from(value))),
Inner::Fail(_) => {
return Err(Error::new(ErrorKind::FailNode, state));
}
Expand All @@ -344,7 +344,7 @@ impl Runner {
}
}
}
Inner::Word(value) => self.output.push(Arc::new(ExtValue::from(value.as_ref()))),
Inner::Word(value) => self.output.push(Arc::new(ExtValue::from(value))),
};

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/jet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn execute_jet_with_env<J: Jet>(
unsafe { get_output_frame(output_type.bit_width()) };

let jet_fn = jet.c_jet_ptr();
let c_env = jet.c_jet_env(env);
let c_env = J::c_jet_env(env);
let success = jet_fn(&mut output_write_frame, input_read_frame, c_env);

if !success {
Expand Down
4 changes: 2 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'a, M: node::Marker> fmt::Display for DisplayInner<'a, M> {
Inner::Witness(_) => f.write_str("witness"),
Inner::Fail(_) => f.write_str("fail"),
Inner::Jet(jet) => write!(f, "jet_{}", jet),
Inner::Word(value) => write!(f, "const {}", ExtValue::from(value.as_ref())),
Inner::Word(value) => write!(f, "const {}", ExtValue::from(value)),
}
}
}
Expand All @@ -75,7 +75,7 @@ where
&'a node::Node<M>: DagLike,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for data in self.0.verbose_pre_order_iter::<NoSharing>() {
for data in self.0.verbose_pre_order_iter::<NoSharing>(None) {
match data.n_children_yielded {
1 => {
if let Dag::Binary(..) = data.node.inner().as_dag() {
Expand Down
49 changes: 20 additions & 29 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub enum ExtValue {

impl fmt::Display for ExtValue {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for data in self.verbose_pre_order_iter::<NoSharing>() {
for data in self.verbose_pre_order_iter::<NoSharing>(None) {
match data.node {
ExtValue::Unit => f.write_str("●")?,
ExtValue::Left(..) => {
Expand Down Expand Up @@ -490,24 +490,21 @@ impl<'a> From<&'a Value> for ExtValue {
fn from(value: &'a Value) -> Self {
let mut stack = vec![];
for data in value.post_order_iter::<NoSharing>() {
match data.node {
Value::Unit => stack.push(Item::Value(ExtValue::Unit)),
Value::SumL(..) => {
let tmp = stack.pop().unwrap().into_left();
stack.push(tmp)
}
Value::SumR(..) => {
let tmp = stack.pop().unwrap().into_right();
stack.push(tmp);
}
Value::Prod(..) => {
let tmp = stack.pop().unwrap().into_product(stack.pop().unwrap());
stack.push(tmp);
}
if data.node.is_unit() {
stack.push(Item::Value(ExtValue::Unit));
} else if data.node.as_left().is_some() {
let tmp = stack.pop().unwrap().into_left();
stack.push(tmp);
} else if data.node.as_right().is_some() {
let tmp = stack.pop().unwrap().into_right();
stack.push(tmp);
} else if data.node.as_product().is_some() {
let tmp = stack.pop().unwrap().into_product(stack.pop().unwrap());
stack.push(tmp);
}
}

debug_assert!(stack.len() == 1);
debug_assert_eq!(stack.len(), 1);
stack.pop().unwrap().into_extvalue()
}
}
Expand Down Expand Up @@ -611,38 +608,32 @@ mod tests {
fn extvalue_from_value() {
let output_input = vec![
(ExtValue::unit(), Value::unit()),
(
ExtValue::bits(Bits::from_bit(false)),
Value::sum_l(Value::unit()),
),
(
ExtValue::bits(Bits::from_bit(true)),
Value::sum_r(Value::unit()),
),
(ExtValue::bits(Bits::from_bit(false)), Value::u1(0)),
(ExtValue::bits(Bits::from_bit(true)), Value::u1(1)),
(
ExtValue::left(ExtValue::bits(Bits::from_bit(true))),
Value::sum_l(Value::sum_r(Value::unit())),
Value::left(Value::u1(1), Final::unit()),
),
(
ExtValue::product(ExtValue::unit(), ExtValue::unit()),
Value::prod(Value::unit(), Value::unit()),
Value::product(Value::unit(), Value::unit()),
),
(
ExtValue::bytes(Bytes::from_bytes(Cmr::unit())),
Value::u256_from_slice(Cmr::unit().as_ref()),
Value::u256(Cmr::unit().to_byte_array()),
),
(
ExtValue::bytes(Bytes::from_bytes(vec![0b01010101])),
Value::u8(0b01010101),
),
(
ExtValue::bytes(Bytes::from_bytes(vec![0xab, 0xcd])),
Value::prod(Value::u8(0xab), Value::u8(0xcd)),
Value::product(Value::u8(0xab), Value::u8(0xcd)),
),
];

for (expected_output, input) in output_input {
assert_eq!(expected_output.as_ref(), &ExtValue::from(input.as_ref()));
assert_eq!(expected_output.as_ref(), &ExtValue::from(&input));
}
}

Expand Down

0 comments on commit 6df65cc

Please sign in to comment.