From 864c2ad8b3543ef68996a3a30431c315e1043bb9 Mon Sep 17 00:00:00 2001 From: arty Date: Sun, 18 Jun 2023 09:34:03 -0700 Subject: [PATCH 01/14] Specify the version of wasm-pack --- .github/workflows/npm-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index d8424af7c..395a02866 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -30,7 +30,7 @@ jobs: components: rustfmt, clippy - name: install wasm-pack - run: cargo install wasm-pack + run: cargo install --version 0.11.1 wasm-pack - name: wasm-pack build and pack run: wasm-pack build --release --target=nodejs wasm && wasm-pack pack wasm From b9f7630a69c6bf05fda641a312996bc723201a1a Mon Sep 17 00:00:00 2001 From: arty Date: Tue, 25 Jul 2023 08:34:48 -0700 Subject: [PATCH 02/14] Update recompile check for new tree layout in chia-blockchain --- support/recompile_check.py | 80 +++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/support/recompile_check.py b/support/recompile_check.py index 81c1244d3..6294106b4 100644 --- a/support/recompile_check.py +++ b/support/recompile_check.py @@ -1,24 +1,56 @@ import os +from pathlib import Path import subprocess import traceback +FULL_NODE='chia/full_node/puzzles' +CAT_WALLET='chia/wallet/cat_wallet/puzzles' +DID_WALLET='chia/wallet/did_wallet/puzzles' +NFT_WALLET='chia/wallet/nft_wallet/puzzles' +POOLS='chia/pools/puzzles' +CONSENSUS='chia/consensus/puzzles' +GENTEST='tests/generator/puzzles' + +def full_node(x): + return {'fname': x, 'dirname': FULL_NODE} + +def cat_wallet(x): + return {'fname': x, 'dirname': CAT_WALLET} + +def did_wallet(x): + return {'fname': x, 'dirname': DID_WALLET} + +def nft_wallet(x): + return {'fname': x, 'dirname': NFT_WALLET} + +def pools(x): + return {'fname': x, 'dirname': POOLS} + +def consensus(x): + return {'fname': x, 'dirname': CONSENSUS} + +def gentest(x): + return {'fname': x, 'dirname': GENTEST} + recompile_list = [ - 'block_program_zero.clsp', + full_node('block_program_zero.clsp'), + full_node('decompress_coin_spend_entry.clsp'), + full_node('decompress_coin_spend_entry_with_prefix.clsp'), + full_node('decompress_puzzle.clsp'), + cat_wallet('delegated_tail.clsp'), + cat_wallet('everything_with_signature.clsp'), + cat_wallet('genesis_by_coin_id.clsp'), + cat_wallet('genesis_by_puzzle_hash.clsp'), + did_wallet('did_innerpuz.clsp'), + nft_wallet('nft_metadata_updater_default.clsp'), + nft_wallet('nft_metadata_updater_updateable.clsp'), + nft_wallet('nft_ownership_layer.clsp'), + nft_wallet('nft_ownership_transfer_program_one_way_claim_with_royalties.clsp'), + nft_wallet('nft_state_layer.clsp'), + pools('pool_member_innerpuz.clsp'), + pools('pool_waitingroom_innerpuz.clsp'), + consensus('rom_bootstrap_generator.clsp'), 'calculate_synthetic_public_key.clsp', - 'chialisp_deserialisation.clsp', - 'decompress_coin_spend_entry.clsp', - 'decompress_coin_spend_entry_with_prefix.clsp', - 'decompress_puzzle.clsp', - 'delegated_tail.clsp', - 'did_innerpuz.clsp', - 'everything_with_signature.clsp', - 'genesis_by_coin_id.clsp', - 'genesis_by_puzzle_hash.clsp', - 'nft_metadata_updater_default.clsp', - 'nft_metadata_updater_updateable.clsp', - 'nft_ownership_layer.clsp', - 'nft_ownership_transfer_program_one_way_claim_with_royalties.clsp', - 'nft_state_layer.clsp', 'p2_conditions.clsp', 'p2_delegated_conditions.clsp', 'p2_delegated_puzzle.clsp', @@ -27,24 +59,28 @@ 'p2_puzzle_hash.clsp', 'p2_singleton.clsp', 'p2_singleton_or_delayed_puzhash.clsp', - 'pool_member_innerpuz.clsp', - 'pool_waitingroom_innerpuz.clsp', - 'rom_bootstrap_generator.clsp', 'settlement_payments.clsp', 'sha256tree_module.clsp', 'singleton_launcher.clsp', 'singleton_top_layer.clsp', 'singleton_top_layer_v1_1.clsp', - 'test_generator_deserialize.clsp', - 'test_multiple_generator_input_arguments.clsp' + gentest('test_generator_deserialize.clsp'), + gentest('test_multiple_generator_input_arguments.clsp') ] for fname in recompile_list: - hexfile = f'./chia/wallet/puzzles/{fname}.hex' + if 'dirname' in fname and 'fname' in fname: + dirname = fname['dirname'] + fname = fname['fname'] + else: + dirname = 'chia/wallet/puzzles' + + srcfile = str(Path(dirname) / Path(fname)) + hexfile = f'{str(srcfile)}.hex' hexdata = open(hexfile).read().strip() os.unlink(hexfile) try: - compiled = subprocess.check_output(['../target/release/run', '-i', 'chia/wallet/puzzles/', f'chia/wallet/puzzles/{fname}']).strip() + compiled = subprocess.check_output(['../target/release/run', '-i', dirname, '-i', 'chia/wallet/puzzles', srcfile]).strip() recompile = subprocess.check_output(['../target/release/opc', compiled]).decode('utf8').strip() except: print(f'compiling {fname}') From 7264b180fddf2c55c33249b8361e8ae49731f3c1 Mon Sep 17 00:00:00 2001 From: arty Date: Tue, 25 Jul 2023 08:42:07 -0700 Subject: [PATCH 03/14] New clippy edition issues --- src/classic/clvm_tools/stages/stage_2/optimize.rs | 5 ++--- src/compiler/codegen.rs | 2 +- src/compiler/compiler.rs | 4 ++-- src/compiler/frontend.rs | 2 +- src/compiler/sexp.rs | 4 ++-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/classic/clvm_tools/stages/stage_2/optimize.rs b/src/classic/clvm_tools/stages/stage_2/optimize.rs index d723e279f..7fde38552 100644 --- a/src/classic/clvm_tools/stages/stage_2/optimize.rs +++ b/src/classic/clvm_tools/stages/stage_2/optimize.rs @@ -1,4 +1,3 @@ -use std::borrow::Borrow; use std::cell::{Ref, RefCell}; use std::collections::HashMap; use std::mem::swap; @@ -635,7 +634,7 @@ pub fn optimize_sexp_( // pass and need to cache the result. { let memo_ref: Ref> = memo.borrow(); - let memo: &HashMap = memo_ref.borrow(); + let memo: &HashMap = &memo_ref; if let Some(res) = memo.get(&AllocatorRefOrTreeHash::new_from_nodeptr(r_)) { return Ok(*res); } @@ -645,7 +644,7 @@ pub fn optimize_sexp_( let footprint = AllocatorRefOrTreeHash::new_from_sexp(allocator, r_); { let memo_ref: Ref> = memo.borrow(); - let memo: &HashMap = memo_ref.borrow(); + let memo: &HashMap = &memo_ref; if let Some(res) = memo.get(&footprint) { return Ok(*res); } diff --git a/src/compiler/codegen.rs b/src/compiler/codegen.rs index 20fff0062..48527f81f 100644 --- a/src/compiler/codegen.rs +++ b/src/compiler/codegen.rs @@ -91,7 +91,7 @@ fn helper_atom(h: &HelperForm) -> SExp { fn build_tree(l: Srcloc, s: usize, e: usize, helper_array: &[HelperForm]) -> SExp { if e - s == 1 { - helper_atom(helper_array[s].borrow()) + helper_atom(&helper_array[s]) } else { let mid = (e + s) / 2; let car = build_tree(l.clone(), s, mid, helper_array); diff --git a/src/compiler/compiler.rs b/src/compiler/compiler.rs index 7639f88b5..bab6a1020 100644 --- a/src/compiler/compiler.rs +++ b/src/compiler/compiler.rs @@ -472,7 +472,7 @@ pub fn extract_program_and_env(program: Rc) -> Option<(Rc, Rc) return None; } - match (is_apply(&lst[0]), lst[1].borrow(), lst[2].proper_list()) { + match (is_apply(&lst[0]), &lst[1], lst[2].proper_list()) { (true, real_program, Some(cexp)) => { if cexp.len() != 3 || !is_cons(&cexp[0]) || !is_whole_env(&cexp[2]) { None @@ -492,7 +492,7 @@ pub fn is_at_capture(head: Rc, rest: Rc) -> Option<(Vec, Rc { - let compiled_val: &CompileForm = v.borrow(); + let compiled_val: &CompileForm = &v; Ok(compiled_val.clone()) } }; diff --git a/src/compiler/sexp.rs b/src/compiler/sexp.rs index 599eea3fe..881694f82 100644 --- a/src/compiler/sexp.rs +++ b/src/compiler/sexp.rs @@ -143,7 +143,7 @@ impl Display for SExp { } else { let vlen = s.len() * 2; let mut outbuf = vec![0; vlen]; - bin2hex(s, &mut outbuf).map_err(|_e| std::fmt::Error::default())?; + bin2hex(s, &mut outbuf).map_err(|_e| std::fmt::Error)?; formatter.write_str("0x")?; formatter.write_str( std::str::from_utf8(&outbuf).expect("only hex digits expected"), @@ -781,7 +781,7 @@ where for this_char in s { let next_location = start.clone().advance(this_char); - match parse_sexp_step(start.clone(), parse_state.borrow(), this_char) { + match parse_sexp_step(start.clone(), &parse_state, this_char) { SExpParseResult::Error(l, e) => { return Err((l, e)); } From 960b9fb3c4804679afe8bf21de991da0f75c57bd Mon Sep 17 00:00:00 2001 From: arty Date: Tue, 25 Jul 2023 16:57:06 -0700 Subject: [PATCH 04/14] Use nicer names --- support/recompile_check.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/support/recompile_check.py b/support/recompile_check.py index 6294106b4..7b5f726ba 100644 --- a/support/recompile_check.py +++ b/support/recompile_check.py @@ -68,14 +68,15 @@ def gentest(x): gentest('test_multiple_generator_input_arguments.clsp') ] -for fname in recompile_list: - if 'dirname' in fname and 'fname' in fname: - dirname = fname['dirname'] - fname = fname['fname'] +for recompile_entry in recompile_list: + if 'dirname' in recompile_entry and 'fname' in recompile_entry: + dirname = recompile_entry['dirname'] + filename = recompile_entry['fname'] else: + filename = recompile_entry dirname = 'chia/wallet/puzzles' - srcfile = str(Path(dirname) / Path(fname)) + srcfile = str(Path(dirname) / Path(filename)) hexfile = f'{str(srcfile)}.hex' hexdata = open(hexfile).read().strip() os.unlink(hexfile) From 4c08b012db9c787ef730ae2a4a4d92a23719923a Mon Sep 17 00:00:00 2001 From: arty Date: Wed, 26 Jul 2023 04:24:20 -0700 Subject: [PATCH 05/14] Two removed modules upstream (calculate_synthetic_public_key.clsp and sha256tree_module.clsp) --- support/recompile_check.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/support/recompile_check.py b/support/recompile_check.py index 7b5f726ba..c991198e4 100644 --- a/support/recompile_check.py +++ b/support/recompile_check.py @@ -50,7 +50,6 @@ def gentest(x): pools('pool_member_innerpuz.clsp'), pools('pool_waitingroom_innerpuz.clsp'), consensus('rom_bootstrap_generator.clsp'), - 'calculate_synthetic_public_key.clsp', 'p2_conditions.clsp', 'p2_delegated_conditions.clsp', 'p2_delegated_puzzle.clsp', @@ -60,7 +59,6 @@ def gentest(x): 'p2_singleton.clsp', 'p2_singleton_or_delayed_puzhash.clsp', 'settlement_payments.clsp', - 'sha256tree_module.clsp', 'singleton_launcher.clsp', 'singleton_top_layer.clsp', 'singleton_top_layer_v1_1.clsp', From c3db5b7618fff285c8b80a9fd4ad753ea23da8a0 Mon Sep 17 00:00:00 2001 From: arty Date: Thu, 27 Jul 2023 19:03:14 -0700 Subject: [PATCH 06/14] Isolated change to upgrade clvmr --- .github/workflows/build-test.yml | 2 +- Cargo.lock | 267 +++++++++++++++--- Cargo.toml | 4 +- src/classic/clvm/serialize.rs | 8 +- src/classic/clvm/sexp.rs | 22 +- src/classic/clvm_tools/binutils.rs | 7 +- src/classic/clvm_tools/clvmc.rs | 11 +- src/classic/clvm_tools/debug.rs | 2 +- src/classic/clvm_tools/pattern_match.rs | 50 ++-- src/classic/clvm_tools/sha256tree.rs | 5 +- src/classic/clvm_tools/stages/stage_0.rs | 8 +- .../clvm_tools/stages/stage_2/compile.rs | 73 +++-- .../clvm_tools/stages/stage_2/inline.rs | 19 +- .../clvm_tools/stages/stage_2/module.rs | 23 +- .../clvm_tools/stages/stage_2/operators.rs | 66 +++-- .../clvm_tools/stages/stage_2/optimize.rs | 46 +-- .../clvm_tools/stages/stage_2/reader.rs | 10 +- src/compiler/clvm.rs | 6 +- src/tests/classic/smoke.rs | 61 +++- wasm/Cargo.lock | 106 +++---- wasm/Cargo.toml | 2 +- 21 files changed, 542 insertions(+), 256 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 98330573c..24a3522d6 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -79,7 +79,7 @@ jobs: . ./activate && \ pip install --upgrade pip ' - docker run --rm -v $(pwd):/io ghcr.io/pyo3/maturin:v0.13.1 build --release --strip --manylinux 2010 + docker run --rm -v $(pwd):/io ghcr.io/pyo3/maturin:v1.1.0 build --release --strip --manylinux 2014 # Refresh in case any ownerships changed. mv target target.docker && cp -r target.docker target # Ensure an empty .cargo-lock file exists. diff --git a/Cargo.lock b/Cargo.lock index 182446923..740e20834 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,18 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "binascii" version = "0.1.4" @@ -43,19 +55,20 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ "generic-array", ] [[package]] name = "bls12_381" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62250ece575fa9b22068b3a8d59586f01d426dd7785522efd97632959e71c986" +checksum = "d7bc6d6292be3a19e6379786dac800f551e5865a5bb51ebbe3064ab80433f403" dependencies = [ + "digest 0.9.0", "ff", "group", "pairing", @@ -116,7 +129,7 @@ dependencies = [ "rand_chacha", "serde", "serde_json", - "sha2 0.9.5", + "sha2 0.9.9", "tempfile", "unicode-segmentation", "wasm-bindgen", @@ -126,17 +139,21 @@ dependencies = [ [[package]] name = "clvmr" -version = "0.1.24" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5e907612d322d0d7def6b0ecb3ad681f6af2db106bcfabe4153746c60ef9e4" +checksum = "83afaa6d5081706f202d31ed08ddb2425c902ca968d9832429bcdf9474ca6c9f" dependencies = [ "bls12_381", + "getrandom", + "group", "hex", + "k256", "lazy_static", "num-bigint", "num-integer", "num-traits", - "sha2 0.10.2", + "p256", + "sha2 0.9.9", ] [[package]] @@ -150,13 +167,10 @@ dependencies = [ ] [[package]] -name = "cpufeatures" -version = "0.1.5" +name = "const-oid" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" -dependencies = [ - "libc", -] +checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" [[package]] name = "cpufeatures" @@ -167,6 +181,18 @@ dependencies = [ "libc", ] +[[package]] +name = "crypto-bigint" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4c2f4e1afd912bc40bfd6fed5d9dc1f288e0ba01bfcc835cc5bc3eb13efe15" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -177,6 +203,17 @@ dependencies = [ "typenum", ] +[[package]] +name = "der" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56acb310e15652100da43d130af8d97b509e95af61aab1c5a7939ef24337ee17" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + [[package]] name = "derivative" version = "2.2.0" @@ -199,12 +236,14 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer 0.10.3", + "block-buffer 0.10.4", + "const-oid", "crypto-common", + "subtle", ] [[package]] @@ -213,6 +252,40 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e16a80c1dda2cf52fa07106427d3d798b6331dca8155fcb8c39f7fc78f6dd2" +[[package]] +name = "ecdsa" +version = "0.16.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0997c976637b606099b9985693efa3581e84e41f5c11ba5255f88711058ad428" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "968405c8fdc9b3bf4df0a6638858cc0b52462836ab6b1c87377785dd09cf1c0b" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pem-rfc7468", + "pkcs8", + "rand_core", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "encoding8" version = "0.3.2" @@ -230,9 +303,9 @@ dependencies = [ [[package]] name = "ff" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ "bitvec", "rand_core", @@ -247,19 +320,20 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "generic-array" -version = "0.14.5" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", + "zeroize", ] [[package]] name = "getrandom" -version = "0.2.7" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" dependencies = [ "cfg-if", "js-sys", @@ -270,9 +344,9 @@ dependencies = [ [[package]] name = "group" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ "ff", "rand_core", @@ -285,6 +359,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "indoc" version = "0.3.6" @@ -338,6 +421,20 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "k256" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.7", + "signature", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -346,9 +443,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "linked-hash-map" @@ -454,9 +551,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.12.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "opaque-debug" @@ -464,11 +561,23 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "p256" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primeorder", + "sha2 0.10.7", +] + [[package]] name = "pairing" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "135590d8bdba2b31346f9cd1fb2a912329f5135e832a4f422942eb6ead8b6b3b" +checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" dependencies = [ "group", ] @@ -517,12 +626,40 @@ dependencies = [ "proc-macro-hack", ] +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "ppv-lite86" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +[[package]] +name = "primeorder" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c2fcef82c0ec6eefcc179b978446c399b3cdf73c392c35604e399eee6df1ee3" +dependencies = [ + "elliptic-curve", +] + [[package]] name = "proc-macro-hack" version = "0.5.19" @@ -633,9 +770,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", ] @@ -658,6 +795,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + [[package]] name = "ryu" version = "1.0.10" @@ -676,6 +823,20 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sec1" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0aec48e813d6b90b15f0b8948af3c63483992dee44c03e9930b3eebdabe046e" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + [[package]] name = "serde" version = "1.0.137" @@ -709,26 +870,36 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.5" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" dependencies = [ "block-buffer 0.9.0", "cfg-if", - "cpufeatures 0.1.5", + "cpufeatures", "digest 0.9.0", "opaque-debug", ] [[package]] name = "sha2" -version = "0.10.2" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" dependencies = [ "cfg-if", - "cpufeatures 0.2.5", - "digest 0.10.6", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "signature" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" +dependencies = [ + "digest 0.10.7", + "rand_core", ] [[package]] @@ -737,6 +908,16 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +[[package]] +name = "spki" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "subtle" version = "2.4.1" @@ -951,3 +1132,9 @@ checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" dependencies = [ "linked-hash-map", ] + +[[package]] +name = "zeroize" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" diff --git a/Cargo.toml b/Cargo.toml index 9aae5c82e..1c5a933aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ python-source = "python" [dependencies] hex = "0.4.3" num-bigint = { version = "0.4.0", features = ["serde"] } -bls12_381 = "0.7.0" +bls12_381 = { version = "=0.8.0", features = ["experimental"] } bytestream = "0.4.1" num-traits = "0.2.14" lazy_static = "1.4.0" @@ -32,7 +32,7 @@ do-notation = "0.1.3" serde_json = "1.0" sha2 = "0.9.5" tempfile = "3.3.0" -clvmr = "0.1.24" +clvmr = { version = "0.2.6", features = ["pre-eval"] } binascii = "0.1.4" yaml-rust = "0.4" linked-hash-map = "0.5.6" diff --git a/src/classic/clvm/serialize.rs b/src/classic/clvm/serialize.rs index 95ab47c63..05246789a 100644 --- a/src/classic/clvm/serialize.rs +++ b/src/classic/clvm/serialize.rs @@ -98,9 +98,11 @@ impl<'a> Iterator for SExpToBytesIterator<'a> { fn next(&mut self) -> Option { self.state.pop().and_then(|step| match step { SExpToByteOp::Object(x) => match self.allocator.sexp(x) { - SExp::Atom(b) => { - let buf = self.allocator.buf(&b).to_vec(); - let bytes = Bytes::new(Some(BytesFromType::Raw(buf.to_vec()))); + SExp::Atom() => { + // The only node we have in scope is x, so this atom + // capture is trivial. + let buf = self.allocator.atom(x).to_vec(); + let bytes = Bytes::new(Some(BytesFromType::Raw(buf.clone()))); match atom_size_blob(&bytes) { Ok((original, b)) => { if original { diff --git a/src/classic/clvm/sexp.rs b/src/classic/clvm/sexp.rs index 2cc433912..ef730eedd 100644 --- a/src/classic/clvm/sexp.rs +++ b/src/classic/clvm/sexp.rs @@ -3,7 +3,7 @@ use std::fmt::Debug; use std::rc::Rc; use std::string::String; -use clvm_rs::allocator::{Allocator, AtomBuf, NodePtr, SExp}; +use clvm_rs::allocator::{Allocator, NodePtr, SExp}; use clvm_rs::reduction::EvalErr; use bls12_381::G1Affine; @@ -150,7 +150,7 @@ pub fn to_sexp_type(allocator: &mut Allocator, value: CastableType) -> Result { + SExp::Atom() => { return Err(EvalErr( *target_value, "attempt to set_pair in atom".to_string(), @@ -335,7 +335,8 @@ pub fn bool_sexp(allocator: &mut Allocator, b: bool) -> NodePtr { pub fn non_nil(allocator: &mut Allocator, sexp: NodePtr) -> bool { match allocator.sexp(sexp) { SExp::Pair(_, _) => true, - SExp::Atom(b) => !b.is_empty(), + // sexp is the only node in scope, was !is_empty + SExp::Atom() => allocator.atom_len(sexp) != 0, } } @@ -353,9 +354,9 @@ pub fn rest(allocator: &mut Allocator, sexp: NodePtr) -> Result Result { +pub fn atom(allocator: &mut Allocator, sexp: NodePtr) -> Result, EvalErr> { match allocator.sexp(sexp) { - SExp::Atom(abuf) => Ok(abuf), + SExp::Atom() => Ok(allocator.atom(sexp).to_vec()), // only sexp in scope _ => Err(EvalErr(sexp, "not an atom".to_string())), } } @@ -365,7 +366,7 @@ pub fn proper_list(allocator: &mut Allocator, sexp: NodePtr, store: bool) -> Opt let mut args_sexp = sexp; loop { match allocator.sexp(args_sexp) { - SExp::Atom(_) => { + SExp::Atom() => { if !non_nil(allocator, args_sexp) { return Some(args); } else { @@ -453,10 +454,9 @@ pub fn equal_to(allocator: &mut Allocator, first_: NodePtr, second_: NodePtr) -> return true; } match (allocator.sexp(first), allocator.sexp(second)) { - (SExp::Atom(fbuf), SExp::Atom(sbuf)) => { - let fvec = allocator.buf(&fbuf); - let svec = allocator.buf(&sbuf); - return fvec == svec; + (SExp::Atom(), SExp::Atom()) => { + // two atoms in scope, both are used + return allocator.atom(first) == allocator.atom(second); } (SExp::Pair(ff, fr), SExp::Pair(rf, rr)) => { if !equal_to(allocator, ff, rf) { @@ -477,7 +477,7 @@ pub fn flatten(allocator: &mut Allocator, tree_: NodePtr, res: &mut Vec loop { match allocator.sexp(tree) { - SExp::Atom(_) => { + SExp::Atom() => { if non_nil(allocator, tree) { res.push(tree); } diff --git a/src/classic/clvm_tools/binutils.rs b/src/classic/clvm_tools/binutils.rs index 9e5e160ff..deac313cc 100644 --- a/src/classic/clvm_tools/binutils.rs +++ b/src/classic/clvm_tools/binutils.rs @@ -127,8 +127,9 @@ pub fn disassemble_to_ir_with_kw( IRRepr::Cons(Rc::new(v0), Rc::new(v1)) } - SExp::Atom(a) => { - let bytes = Bytes::new(Some(BytesFromType::Raw(allocator.buf(&a).to_vec()))); + SExp::Atom() => { + // sexp is the only node in scope. + let bytes = Bytes::new(Some(BytesFromType::Raw(allocator.atom(sexp).to_vec()))); ir_for_atom(&bytes, allow_keyword, keyword_from_atom) } } @@ -139,7 +140,7 @@ pub fn disassemble_with_kw( sexp: NodePtr, keyword_from_atom: &Record, String>, ) -> String { - let with_keywords = !matches!(allocator.sexp(sexp), SExp::Atom(_)); + let with_keywords = !matches!(allocator.sexp(sexp), SExp::Atom()); let symbols = disassemble_to_ir_with_kw(allocator, sexp, keyword_from_atom, with_keywords); write_ir(Rc::new(symbols)) } diff --git a/src/classic/clvm_tools/clvmc.rs b/src/classic/clvm_tools/clvmc.rs index 3e91ae099..322791c64 100644 --- a/src/classic/clvm_tools/clvmc.rs +++ b/src/classic/clvm_tools/clvmc.rs @@ -33,9 +33,12 @@ fn include_dialect( dialects: &HashMap, i32>, e: &[NodePtr], ) -> Option { - if let (SExp::Atom(inc), SExp::Atom(name)) = (allocator.sexp(e[0]), allocator.sexp(e[1])) { - if allocator.buf(&inc) == "include".as_bytes().to_vec() { - if let Some(dialect) = dialects.get(allocator.buf(&name)) { + // Propogated names from let capture to labeled nodes. + let inc_node = e[0]; + let name_node = e[1]; + if let (SExp::Atom(), SExp::Atom()) = (allocator.sexp(inc_node), allocator.sexp(name_node)) { + if allocator.atom(inc_node) == "include".as_bytes().to_vec() { + if let Some(dialect) = dialects.get(allocator.atom(name_node)) { return Some(*dialect); } } @@ -137,7 +140,7 @@ pub fn compile_clvm_inner( ) -> Result<(), String> { let result = compile_clvm_text( allocator, - opts, + opts.clone(), symbol_table, text, filename, diff --git a/src/classic/clvm_tools/debug.rs b/src/classic/clvm_tools/debug.rs index 761a5640f..bbed5519b 100644 --- a/src/classic/clvm_tools/debug.rs +++ b/src/classic/clvm_tools/debug.rs @@ -180,7 +180,7 @@ fn table_trace( ) { let (sexp, args) = match allocator.sexp(form) { SExp::Pair(sexp, args) => (sexp, args), - SExp::Atom(_) => (form, allocator.null()), + SExp::Atom() => (form, allocator.null()), }; stdout.write_str(&format!("exp: {}\n", disassemble_f(allocator, sexp))); diff --git a/src/classic/clvm_tools/pattern_match.rs b/src/classic/clvm_tools/pattern_match.rs index df24d3c77..0df1345cd 100644 --- a/src/classic/clvm_tools/pattern_match.rs +++ b/src/classic/clvm_tools/pattern_match.rs @@ -51,40 +51,34 @@ pub fn match_sexp( */ match (allocator.sexp(pattern), allocator.sexp(sexp)) { - (SExp::Atom(pat_buf), SExp::Atom(sexp_buf)) => { - let sexp_bytes = allocator.buf(&sexp_buf).to_vec(); - if allocator.buf(&pat_buf).to_vec() == sexp_bytes { + (SExp::Atom(), SExp::Atom()) => { + // Two nodes in scope, both used. + if allocator.atom(pattern) == allocator.atom(sexp) { Some(known_bindings) } else { None } } (SExp::Pair(pleft, pright), _) => match (allocator.sexp(pleft), allocator.sexp(pright)) { - (SExp::Atom(pat_left), SExp::Atom(pat_right)) => { - let pat_right_bytes = allocator.buf(&pat_right).to_vec(); - let pat_left_bytes = allocator.buf(&pat_left).to_vec(); - + (SExp::Atom(), SExp::Atom()) => { + let pright_atom = allocator.atom(pright).to_vec(); match allocator.sexp(sexp) { - SExp::Atom(sexp_buf) => { - let sexp_bytes = allocator.buf(&sexp_buf).to_vec(); - if pat_left_bytes == ATOM_MATCH.to_vec() { - if pat_right_bytes == ATOM_MATCH.to_vec() { - if sexp_bytes == ATOM_MATCH.to_vec() { + SExp::Atom() => { + // Expression is ($ . $), sexp is '$', result: no capture. + // Avoid double borrow. + if allocator.atom(pleft) == ATOM_MATCH { + if allocator.atom(pright) == ATOM_MATCH { + if allocator.atom(sexp) == ATOM_MATCH { return Some(HashMap::new()); } return None; } - return unify_bindings( - allocator, - known_bindings, - &pat_right_bytes, - sexp, - ); + return unify_bindings(allocator, known_bindings, &pright_atom, sexp); } - if pat_left_bytes == SEXP_MATCH.to_vec() { - if pat_right_bytes == SEXP_MATCH.to_vec() - && sexp_bytes == SEXP_MATCH.to_vec() + if allocator.atom(pleft) == SEXP_MATCH { + if allocator.atom(pright) == SEXP_MATCH + && allocator.atom(sexp) == SEXP_MATCH { return Some(HashMap::new()); } @@ -92,7 +86,8 @@ pub fn match_sexp( return unify_bindings( allocator, known_bindings, - &pat_right_bytes, + // pat_right_bytes + &pright_atom, sexp, ); } @@ -100,13 +95,14 @@ pub fn match_sexp( None } SExp::Pair(sleft, sright) => { - if pat_left_bytes == SEXP_MATCH.to_vec() - && pat_right_bytes != SEXP_MATCH.to_vec() + if allocator.atom(pleft) == SEXP_MATCH + && allocator.atom(pright) != SEXP_MATCH { return unify_bindings( allocator, known_bindings, - &pat_right_bytes, + // pat_right_bytes + &pright_atom, sexp, ); } @@ -118,11 +114,11 @@ pub fn match_sexp( } } _ => match allocator.sexp(sexp) { - SExp::Atom(_) => None, + SExp::Atom() => None, SExp::Pair(sleft, sright) => match_sexp(allocator, pleft, sleft, known_bindings) .and_then(|new_bindings| match_sexp(allocator, pright, sright, new_bindings)), }, }, - (SExp::Atom(_), _) => None, + (SExp::Atom(), _) => None, } } diff --git a/src/classic/clvm_tools/sha256tree.rs b/src/classic/clvm_tools/sha256tree.rs index 3c9986cc3..0212d0c78 100644 --- a/src/classic/clvm_tools/sha256tree.rs +++ b/src/classic/clvm_tools/sha256tree.rs @@ -34,9 +34,10 @@ pub fn sha256tree(allocator: &mut Allocator, v: NodePtr) -> Bytes { .concat(&right), ) } - SExp::Atom(a) => sha256( + SExp::Atom() => sha256( Bytes::new(Some(BytesFromType::Raw(vec![1]))).concat(&Bytes::new(Some( - BytesFromType::Raw(allocator.buf(&a).to_vec()), + // only v in scope. + BytesFromType::Raw(allocator.atom(v).to_vec()), ))), ), } diff --git a/src/classic/clvm_tools/stages/stage_0.rs b/src/classic/clvm_tools/stages/stage_0.rs index a447b90bb..6292411b1 100644 --- a/src/classic/clvm_tools/stages/stage_0.rs +++ b/src/classic/clvm_tools/stages/stage_0.rs @@ -1,9 +1,9 @@ use clvm_rs::allocator::{Allocator, NodePtr}; -use clvm_rs::chia_dialect::{ChiaDialect, NO_NEG_DIV, NO_UNKNOWN_OPS}; +use clvm_rs::chia_dialect::{ChiaDialect, ENABLE_BLS_OPS, ENABLE_SECP_OPS, NO_UNKNOWN_OPS}; use clvm_rs::cost::Cost; use clvm_rs::reduction::Response; -use clvm_rs::run_program::{run_program, PreEval}; +use clvm_rs::run_program::{run_program_with_pre_eval, PreEval}; pub struct RunProgramOption { pub max_cost: Option, @@ -45,9 +45,9 @@ impl TRunProgram for DefaultProgramRunner { ) -> Response { let max_cost = option.as_ref().and_then(|o| o.max_cost).unwrap_or(0); - run_program( + run_program_with_pre_eval( allocator, - &ChiaDialect::new(NO_NEG_DIV | NO_UNKNOWN_OPS), + &ChiaDialect::new(NO_UNKNOWN_OPS | ENABLE_BLS_OPS | ENABLE_SECP_OPS), program, args, max_cost, diff --git a/src/classic/clvm_tools/stages/stage_2/compile.rs b/src/classic/clvm_tools/stages/stage_2/compile.rs index a1866bbda..bf433bdf1 100644 --- a/src/classic/clvm_tools/stages/stage_2/compile.rs +++ b/src/classic/clvm_tools/stages/stage_2/compile.rs @@ -1,7 +1,7 @@ use std::collections::{HashMap, HashSet}; use std::rc::Rc; -use clvm_rs::allocator::{Allocator, AtomBuf, NodePtr, SExp}; +use clvm_rs::allocator::{Allocator, NodePtr, SExp}; use clvm_rs::reduction::{EvalErr, Reduction, Response}; use crate::classic::clvm::__type_compatibility__::{Bytes, BytesFromType}; @@ -121,13 +121,14 @@ pub fn compile_qq( }; match allocator.sexp(sexp) { - SExp::Atom(_) => { + SExp::Atom() => { // (qq ATOM) => (q . ATOM) quote(allocator, sexp) } SExp::Pair(op, sexp_rest) => { - if let SExp::Atom(opbuf) = allocator.sexp(op) { - if allocator.buf(&opbuf).to_vec() == qq_atom() { + if let SExp::Atom() = allocator.sexp(op) { + // opbuf => op + if allocator.atom(op).to_vec() == qq_atom() { return m! { cons_atom <- allocator.new_atom(&[4]); subexp <- @@ -137,7 +138,8 @@ pub fn compile_qq( run_list <- enlist(allocator, &[cons_atom, op, consed]); com_qq(allocator, "qq sexp pair".to_string(), macro_lookup, symbol_table, runner, run_list) }; - } else if allocator.buf(&opbuf).to_vec() == unquote_atom() { + } else if allocator.atom(op).to_vec() == unquote_atom() { + // opbuf if level == 1 { // (qq (unquote X)) => X return m! { @@ -206,8 +208,10 @@ fn lower_quote_(allocator: &mut Allocator, prog: NodePtr) -> Result { - if allocator.buf(¯o_name).to_vec() == *operator { + SExp::Atom() => { + // was macro_name, but it's singular and probably + // not useful to rename. + if allocator.atom(mp_list[0]) == operator { return Ok(Some(value)); } } @@ -356,10 +362,10 @@ fn get_macro_program( fn transform_program_atom( allocator: &mut Allocator, prog: NodePtr, - a: &AtomBuf, + a: &[u8], symbol_table: NodePtr, ) -> Response { - if allocator.buf(a).to_vec() == "@".as_bytes().to_vec() { + if a == b"@" { return allocator .new_atom(NodePath::new(None).as_path().data()) .map(|x| Reduction(1, x)); @@ -378,8 +384,10 @@ fn transform_program_atom( let value = if v.len() > 1 { v[1] } else { allocator.null() }; match allocator.sexp(v[0]) { - SExp::Atom(s) => { - if allocator.buf(&s).to_vec() == allocator.buf(a).to_vec() { + SExp::Atom() => { + // v[0] is close by, and probably not useful to + // rename here. + if allocator.atom(v[0]) == a { return Ok(Reduction(1, value)); } } @@ -453,7 +461,7 @@ fn find_symbol_match( } match allocator.sexp(symdef[0]) { - SExp::Atom(symptr) => { + SExp::Atom() => { let symbol = symdef[0]; let value = if symdef.len() == 1 { allocator.null() @@ -461,10 +469,10 @@ fn find_symbol_match( symdef[1] }; - let symbuf = allocator.buf(&symptr).to_vec(); - if vec![b'*'] == symbuf { + let symbuf = allocator.atom(symdef[0]); + if b"*" == symbuf { return Ok(Some(SymbolResult::Direct(r))); - } else if *opname == symbuf { + } else if opname == symbuf { return Ok(Some(SymbolResult::Matched(symbol, value))); } } @@ -629,18 +637,21 @@ fn do_com_prog_( // quote atoms match allocator.sexp(prog) { - SExp::Atom(a) => { + SExp::Atom() => { + // Note: can't co-borrow with allocator below. + let prog_bytes = allocator.atom(prog).to_vec(); transform_program_atom( allocator, prog, - &a, + &prog_bytes, symbol_table ) }, SExp::Pair(operator,prog_rest) => { match allocator.sexp(operator) { - SExp::Atom(a) => { - let opbuf = allocator.buf(&a).to_vec(); + SExp::Atom() => { + // Note: can't co-borrow with allocator below. + let opbuf = allocator.atom(operator).to_vec(); get_macro_program(allocator, &opbuf, macro_lookup). and_then(|x| match x { Some(value) => { @@ -764,14 +775,16 @@ pub fn get_compile_filename( ) -> Result, EvalErr> { let cvt_prog = assemble(allocator, "(_get_compile_filename)")?; - let cvt_prog_result = runner.run_program(allocator, cvt_prog, allocator.null(), None)?; + let Reduction(_, cvt_prog_result) = + runner.run_program(allocator, cvt_prog, allocator.null(), None)?; - if cvt_prog_result.1 == allocator.null() { + if cvt_prog_result == allocator.null() { return Ok(None); } - if let SExp::Atom(buf) = allocator.sexp(cvt_prog_result.1) { - let abuf = allocator.buf(&buf).to_vec(); + if let SExp::Atom() = allocator.sexp(cvt_prog_result) { + // only cvt_prog_result in scope. + let abuf = allocator.atom(cvt_prog_result).to_vec(); return Ok(Some(Bytes::new(Some(BytesFromType::Raw(abuf))).decode())); } @@ -791,10 +804,12 @@ pub fn get_search_paths( let mut res = Vec::new(); if let Some(l) = proper_list(allocator, search_path_result.1, true) { - for elt in l.iter() { - if let SExp::Atom(buf) = allocator.sexp(*elt) { - let abuf = allocator.buf(&buf).to_vec(); - res.push(Bytes::new(Some(BytesFromType::Raw(abuf))).decode()); + for elt in l.iter().copied() { + if let SExp::Atom() = allocator.sexp(elt) { + // Only elt in scope. + res.push( + Bytes::new(Some(BytesFromType::Raw(allocator.atom(elt).to_vec()))).decode(), + ); } } } diff --git a/src/classic/clvm_tools/stages/stage_2/inline.rs b/src/classic/clvm_tools/stages/stage_2/inline.rs index c989b6ad0..e47abbf73 100644 --- a/src/classic/clvm_tools/stages/stage_2/inline.rs +++ b/src/classic/clvm_tools/stages/stage_2/inline.rs @@ -15,11 +15,11 @@ pub fn is_at_capture( tree_first: NodePtr, tree_rest: NodePtr, ) -> Option<(NodePtr, NodePtr)> { - if let (SExp::Atom(a), Some(spec)) = ( + if let (SExp::Atom(), Some(spec)) = ( allocator.sexp(tree_first), proper_list(allocator, tree_rest, true), ) { - if allocator.buf(&a) == [b'@'] && spec.len() == 2 { + if allocator.atom(tree_first) == b"@" && spec.len() == 2 { return Some((spec[0], spec[1])); } } @@ -88,7 +88,7 @@ fn formulate_path_selections_for_destructuring_arg( SExp::Pair(a, b) => { let next_depth = arg_depth.clone() * 2_u32.to_bigint().unwrap(); if let Some((capture, substructure)) = is_at_capture(allocator, a, b) { - if let SExp::Atom(cbuf) = allocator.sexp(capture) { + if let SExp::Atom() = allocator.sexp(capture) { let (new_arg_path, new_arg_depth, tail) = if let Some(prev_ref) = referenced_from { (arg_path, arg_depth, prev_ref) @@ -99,7 +99,8 @@ fn formulate_path_selections_for_destructuring_arg( (bi_zero(), bi_one(), qtail) }; - selections.insert(allocator.buf(&cbuf).to_vec(), tail); + // Was cbuf from capture. + selections.insert(allocator.atom(capture).to_vec(), tail); return formulate_path_selections_for_destructuring_arg( allocator, @@ -146,8 +147,9 @@ fn formulate_path_selections_for_destructuring_arg( ) } } - SExp::Atom(b) => { - let buf = allocator.buf(&b).to_vec(); + SExp::Atom() => { + // Note: can't co-borrow with allocator below. + let buf = allocator.atom(arg_sexp).to_vec(); if !buf.is_empty() { if let Some(capture) = referenced_from { let tail = wrap_path_selection(allocator, arg_path + arg_depth, capture)?; @@ -223,10 +225,11 @@ pub fn formulate_path_selections_for_destructuring( ) -> Result { if let SExp::Pair(a, b) = allocator.sexp(args_sexp) { if let Some((capture, substructure)) = is_at_capture(allocator, a, b) { - if let SExp::Atom(cbuf) = allocator.sexp(capture) { + if let SExp::Atom() = allocator.sexp(capture) { let quoted_arg_list = wrap_in_unquote(allocator, capture)?; let tail = wrap_in_compile_time_list(allocator, quoted_arg_list)?; - let buf = allocator.buf(&cbuf); + // Was: cbuf from capture. + let buf = allocator.atom(capture); selections.insert(buf.to_vec(), tail); let newsub = formulate_path_selections_for_destructuring_arg( allocator, diff --git a/src/classic/clvm_tools/stages/stage_2/module.rs b/src/classic/clvm_tools/stages/stage_2/module.rs index cbf134365..de8023542 100644 --- a/src/classic/clvm_tools/stages/stage_2/module.rs +++ b/src/classic/clvm_tools/stages/stage_2/module.rs @@ -144,8 +144,9 @@ fn build_used_constants_names( .collect::>(); let matching_names = matching_names_1.iter().filter_map(|v| { - if let SExp::Atom(b) = allocator.sexp(*v) { - Some(allocator.buf(&b).to_vec()) + // Only v usefully in scope. + if let SExp::Atom() = allocator.sexp(*v) { + Some(allocator.atom(*v).to_vec()) } else { None } @@ -222,8 +223,9 @@ fn unquote_args( matches: &HashMap, NodePtr>, ) -> Result { match allocator.sexp(code) { - SExp::Atom(code_buf) => { - let code_atom = allocator.buf(&code_buf); + SExp::Atom() => { + // Only code in scope. + let code_atom = allocator.atom(code); let matching_args = args .iter() .filter(|arg| *arg == code_atom) @@ -283,8 +285,9 @@ fn defun_inline_to_macro( let arg_name_list = arg_atom_list .iter() .filter_map(|x| { - if let SExp::Atom(a) = allocator.sexp(*x) { - Some(allocator.buf(&a)) + if let SExp::Atom() = allocator.sexp(*x) { + // only x usefully in scope. + Some(allocator.atom(*x)) } else { None } @@ -321,11 +324,13 @@ fn parse_mod_sexp( .select_nodes(allocator, declaration_sexp)?; let op = match allocator.sexp(op_node) { - SExp::Atom(b) => allocator.buf(&b).to_vec(), + // op_node in use. + SExp::Atom() => allocator.atom(op_node).to_vec(), _ => Vec::new(), }; let name = match allocator.sexp(name_node) { - SExp::Atom(b) => allocator.buf(&b).to_vec(), + // name_node in use. + SExp::Atom() => allocator.atom(name_node).to_vec(), _ => Vec::new(), }; @@ -540,7 +545,7 @@ fn symbol_table_for_tree( } match allocator.sexp(tree) { - SExp::Atom(_) => Ok(vec![(tree, root_node.as_path().data().to_vec())]), + SExp::Atom() => Ok(vec![(tree, root_node.as_path().data().to_vec())]), SExp::Pair(_, _) => { let left_bytes = NodePath::new(None).first(); let right_bytes = NodePath::new(None).rest(); diff --git a/src/classic/clvm_tools/stages/stage_2/operators.rs b/src/classic/clvm_tools/stages/stage_2/operators.rs index ae202bf67..c13ef1ed6 100644 --- a/src/classic/clvm_tools/stages/stage_2/operators.rs +++ b/src/classic/clvm_tools/stages/stage_2/operators.rs @@ -5,11 +5,11 @@ use std::path::PathBuf; use std::rc::Rc; use clvm_rs::allocator::{Allocator, NodePtr, SExp}; -use clvm_rs::chia_dialect::{ChiaDialect, NO_NEG_DIV, NO_UNKNOWN_OPS}; +use clvm_rs::chia_dialect::{ChiaDialect, ENABLE_BLS_OPS, ENABLE_SECP_OPS, NO_UNKNOWN_OPS}; use clvm_rs::cost::Cost; -use clvm_rs::dialect::Dialect; +use clvm_rs::dialect::{Dialect, OperatorSet}; use clvm_rs::reduction::{EvalErr, Reduction, Response}; -use clvm_rs::run_program::run_program; +use clvm_rs::run_program::run_program_with_pre_eval; use crate::classic::clvm::__type_compatibility__::{Bytes, BytesFromType, Stream}; @@ -118,7 +118,9 @@ impl Drop for CompilerOperators { impl CompilerOperatorsInternal { pub fn new(source_file: &str, search_paths: Vec, symbols_extra_info: bool) -> Self { - let base_dialect = Rc::new(ChiaDialect::new(NO_NEG_DIV | NO_UNKNOWN_OPS)); + let base_dialect = Rc::new(ChiaDialect::new( + NO_UNKNOWN_OPS | ENABLE_BLS_OPS | ENABLE_SECP_OPS, + )); let base_runner = Rc::new(DefaultProgramRunner::new()); CompilerOperatorsInternal { base_dialect, @@ -176,9 +178,9 @@ impl CompilerOperatorsInternal { match allocator.sexp(sexp) { SExp::Pair(f, _) => match allocator.sexp(f) { - SExp::Atom(b) => { + SExp::Atom() => { let filename = - Bytes::new(Some(BytesFromType::Raw(allocator.buf(&b).to_vec()))).decode(); + Bytes::new(Some(BytesFromType::Raw(allocator.atom(f).to_vec()))).decode(); // Use the read interface in CompilerOpts if we have one. if let Some(opts) = self.get_compiler_opts() { if let Ok((_, content)) = @@ -209,8 +211,8 @@ impl CompilerOperatorsInternal { fn write(&self, allocator: &mut Allocator, sexp: NodePtr) -> Response { if let SExp::Pair(filename_sexp, r) = allocator.sexp(sexp) { if let SExp::Pair(data, _) = allocator.sexp(r) { - if let SExp::Atom(filename_buf) = allocator.sexp(filename_sexp) { - let filename_buf = allocator.buf(&filename_buf); + if let SExp::Atom() = allocator.sexp(filename_sexp) { + let filename_buf = allocator.atom(filename_sexp); let filename_bytes = Bytes::new(Some(BytesFromType::Raw(filename_buf.to_vec()))); let ir = disassemble_to_ir_with_kw(allocator, data, keyword_from_atom(), true); @@ -251,9 +253,10 @@ impl CompilerOperatorsInternal { }; if let SExp::Pair(l, _r) = allocator.sexp(sexp) { - if let SExp::Atom(b) = allocator.sexp(l) { + if let SExp::Atom() = allocator.sexp(l) { + // l most relevant in scope. let filename = - Bytes::new(Some(BytesFromType::Raw(allocator.buf(&b).to_vec()))).decode(); + Bytes::new(Some(BytesFromType::Raw(allocator.atom(l).to_vec()))).decode(); // If we have a compiler opts injected, let that handle reading // files. The name will bubble up to the _read function. if self.get_compiler_opts().is_some() { @@ -284,14 +287,15 @@ impl CompilerOperatorsInternal { { for kv in symtable.iter() { if let SExp::Pair(hash, name) = allocator.sexp(*kv) { - if let (SExp::Atom(hash), SExp::Atom(name)) = + if let (SExp::Atom(), SExp::Atom()) = (allocator.sexp(hash), allocator.sexp(name)) { + // hash and name in scope. let hash_text = - Bytes::new(Some(BytesFromType::Raw(allocator.buf(&hash).to_vec()))) + Bytes::new(Some(BytesFromType::Raw(allocator.atom(hash).to_vec()))) .decode(); let name_text = - Bytes::new(Some(BytesFromType::Raw(allocator.buf(&name).to_vec()))) + Bytes::new(Some(BytesFromType::Raw(allocator.atom(name).to_vec()))) .decode(); self.compile_outcomes.replace_with(|co| { @@ -309,26 +313,39 @@ impl CompilerOperatorsInternal { } impl Dialect for CompilerOperatorsInternal { - fn val_stack_limit(&self) -> usize { - 10000000 - } fn quote_kw(&self) -> &[u8] { &[1] } + fn apply_kw(&self) -> &[u8] { &[2] } + fn softfork_kw(&self) -> &[u8] { + &[36] + } + + // The softfork operator comes with an extension argument. + fn softfork_extension(&self, ext: u32) -> OperatorSet { + match ext { + 0 => OperatorSet::BLS, + // new extensions go here + _ => OperatorSet::Default, + } + } + fn op( &self, allocator: &mut Allocator, op: NodePtr, sexp: NodePtr, max_cost: Cost, + _extension: OperatorSet, ) -> Response { match allocator.sexp(op) { - SExp::Atom(opname) => { - let opbuf = allocator.buf(&opname); + SExp::Atom() => { + // use of op obvious. + let opbuf = allocator.atom(op); if opbuf == "_read".as_bytes() { self.read(allocator, sexp) } else if opbuf == "_write".as_bytes() { @@ -350,12 +367,19 @@ impl Dialect for CompilerOperatorsInternal { } else if opbuf == "_get_source_file".as_bytes() { self.get_source_file(allocator) } else { - self.base_dialect.op(allocator, op, sexp, max_cost) + self.base_dialect + .op(allocator, op, sexp, max_cost, OperatorSet::BLS) } } - _ => self.base_dialect.op(allocator, op, sexp, max_cost), + _ => self + .base_dialect + .op(allocator, op, sexp, max_cost, OperatorSet::BLS), } } + + fn allow_unknown_ops(&self) -> bool { + false + } } impl CompilerOperatorsInternal { @@ -383,7 +407,7 @@ impl TRunProgram for CompilerOperatorsInternal { option: Option, ) -> Response { let max_cost = option.as_ref().and_then(|o| o.max_cost).unwrap_or(0); - run_program( + run_program_with_pre_eval( allocator, self, program, diff --git a/src/classic/clvm_tools/stages/stage_2/optimize.rs b/src/classic/clvm_tools/stages/stage_2/optimize.rs index 7fde38552..5e1e2306d 100644 --- a/src/classic/clvm_tools/stages/stage_2/optimize.rs +++ b/src/classic/clvm_tools/stages/stage_2/optimize.rs @@ -41,7 +41,7 @@ pub fn seems_constant_tail(allocator: &mut Allocator, sexp_: NodePtr) -> bool { sexp = r; } - SExp::Atom(_) => { + SExp::Atom() => { return sexp == allocator.null(); } } @@ -50,13 +50,14 @@ pub fn seems_constant_tail(allocator: &mut Allocator, sexp_: NodePtr) -> bool { pub fn seems_constant(allocator: &mut Allocator, sexp: NodePtr) -> bool { match allocator.sexp(sexp) { - SExp::Atom(_b) => { + SExp::Atom() => { return sexp == allocator.null(); } SExp::Pair(operator, r) => { match allocator.sexp(operator) { - SExp::Atom(b) => { - let atom = allocator.buf(&b); + SExp::Atom() => { + // Was buf of operator. + let atom = allocator.atom(operator); if atom.len() == 1 && atom[0] == 1 { return true; } else if atom.len() == 1 && atom[0] == 8 { @@ -91,8 +92,9 @@ pub fn constant_optimizer( * return the quoted result. */ if let SExp::Pair(first, _) = allocator.sexp(r) { - if let SExp::Atom(b) = allocator.sexp(first) { - let buf = allocator.buf(&b); + // first relevant in scope. + if let SExp::Atom() = allocator.sexp(first) { + let buf = allocator.atom(first); if buf.len() == 1 && buf[0] == 1 { // Short circuit already quoted expression. return Ok(r); @@ -135,8 +137,9 @@ pub fn constant_optimizer( } pub fn is_args_call(allocator: &mut Allocator, r: NodePtr) -> bool { - if let SExp::Atom(b) = allocator.sexp(r) { - let buf = allocator.buf(&b); + if let SExp::Atom() = allocator.sexp(r) { + // Only r in scope. + let buf = allocator.atom(r); buf.len() == 1 && buf[0] == 1 } else { false @@ -217,8 +220,9 @@ fn path_from_args( new_args: NodePtr, ) -> Result { match allocator.sexp(sexp) { - SExp::Atom(v_buf) => { - let v = number_from_u8(allocator.buf(&v_buf)); + SExp::Atom() => { + // Only sexp in scope. + let v = number_from_u8(allocator.atom(sexp)); if v <= bi_one() { Ok(new_args) } else { @@ -242,7 +246,7 @@ pub fn sub_args( new_args: NodePtr, ) -> Result { match allocator.sexp(sexp) { - SExp::Atom(_) => path_from_args(allocator, sexp, new_args), + SExp::Atom() => path_from_args(allocator, sexp, new_args), SExp::Pair(first_pre, rest) => { let first; @@ -250,8 +254,9 @@ pub fn sub_args( SExp::Pair(_, _) => { first = sub_args(allocator, first_pre, new_args)?; } - SExp::Atom(b) => { - let atom = allocator.buf(&b); + SExp::Atom() => { + // Atom is a reflection of first_pre. + let atom = allocator.atom(first_pre); if atom.len() == 1 && atom[0] == 1 { return Ok(sexp); } else { @@ -369,8 +374,9 @@ pub fn var_change_optimizer_cons_eval( } let increment = match allocator.sexp(val) { SExp::Pair(val_first, _) => match allocator.sexp(val_first) { - SExp::Atom(b) => { - let vf_buf = allocator.buf(&b); + SExp::Atom() => { + // Atom reflects val_first. + let vf_buf = allocator.atom(val_first); (vf_buf.len() != 1 || vf_buf[0] != 1) as i32 } _ => 0, @@ -413,8 +419,8 @@ pub fn children_optimizer( if list.is_empty() { return Ok(r); } - if let SExp::Atom(op_buf) = allocator.sexp(list[0]) { - if allocator.buf(&op_buf).to_vec() == vec![1] { + if let SExp::Atom() = allocator.sexp(list[0]) { + if allocator.atom(list[0]).to_vec() == vec![1] { return Ok(r); } } @@ -518,7 +524,7 @@ fn path_optimizer( match first. get("atom"). and_then(|a| atom(allocator, *a).ok()). - map(|atom| number_from_u8(allocator.buf(&atom))) + map(|atom| number_from_u8(&atom)) { Some(atom) => { let node = @@ -533,7 +539,7 @@ fn path_optimizer( match rest. get("atom"). and_then(|a| atom(allocator, *a).ok()). - map(|atom| number_from_u8(allocator.buf(&atom))) + map(|atom| number_from_u8(&atom)) { Some(atom) => { let node = @@ -677,7 +683,7 @@ pub fn optimize_sexp_( let mut name = "".to_string(); match allocator.sexp(r) { - SExp::Atom(_) => { + SExp::Atom() => { return Ok(r); } SExp::Pair(_, _) => { diff --git a/src/classic/clvm_tools/stages/stage_2/reader.rs b/src/classic/clvm_tools/stages/stage_2/reader.rs index 0ff21e906..bc91c89b4 100644 --- a/src/classic/clvm_tools/stages/stage_2/reader.rs +++ b/src/classic/clvm_tools/stages/stage_2/reader.rs @@ -90,16 +90,16 @@ pub fn process_embed_file( )); } - if let (SExp::Atom(name), SExp::Atom(kind), SExp::Atom(filename)) = ( + if let (SExp::Atom(), SExp::Atom(), SExp::Atom()) = ( allocator.sexp(l[0]), allocator.sexp(l[1]), allocator.sexp(l[2]), ) { // Note: we don't want to keep borrowing here because we // need the mutable borrow below. - let name_buf = allocator.buf(&name).to_vec(); - let kind_buf = allocator.buf(&kind).to_vec(); - let filename_buf = allocator.buf(&filename).to_vec(); + let name_buf = allocator.atom(l[0]).to_vec(); + let kind_buf = allocator.atom(l[1]); + let filename_buf = allocator.atom(l[2]).to_vec(); let file_data = if kind_buf == b"bin" { let file = read_file( runner, @@ -128,7 +128,7 @@ pub fn process_embed_file( return Err(EvalErr(declaration_sexp, "no such embed kind".to_string())); }; - Ok((name_buf, quote(allocator, file_data)?)) + Ok((name_buf.to_vec(), quote(allocator, file_data)?)) } else { Err(EvalErr( declaration_sexp, diff --git a/src/compiler/clvm.rs b/src/compiler/clvm.rs index eaa6e9a4e..dd4ad017c 100644 --- a/src/compiler/clvm.rs +++ b/src/compiler/clvm.rs @@ -242,11 +242,11 @@ pub fn convert_from_clvm_rs( head: NodePtr, ) -> Result, RunFailure> { match allocator.sexp(head) { - allocator::SExp::Atom(h) => { - if h.is_empty() { + allocator::SExp::Atom() => { + let atom_data = allocator.atom(head); + if atom_data.is_empty() { Ok(Rc::new(SExp::Nil(loc))) } else { - let atom_data = allocator.buf(&h); let integer = number_from_u8(atom_data); // Ensure that atom values that don't evaluate equal to integers // are represented faithfully as atoms. diff --git a/src/tests/classic/smoke.rs b/src/tests/classic/smoke.rs index e7a7d6639..bb4b2e680 100644 --- a/src/tests/classic/smoke.rs +++ b/src/tests/classic/smoke.rs @@ -1,5 +1,6 @@ use num_bigint::ToBigInt; +use std::collections::HashMap; use std::fs; use std::io; use std::path::PathBuf; @@ -20,9 +21,11 @@ use crate::classic::clvm_tools::binutils::{assemble, assemble_from_ir, disassemb use crate::classic::clvm_tools::ir::r#type::IRRepr; use crate::classic::clvm_tools::ir::reader::read_ir; use crate::classic::clvm_tools::node_path::NodePath; +use crate::classic::clvm_tools::pattern_match::match_sexp; use crate::classic::clvm_tools::stages; use crate::classic::clvm_tools::stages::stage_0::{DefaultProgramRunner, TRunProgram}; use crate::classic::clvm_tools::stages::stage_2::operators::run_program_for_search_paths; +use crate::classic::clvm_tools::stages::stage_2::optimize::sub_args; use crate::classic::platform::argparse::{ Argument, ArgumentParser, NArgsSpec, TArgumentParserProps, }; @@ -139,8 +142,8 @@ fn mid_negative_value_bin() { Box::new(SimpleCreateCLVMObject {}), ) .expect("should be able to make nodeptr"); - if let SExp::Atom(abuf) = allocator.sexp(atom.1) { - let res_bytes = allocator.buf(&abuf); + if let SExp::Atom() = allocator.sexp(atom.1) { + let res_bytes = allocator.atom(atom.1); assert_eq!(res_bytes, &[0xff, 0xff]); } else { assert!(false); @@ -267,8 +270,8 @@ fn can_run_from_source_nil() { let mut allocator = Allocator::new(); let res = run_from_source(&mut allocator, "()".to_string()); match allocator.sexp(res) { - SExp::Atom(b) => { - let res_bytes = allocator.buf(&b).to_vec(); + SExp::Atom() => { + let res_bytes = allocator.atom(res); assert_eq!(res_bytes.len(), 0); } _ => { @@ -282,8 +285,8 @@ fn can_echo_quoted_nil() { let mut allocator = Allocator::new(); let res = run_from_source(&mut allocator, "(1)".to_string()); match allocator.sexp(res) { - SExp::Atom(b) => { - let res_bytes = allocator.buf(&b).to_vec(); + SExp::Atom() => { + let res_bytes = allocator.atom(res); assert_eq!(res_bytes.len(), 0); } _ => { @@ -313,8 +316,8 @@ fn can_echo_quoted_atom() { let mut allocator = Allocator::new(); let res = run_from_source(&mut allocator, "(1 . 3)".to_string()); match allocator.sexp(res) { - SExp::Atom(b) => { - let res_bytes = allocator.buf(&b).to_vec(); + SExp::Atom() => { + let res_bytes = allocator.atom(res); assert_eq!(res_bytes.len(), 1); assert_eq!(res_bytes[0], 3); } @@ -329,8 +332,8 @@ fn can_do_operations() { let mut allocator = Allocator::new(); let res = run_from_source(&mut allocator, "(16 (1 . 3) (1 . 5))".to_string()); match allocator.sexp(res) { - SExp::Atom(b) => { - let res_bytes = allocator.buf(&b).to_vec(); + SExp::Atom() => { + let res_bytes = allocator.atom(res); assert_eq!(res_bytes.len(), 1); assert_eq!(res_bytes[0], 8); } @@ -345,8 +348,8 @@ fn can_do_operations_kw() { let mut allocator = Allocator::new(); let res = run_from_source(&mut allocator, "(+ (q . 3) (q . 5))".to_string()); match allocator.sexp(res) { - SExp::Atom(b) => { - let res_bytes = allocator.buf(&b).to_vec(); + SExp::Atom() => { + let res_bytes = allocator.atom(res); assert_eq!(res_bytes.len(), 1); assert_eq!(res_bytes[0], 8); } @@ -770,3 +773,37 @@ fn test_bytes_to_pybytes_repr_0() { "b'\\x11\\x01abc\\r\\ntest\\ttest\\r\\n'" ); } + +#[test] +fn test_pattern_match_dollar_for_dollar() { + let mut allocator = Allocator::new(); + let pattern = assemble(&mut allocator, "($ . $)").expect("should assemble"); + let target_expr = assemble(&mut allocator, "$").expect("should assemble"); + let empty_map = HashMap::new(); + let matched = match_sexp(&mut allocator, pattern, target_expr, empty_map.clone()); + // Returns empty map. + assert_eq!(Some(empty_map), matched); +} + +#[test] +fn test_pattern_match_colon_for_colon() { + let mut allocator = Allocator::new(); + let pattern = assemble(&mut allocator, "(: . :)").expect("should assemble"); + let target_expr = assemble(&mut allocator, ":").expect("should assemble"); + let empty_map = HashMap::new(); + let matched = match_sexp(&mut allocator, pattern, target_expr, empty_map.clone()); + // Returns empty map. + assert_eq!(Some(empty_map), matched); +} + +#[test] +fn test_sub_args() { + let mut allocator = Allocator::new(); + let expr_sexp = assemble(&mut allocator, "(body 2 5)").expect("should assemble"); + let new_args = assemble(&mut allocator, "(test1 test2)").expect("should assemble"); + let result = sub_args(&mut allocator, expr_sexp, new_args).expect("should run"); + assert_eq!( + disassemble(&mut allocator, result), + "(\"body\" (f (\"test1\" \"test2\")) (f (r (\"test1\" \"test2\"))))" + ); +} diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 9c0b27d34..1b4343cb0 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -42,23 +42,28 @@ dependencies = [ ] [[package]] -name = "block-buffer" -version = "0.10.3" +name = "bls12_381" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +checksum = "62250ece575fa9b22068b3a8d59586f01d426dd7785522efd97632959e71c986" dependencies = [ - "generic-array", + "ff 0.12.1", + "group 0.12.1", + "pairing 0.22.0", + "rand_core", + "subtle", ] [[package]] name = "bls12_381" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62250ece575fa9b22068b3a8d59586f01d426dd7785522efd97632959e71c986" +checksum = "d7bc6d6292be3a19e6379786dac800f551e5865a5bb51ebbe3064ab80433f403" dependencies = [ - "ff", - "group", - "pairing", + "digest", + "ff 0.13.0", + "group 0.13.0", + "pairing 0.23.0", "rand_core", "subtle", ] @@ -95,7 +100,7 @@ name = "clvm_tools_rs" version = "0.1.34" dependencies = [ "binascii", - "bls12_381", + "bls12_381 0.7.0", "bytestream", "clvmr", "derivative", @@ -114,7 +119,7 @@ dependencies = [ "pyo3-build-config 0.15.2", "serde", "serde_json", - "sha2 0.9.9", + "sha2", "tempfile", "unicode-segmentation", "wasm-bindgen", @@ -135,17 +140,18 @@ dependencies = [ [[package]] name = "clvmr" -version = "0.1.24" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5e907612d322d0d7def6b0ecb3ad681f6af2db106bcfabe4153746c60ef9e4" +checksum = "d234802ce73011e01f7019ef5701df1f9bffad9326d7d0a6dbca8d4b7591f083" dependencies = [ - "bls12_381", + "bls12_381 0.8.0", + "group 0.13.0", "hex", "lazy_static", "num-bigint", "num-integer", "num-traits", - "sha2 0.10.2", + "sha2", ] [[package]] @@ -167,16 +173,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - [[package]] name = "derivative" version = "2.2.0" @@ -197,16 +193,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "digest" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" -dependencies = [ - "block-buffer 0.10.3", - "crypto-common", -] - [[package]] name = "do-notation" version = "0.1.3" @@ -239,6 +225,17 @@ dependencies = [ "subtle", ] +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "bitvec", + "rand_core", + "subtle", +] + [[package]] name = "funty" version = "2.0.0" @@ -274,7 +271,18 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" dependencies = [ - "ff", + "ff 0.12.1", + "rand_core", + "subtle", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff 0.13.0", "rand_core", "subtle", ] @@ -470,7 +478,16 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "135590d8bdba2b31346f9cd1fb2a912329f5135e832a4f422942eb6ead8b6b3b" dependencies = [ - "group", + "group 0.12.1", +] + +[[package]] +name = "pairing" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" +dependencies = [ + "group 0.13.0", ] [[package]] @@ -683,24 +700,13 @@ version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" dependencies = [ - "block-buffer 0.9.0", + "block-buffer", "cfg-if", "cpufeatures", - "digest 0.9.0", + "digest", "opaque-debug", ] -[[package]] -name = "sha2" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.5", -] - [[package]] name = "smallvec" version = "1.10.0" diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index 703831506..4388b2dc0 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -18,7 +18,7 @@ path = "src/mod.rs" [dependencies] clvm_tools_rs = { path= "..", features = [] } -clvmr = "0.1.24" +clvmr = { version = "0.2.5", features = ["pre-eval"] } wasm-bindgen = "=0.2.83" wasm-bindgen-test = "=0.3.25" js-sys = "0.3.60" From 2d3a899a670cab2c7ce058a6839c1e6da7d0b13d Mon Sep 17 00:00:00 2001 From: arty Date: Fri, 28 Jul 2023 13:36:39 -0700 Subject: [PATCH 07/14] Pass through op extension --- src/classic/clvm_tools/stages/stage_2/operators.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/classic/clvm_tools/stages/stage_2/operators.rs b/src/classic/clvm_tools/stages/stage_2/operators.rs index c13ef1ed6..2d281c20a 100644 --- a/src/classic/clvm_tools/stages/stage_2/operators.rs +++ b/src/classic/clvm_tools/stages/stage_2/operators.rs @@ -340,7 +340,7 @@ impl Dialect for CompilerOperatorsInternal { op: NodePtr, sexp: NodePtr, max_cost: Cost, - _extension: OperatorSet, + extension: OperatorSet, ) -> Response { match allocator.sexp(op) { SExp::Atom() => { @@ -368,12 +368,12 @@ impl Dialect for CompilerOperatorsInternal { self.get_source_file(allocator) } else { self.base_dialect - .op(allocator, op, sexp, max_cost, OperatorSet::BLS) + .op(allocator, op, sexp, max_cost, extension) } } _ => self .base_dialect - .op(allocator, op, sexp, max_cost, OperatorSet::BLS), + .op(allocator, op, sexp, max_cost, extension), } } From 5c2cd8a78e04cda8bf655cc80d5aa7e4ce1b57fa Mon Sep 17 00:00:00 2001 From: Earle Lowe <30607889+emlowe@users.noreply.github.com> Date: Mon, 31 Jul 2023 08:03:30 -0700 Subject: [PATCH 08/14] Change macOS target to macOS 11 Update MACOSX_DEPLOYMENT_TARGET to 11 --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 24a3522d6..bec2dfb87 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -48,7 +48,7 @@ jobs: - name: Build MacOs with maturin on Python ${{ matrix.python }} if: startsWith(matrix.os, 'macos') env: - MACOSX_DEPLOYMENT_TARGET: '10.14' + MACOSX_DEPLOYMENT_TARGET: '11' run: | python -m venv venv ln -s venv/bin/activate From e1bd823108a43d618c1f37ad6463af9c14688223 Mon Sep 17 00:00:00 2001 From: Earle Lowe <30607889+emlowe@users.noreply.github.com> Date: Mon, 31 Jul 2023 08:33:28 -0700 Subject: [PATCH 09/14] Remove python 3.7 ; add 3.11 --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index bec2dfb87..08cdaa45d 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -20,7 +20,7 @@ jobs: fail-fast: false matrix: os: [macos-latest, ubuntu-latest, windows-latest] - python: [3.7, 3.8, 3.9, '3.10'] + python: [3.8, 3.9, 3.10, 3.11] steps: - uses: actions/checkout@v3 From eb5b4999951d675695ec98e4a0980012685cc43c Mon Sep 17 00:00:00 2001 From: Earle Lowe <30607889+emlowe@users.noreply.github.com> Date: Mon, 31 Jul 2023 08:48:14 -0700 Subject: [PATCH 10/14] Update build-test.yml --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 08cdaa45d..3764d4626 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -48,7 +48,7 @@ jobs: - name: Build MacOs with maturin on Python ${{ matrix.python }} if: startsWith(matrix.os, 'macos') env: - MACOSX_DEPLOYMENT_TARGET: '11' + MACOSX_DEPLOYMENT_TARGET: 11 run: | python -m venv venv ln -s venv/bin/activate From b98a8181d09b98f10aa6aed060d9365181d8738c Mon Sep 17 00:00:00 2001 From: Earle Lowe <30607889+emlowe@users.noreply.github.com> Date: Mon, 31 Jul 2023 08:51:19 -0700 Subject: [PATCH 11/14] Update build-test.yml --- .github/workflows/build-test.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 3764d4626..51977f934 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -86,7 +86,7 @@ jobs: touch target/release/.cargo-lock - name: Build alpine wheel via docker - if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.7') + if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.8') run: | cd resources/alpine && docker build -t clvm-tools-rs-alpine . docker run -v ${GITHUB_WORKSPACE}:/root/clvm_tools_rs -t clvm-tools-rs-alpine sh /root/build-alpine.sh @@ -142,7 +142,7 @@ jobs: python -c 'import clvm_tools_rs; print(clvm_tools_rs.__file__)' - name: Verify recompilation of old sources match - if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.7') + if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.8') run: | . ./activate # Build cmd line tools @@ -157,7 +157,7 @@ jobs: (cd chia-blockchain && python recompile_check.py) - name: Test Classic command line tools with pytest - if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.7') + if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.8') run: | python -m pip install pytest # This script installs the wheel built during this workflow. @@ -166,7 +166,7 @@ jobs: (cd resources/tests/cmdline/tests && py.test cmds_test.py ) - name: Verify recompilation of cl21 sources - if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.7') + if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.8') run: | . ./activate # We need chia-rs for the following. @@ -178,7 +178,7 @@ jobs: (cd resources/tests && python check-recompiles.py) - name: Verify recompilation follows date and modification rules - if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.7') + if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.8') run: | python support/wheelname.py python resources/tests/test-clvm-recompile-behavior.py @@ -201,11 +201,11 @@ jobs: pytest tests - name: Run tests - if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.7') + if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.8') run: cargo test --no-default-features - name: Check coverage - if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.7') + if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.8') run: | cargo install grcov rustup component add llvm-tools-preview From 5c12d602cc81d6c53152e3e17b194ee03e4d8214 Mon Sep 17 00:00:00 2001 From: Earle Lowe <30607889+emlowe@users.noreply.github.com> Date: Mon, 31 Jul 2023 09:02:04 -0700 Subject: [PATCH 12/14] Change to 11.0 from just 11 --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 51977f934..76a80339f 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -48,7 +48,7 @@ jobs: - name: Build MacOs with maturin on Python ${{ matrix.python }} if: startsWith(matrix.os, 'macos') env: - MACOSX_DEPLOYMENT_TARGET: 11 + MACOSX_DEPLOYMENT_TARGET: '11.0' run: | python -m venv venv ln -s venv/bin/activate From 394e7cb8d3c4a6b8ca87a392d38fcdd5cabdd069 Mon Sep 17 00:00:00 2001 From: Earle Lowe <30607889+emlowe@users.noreply.github.com> Date: Mon, 31 Jul 2023 09:15:46 -0700 Subject: [PATCH 13/14] Update build-test.yml --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 76a80339f..f064ea238 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -20,7 +20,7 @@ jobs: fail-fast: false matrix: os: [macos-latest, ubuntu-latest, windows-latest] - python: [3.8, 3.9, 3.10, 3.11] + python: [3.8, 3.9, '3.10', 3.11] steps: - uses: actions/checkout@v3 From 887d136d9749c43c0fdaa9e239f49519ddaf08bc Mon Sep 17 00:00:00 2001 From: Earle Lowe <30607889+emlowe@users.noreply.github.com> Date: Mon, 31 Jul 2023 10:48:29 -0700 Subject: [PATCH 14/14] Set minimum python version to 3.8 Change abi3-py37 to abi3-py38 to set minimum python version to 3.8 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1c5a933aa..f11892ec9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,7 @@ js-sys = "0.3.58" getrandom = { version = "0.2", features = ["js"] } [target.'cfg(not(target_family="wasm"))'.dependencies] -pyo3 = { version = "0.14.2", features = ["abi3-py37", "extension-module"], optional = true } +pyo3 = { version = "0.14.2", features = ["abi3-py38", "extension-module"], optional = true } getrandom = { version = "0.2" } [build-dependencies]