-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #169: Introduce typed holes; improve disconnect support in huma…
…n-readable encoding 5465612 human_encoding: output both CMR and IMR when disassembling programs; add more spacing (Andrew Poelstra) 7494aab simpcli: fixpoint example program, and `relabel` command (Andrew Poelstra) 2680e3e node: expose IMR in CommitData (Andrew Poelstra) 0fbddc6 human_readable: add fuzztest (Andrew Poelstra) 2ceb135 human_encoding: make disconnect a binary combinator with a hole for a right child (Andrew Poelstra) 3f974d0 human_encoding: add typed holes (Andrew Poelstra) 045a3c3 simpcli: add example programs directory (Andrew Poelstra) Pull request description: This introduces the notion of "typed holes" which can be used as placeholders in the text encoding of Simplicity. It uses these holes for disconnect, so that at commitment time users can set their right children to placeholders. The old behavior, which allowed putting a complete expression into `disconnect` that wouldn't be committed to, was dangerous. ACKs for top commit: uncomputable: 5465612 ACK. Sanket's bug is already present on master. Tree-SHA512: 08e2529cd7ddc4238635550e34aea1ab0d1dcaa8a83124701329f390624d218c9893948174e15ff04bd1431c5b6d320ed28e54aa470f18e752db5d76eee0a6a9
- Loading branch information
Showing
15 changed files
with
311 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Rust Simplicity Library | ||
// Written in 2023 by | ||
// Andrew Poelstra <[email protected]> | ||
// | ||
// To the extent possible under law, the author(s) have dedicated all | ||
// copyright and related and neighboring rights to this software to | ||
// the public domain worldwide. This software is distributed without | ||
// any warranty. | ||
// | ||
// You should have received a copy of the CC0 Public Domain Dedication | ||
// along with this software. | ||
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
// | ||
|
||
use std::str; | ||
use honggfuzz::fuzz; | ||
use simplicity::jet::Elements; | ||
use simplicity::human_encoding::Forest; | ||
|
||
fn do_test(data: &[u8]) { | ||
let s = match str::from_utf8(data) { | ||
Ok(s) => s, | ||
Err(_) => return, | ||
}; | ||
|
||
if let Ok(program) = Forest::<Elements>::parse(s) { | ||
let reserialize= program.string_serialize(); | ||
let round_trip = Forest::<Elements>::parse(&reserialize).unwrap(); | ||
assert_eq!(program, round_trip); | ||
} | ||
} | ||
|
||
fn main() { | ||
loop { | ||
fuzz!(|data| { | ||
do_test(data); | ||
}); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) { | ||
let mut b = 0; | ||
for (idx, c) in hex.as_bytes().iter().enumerate() { | ||
b <<= 4; | ||
match *c { | ||
b'A'..=b'F' => b |= c - b'A' + 10, | ||
b'a'..=b'f' => b |= c - b'a' + 10, | ||
b'0'..=b'9' => b |= c - b'0', | ||
_ => panic!("Bad hex"), | ||
} | ||
if (idx & 1) == 1 { | ||
out.push(b); | ||
b = 0; | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn duplicate_crash() { | ||
let mut a = Vec::new(); | ||
extend_vec_from_hex("00", &mut a); | ||
super::do_test(&a); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- Witnesses | ||
sig1 := witness : 1 -> 2^512 | ||
|
||
-- Constants | ||
const1 := const 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f90000000000000000000000000000000000000000000000000000000000000000 : 1 -> 2^512 -- f254d6e9 | ||
|
||
-- Program code | ||
pr1 := pair const1 sig1 : 1 -> (2^512 * 2^512) -- 31ae2960 | ||
jt2 := jet_bip_0340_verify : (2^512 * 2^512) -> 1 -- af924cbe | ||
|
||
main := comp pr1 jt2 : 1 -> 1 -- 7bc56cb1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- Program which demands two 32-bit witnesses, the first one == the second + 1 | ||
wit1 := comp iden witness : 1 -> 2^32 | ||
wit2 := comp iden witness : 1 -> 2^32 | ||
|
||
wit_diff := comp (comp (pair wit1 wit2) jet_subtract_32) (drop iden) : 1 -> 2^32 | ||
diff_is_one := comp (pair wit_diff jet_one_32) jet_eq_32 : 1 -> 2 | ||
main := comp diff_is_one jet_verify : 1 -> 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- | ||
-- Attempts to reuse a witness name. | ||
-- | ||
-- By uncommenting wit2 and replacing one of the wit1 references with wit2, | ||
-- it'll work...but is it what you intended? | ||
-- | ||
|
||
wit1 := witness : 1 -> 2^32 | ||
--wit2 := witness : 1 -> 2^32 | ||
wit_tuple := pair wit1 wit1 : 1 -> 2^64 | ||
|
||
check_eq := comp wit_tuple jet_eq_32 | ||
main := comp check_eq jet_verify | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.