Skip to content

Commit

Permalink
f fixpoint expample progrem / rebale command
Browse files Browse the repository at this point in the history
  • Loading branch information
apoelstra committed Aug 14, 2023
1 parent bd5dd67 commit 04f8ffa
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
32 changes: 32 additions & 0 deletions simpcli/example_programs/fixpoint.simpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

-- Witnesses
-- IMR: [none]
wit_input := witness

-- All jets have source type 1; but to use the `pair` combinator we want one
-- with source type 2^256. To get this, we compose it with unit.
sha256_init :: 2^256 -> _
sha256_init := comp unit jet_sha_256_ctx_8_init

-- Using this, we can write a self-contained "take 32 bytes and compute their
-- sha2 hash" function.
-- IMR: 8e341445...
sha256 :: 2^256 -> 2^256
sha256 := comp
comp
pair sha256_init iden
jet_sha_256_ctx_8_add_32
jet_sha_256_ctx_8_finalize

-- Check eq
assert_fixpoint :: 2^256 -> 1
assert_fixpoint := comp
comp
pair (comp iden sha256) iden
jet_eq_256
jet_verify

-- IMR: [none]
main := comp wit_input assert_fixpoint


8 changes: 8 additions & 0 deletions simpcli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fn usage(process_name: &str) {
eprintln!("Usage:");
eprintln!(" {} assemble <filename>", process_name);
eprintln!(" {} disassemble <base64>", process_name);
eprintln!(" {} relabel <base64>", process_name);
eprintln!();
eprintln!("For commands which take an optional expression, the default value is \"main\".");
eprintln!();
Expand All @@ -43,6 +44,7 @@ fn invalid_usage(process_name: &str) -> Result<(), String> {
enum Command {
Assemble,
Disassemble,
Relabel,
Help,
}

Expand All @@ -52,6 +54,7 @@ impl FromStr for Command {
match s {
"assemble" => Ok(Command::Assemble),
"disassemble" => Ok(Command::Disassemble),
"relabel" => Ok(Command::Relabel),
"help" => Ok(Command::Help),
x => Err(format!("unknown command {}", x)),
}
Expand All @@ -63,6 +66,7 @@ impl Command {
match *self {
Command::Assemble => false,
Command::Disassemble => false,
Command::Relabel => false,
Command::Help => false,
}
}
Expand Down Expand Up @@ -153,6 +157,10 @@ fn main() -> Result<(), String> {
let prog = Forest::<DefaultJet>::from_program(commit);
println!("{}", prog.string_serialize());
}
Command::Relabel => {
let prog = parse_file(&first_arg)?;
println!("{}", prog.string_serialize());
}
Command::Help => unreachable!(),
}

Expand Down
10 changes: 6 additions & 4 deletions src/human_encoding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,13 @@ impl<J: Jet> Forest<J> {
let arrow_str = format!(": {} -> {}", arrow.source, arrow.target).replace('×', "*"); // for human-readable encoding stick with ASCII

// All witnesses have the same CMR so don't bother printing it
let cmr_str = if let node::Inner::Witness(..) = node.inner() {
let cmr_str = /*if let node::Inner::Witness(..) = node.inner() {
String::new()
} else {
format!("-- cmr {:.8}...", node.cmr())
};
} else { */
format!("-- cmr {}...", node.cmr())
+ &format!(" -- imr {}...", node.imr().as_ref().map(ToString::to_string).unwrap_or("???".to_string()))
// };
;

let print = Print {
expr_str,
Expand Down

0 comments on commit 04f8ffa

Please sign in to comment.