From b4496584fd53a7fe6b21d546a1576d17074cef97 Mon Sep 17 00:00:00 2001 From: Alex Ozdemir Date: Tue, 11 Jun 2024 14:34:57 -0700 Subject: [PATCH 1/3] opts and tests from the memory project --- .github/workflows/ci.yml | 2 + .gitignore | 2 + Cargo.toml | 2 +- circ_opt/README.md | 27 +- circ_opt/src/lib.rs | 22 +- driver.py | 102 ++++- .../pf/mem/gen/generate_persistent.py | 18 + .../pf/mem/gen/persistent_template.zok | 16 + .../pf/mem/persistent_10accs_size1024.zok | 16 + .../pf/mem/persistent_10accs_size32.zok | 16 + .../pf/mem/persistent_50accs_size1024.zok | 16 + .../pf/mem/persistent_50accs_size32.zok | 16 + examples/circ.rs | 12 +- examples/ir/gen/generate_volatile.py | 67 ++++ examples/ir/volatile_10accs_size1024.circir | 109 ++++++ .../ir/volatile_10accs_size1048576.circir | 109 ++++++ .../volatile_10accs_size1099511627776.circir | 109 ++++++ ...tile_10accs_size1152921504606846976.circir | 109 ++++++ examples/ir/volatile_10accs_size32.circir | 109 ++++++ examples/ir/volatile_50accs_size1024.circir | 349 ++++++++++++++++++ .../ir/volatile_50accs_size1048576.circir | 349 ++++++++++++++++++ .../volatile_50accs_size1099511627776.circir | 349 ++++++++++++++++++ ...tile_50accs_size1152921504606846976.circir | 349 ++++++++++++++++++ examples/ir/volatile_50accs_size32.circir | 349 ++++++++++++++++++ requirements.txt | 1 - scripts/assert_no_default_features.zsh | 12 + scripts/file_test.py | 134 +++++++ scripts/file_tests.zsh | 10 + src/ir/opt/fits_in_bits_ip.rs | 156 ++++++++ src/ir/opt/mem/obliv.rs | 28 +- src/ir/opt/mem/ram.rs | 1 + src/ir/opt/mem/ram/checker.rs | 2 +- src/ir/opt/mod.rs | 9 + util.py | 42 --- 34 files changed, 2948 insertions(+), 71 deletions(-) create mode 100755 examples/ZoKrates/pf/mem/gen/generate_persistent.py create mode 100644 examples/ZoKrates/pf/mem/gen/persistent_template.zok create mode 100644 examples/ZoKrates/pf/mem/persistent_10accs_size1024.zok create mode 100644 examples/ZoKrates/pf/mem/persistent_10accs_size32.zok create mode 100644 examples/ZoKrates/pf/mem/persistent_50accs_size1024.zok create mode 100644 examples/ZoKrates/pf/mem/persistent_50accs_size32.zok create mode 100755 examples/ir/gen/generate_volatile.py create mode 100644 examples/ir/volatile_10accs_size1024.circir create mode 100644 examples/ir/volatile_10accs_size1048576.circir create mode 100644 examples/ir/volatile_10accs_size1099511627776.circir create mode 100644 examples/ir/volatile_10accs_size1152921504606846976.circir create mode 100644 examples/ir/volatile_10accs_size32.circir create mode 100644 examples/ir/volatile_50accs_size1024.circir create mode 100644 examples/ir/volatile_50accs_size1048576.circir create mode 100644 examples/ir/volatile_50accs_size1099511627776.circir create mode 100644 examples/ir/volatile_50accs_size1152921504606846976.circir create mode 100644 examples/ir/volatile_50accs_size32.circir delete mode 100644 requirements.txt create mode 100755 scripts/assert_no_default_features.zsh create mode 100755 scripts/file_test.py create mode 100755 scripts/file_tests.zsh create mode 100644 src/ir/opt/fits_in_bits_ip.rs delete mode 100644 util.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92e8d5101..382b87f93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,8 @@ jobs: with: toolchain: stable - uses: Swatinem/rust-cache@v2 + - name: No default features pushed + run: zsh ./scripts/assert_no_default_features.zsh - name: Set all features on run: python3 driver.py --all_features - name: Install python reqs diff --git a/.gitignore b/.gitignore index 15bb00154..f35286d6a 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ __pycache__ .mode.txt scripts/aby_tests/tests /flamegraph*.svg +/.ccls-cache +/.vscode diff --git a/Cargo.toml b/Cargo.toml index b0ff373e9..ef196a92d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,7 +61,7 @@ bls12_381 = "0.7" approx = "0.5.0" [features] -default = ["bellman", "r1cs", "poly", "smt", "zok"] +default = [] # frontends c = ["lang-c"] zok = ["smt", "zokrates_parser", "zokrates_pest_ast", "typed-arena", "petgraph"] diff --git a/circ_opt/README.md b/circ_opt/README.md index 488c75a8b..47fb2f76c 100644 --- a/circ_opt/README.md +++ b/circ_opt/README.md @@ -92,6 +92,13 @@ Options: [default: false] [possible values: true, false] + --ir-fits-in-bits-ip + Use an IP to check bit-constraints + + [env: IR_FITS_IN_BITS_IP=] + [default: true] + [possible values: true, false] + --ram Whether to use advanced RAM techniques @@ -120,7 +127,7 @@ Options: - uniqueness: Use the GCD-derivative uniqueness argument --ram-permutation - How to argue that indices are only repeated in blocks + How to permute accesses [env: RAM_PERMUTATION=] [default: msh] @@ -212,6 +219,8 @@ Options: Which field to use [env: IR_FIELD_TO_BV=] [default: wrap] [possible values: wrap, panic] --ir-frequent-gc Garbage collection after each optimization pass [env: IR_FREQUENT_GC=] [default: false] [possible values: true, false] + --ir-fits-in-bits-ip + Use an IP to check bit-constraints [env: IR_FITS_IN_BITS_IP=] [default: true] [possible values: true, false] --ram Whether to use advanced RAM techniques [env: RAM=] [default: false] [possible values: true, false] --ram-range @@ -219,7 +228,7 @@ Options: --ram-index How to argue that indices are only repeated in blocks [env: RAM_INDEX=] [default: uniqueness] [possible values: sort, uniqueness] --ram-permutation - How to argue that indices are only repeated in blocks [env: RAM_PERMUTATION=] [default: msh] [possible values: waksman, msh] + How to permute accesses [env: RAM_PERMUTATION=] [default: msh] [possible values: waksman, msh] --ram-rom ROM approach [env: RAM_ROM=] [default: haboeck] [possible values: haboeck, permute] --fmt-use-default-field @@ -259,6 +268,7 @@ BinaryOpt { ir: IrOpt { field_to_bv: Wrap, frequent_gc: false, + fits_in_bits_ip: true, }, ram: RamOpt { enabled: false, @@ -305,6 +315,7 @@ BinaryOpt { ir: IrOpt { field_to_bv: Wrap, frequent_gc: false, + fits_in_bits_ip: true, }, ram: RamOpt { enabled: false, @@ -349,6 +360,7 @@ BinaryOpt { ir: IrOpt { field_to_bv: Wrap, frequent_gc: false, + fits_in_bits_ip: true, }, ram: RamOpt { enabled: false, @@ -393,6 +405,7 @@ BinaryOpt { ir: IrOpt { field_to_bv: Wrap, frequent_gc: false, + fits_in_bits_ip: true, }, ram: RamOpt { enabled: false, @@ -437,6 +450,7 @@ BinaryOpt { ir: IrOpt { field_to_bv: Wrap, frequent_gc: false, + fits_in_bits_ip: true, }, ram: RamOpt { enabled: false, @@ -481,6 +495,7 @@ BinaryOpt { ir: IrOpt { field_to_bv: Wrap, frequent_gc: false, + fits_in_bits_ip: true, }, ram: RamOpt { enabled: false, @@ -525,6 +540,7 @@ BinaryOpt { ir: IrOpt { field_to_bv: Wrap, frequent_gc: false, + fits_in_bits_ip: true, }, ram: RamOpt { enabled: false, @@ -569,6 +585,7 @@ BinaryOpt { ir: IrOpt { field_to_bv: Wrap, frequent_gc: false, + fits_in_bits_ip: true, }, ram: RamOpt { enabled: false, @@ -616,6 +633,7 @@ BinaryOpt { ir: IrOpt { field_to_bv: Wrap, frequent_gc: false, + fits_in_bits_ip: true, }, ram: RamOpt { enabled: false, @@ -661,6 +679,7 @@ BinaryOpt { ir: IrOpt { field_to_bv: Wrap, frequent_gc: false, + fits_in_bits_ip: true, }, ram: RamOpt { enabled: false, @@ -708,6 +727,7 @@ BinaryOpt { ir: IrOpt { field_to_bv: Wrap, frequent_gc: false, + fits_in_bits_ip: true, }, ram: RamOpt { enabled: false, @@ -753,6 +773,7 @@ BinaryOpt { ir: IrOpt { field_to_bv: Wrap, frequent_gc: false, + fits_in_bits_ip: true, }, ram: RamOpt { enabled: false, @@ -800,6 +821,7 @@ BinaryOpt { ir: IrOpt { field_to_bv: Wrap, frequent_gc: false, + fits_in_bits_ip: true, }, ram: RamOpt { enabled: false, @@ -845,6 +867,7 @@ BinaryOpt { ir: IrOpt { field_to_bv: Wrap, frequent_gc: false, + fits_in_bits_ip: true, }, ram: RamOpt { enabled: false, diff --git a/circ_opt/src/lib.rs b/circ_opt/src/lib.rs index 34a171286..b38032c8a 100644 --- a/circ_opt/src/lib.rs +++ b/circ_opt/src/lib.rs @@ -168,7 +168,7 @@ impl Default for BuiltinField { } /// Options for the prime field used -#[derive(Args, Debug, Default, Clone, PartialEq, Eq)] +#[derive(Args, Debug, Clone, PartialEq, Eq)] pub struct IrOpt { /// Which field to use #[arg( @@ -186,6 +186,24 @@ pub struct IrOpt { default_value = "false" )] pub frequent_gc: bool, + /// Use an IP to check bit-constraints + #[arg( + long = "ir-fits-in-bits-ip", + env = "IR_FITS_IN_BITS_IP", + action = ArgAction::Set, + default_value = "true" + )] + pub fits_in_bits_ip: bool, +} + +impl Default for IrOpt { + fn default() -> Self { + Self { + field_to_bv: Default::default(), + frequent_gc: Default::default(), + fits_in_bits_ip: true, + } + } } #[derive(ValueEnum, Debug, PartialEq, Eq, Clone, Copy)] @@ -231,7 +249,7 @@ pub struct RamOpt { default_value = "uniqueness" )] pub index: IndexStrategy, - /// How to argue that indices are only repeated in blocks. + /// How to permute accesses #[arg( long = "ram-permutation", env = "RAM_PERMUTATION", diff --git a/driver.py b/driver.py index c3ee4841d..7bc8ac37f 100755 --- a/driver.py +++ b/driver.py @@ -3,14 +3,62 @@ import argparse import subprocess import sys +import os + +# Gloable variables +feature_path = ".features.txt" +mode_path = ".mode.txt" + +cargo_features = { + "aby", + "c", + "lp", + "r1cs", + "smt", + "zok", + "datalog", + "bellman", + "spartan", + "poly", +} + + +def save_mode(mode): + """Save mode to file""" + with open(mode_path, "w") as f: + f.write(mode) + + +def load_mode(): + """Load mode from file""" + if os.path.exists(mode_path): + with open(mode_path, "r") as f: + return f.read().strip() + else: + return "" + + +def save_features(features): + """Save features to file""" + with open(feature_path, "w") as f: + feature_str = "\n".join(features) + f.write(feature_str) + -from util import * +def load_features(): + """Load features from file""" + if os.path.exists(feature_path): + with open(feature_path, "r") as f: + features = f.read().splitlines() + return features + else: + return [] def log_run_check(cmd): s = ( " ".join(f"'{tok}'" if " " in tok else tok for tok in cmd) - if type(cmd) == list + if isinstance(cmd, list) else cmd ) print(f"Running: {s}") @@ -28,7 +76,8 @@ def install(features): """ # install python requirements - subprocess.run(["pip3", "install", "-r", "requirements.txt"]) + if "aby" in features: + subprocess.run(["pip3", "install", "-r", "requirements.txt"]) def check(features): @@ -52,8 +101,18 @@ def check_all(): Run cargo check with every individual feature """ for feature in cargo_features: - log_run_check(["cargo", "check", "--tests", "--examples", - "--benches", "--bins", "--features", feature]) + log_run_check( + [ + "cargo", + "check", + "--tests", + "--examples", + "--benches", + "--bins", + "--features", + feature, + ] + ) def build(features): @@ -123,8 +182,7 @@ def test(features, extra_args): if "zok" in features and "smt" in features: if "aby" in features: - log_run_check( - ["python3", "./scripts/aby_tests/zokrates_test_aby.py"]) + log_run_check(["python3", "./scripts/aby_tests/zokrates_test_aby.py"]) if "lp" in features: log_run_check(["./scripts/test_zok_to_ilp.zsh"]) if "r1cs" in features: @@ -143,6 +201,7 @@ def test(features, extra_args): log_run_check(["python3", "./scripts/aby_tests/c_test_aby.py"]) if "smt" in features: log_run_check(["./scripts/test_c_smt.zsh"]) + log_run_check(["./scripts/file_tests.zsh", ",".join(features)]) def benchmark(features): @@ -186,6 +245,16 @@ def lint(): log_run_check(cmd) +def set_default_features(features): + cargo_toml = ( + os.path.dirname(os.path.abspath(os.path.realpath(__file__))) + "/Cargo.toml" + ) + features_array = "[" + ", ".join('"' + f + '"' for f in features) + "]" + new_default_line = f"default = {features_array}" + print(f"sed -i 's/^default =.*/{new_default_line}/' {cargo_toml}") + log_run_check(["sed", "-i", f"s/^default =.*/{new_default_line}/", cargo_toml]) + + def flamegraph(features, extra): cmd = ["cargo", "flamegraph"] if features: @@ -209,8 +278,7 @@ def clean(features): def set_mode(mode): def verify_mode(mode): if mode not in ("debug", "release"): - raise RuntimeError( - f"Unknown mode: {mode}, --mode ") + raise RuntimeError(f"Unknown mode: {mode}, --mode ") verify_mode(mode) save_mode(mode) @@ -236,7 +304,7 @@ def verify_feature(f): features = set(sorted([f for f in features if verify_feature(f)])) save_features(features) - print("Feature set:", sorted(list(features))) + print(",".join(sorted(features))) return features @@ -292,14 +360,19 @@ def format_sub_process_cmd(r: subprocess.CalledProcessError) -> str: parser.add_argument( "-L", "--list_features", action="store_true", help="print active features" ) + parser.add_argument( + "-s", + "--set-default-features", + action="store_true", + help="write active features to Cargo.toml's default features; useful for rust tooling", + ) parser.add_argument( "-F", "--features", nargs="+", help="set features on , reset features with -F none", ) - parser.add_argument( - "--benchmark", action="store_true", help="build benchmarks") + parser.add_argument("--benchmark", action="store_true", help="build benchmarks") parser.add_argument( "extra", metavar="PASS_THROUGH_ARGS", @@ -371,10 +444,13 @@ def verify_extra_implies_flamegraph_or_test(args: argparse.Namespace): features = set_features(cargo_features) if args.list_features: - print("Feature set:", sorted(list(features))) + print(",".join(sorted(features))) if args.features: features = set_features(args.features) + + if args.set_default_features: + set_default_features(features) except subprocess.CalledProcessError as e: print("The command") cmd_str = " ".join("'" + a + "'" if " " in a else a for a in e.cmd) diff --git a/examples/ZoKrates/pf/mem/gen/generate_persistent.py b/examples/ZoKrates/pf/mem/gen/generate_persistent.py new file mode 100755 index 000000000..53b984759 --- /dev/null +++ b/examples/ZoKrates/pf/mem/gen/generate_persistent.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +import argparse +import subprocess as sub +import shutil as sh +import os +import textwrap + +script_dir = os.path.dirname(os.path.realpath(__file__)) +for A in [10, 50]: + for logN in [5, 10]: + N = 2**logN + output = f"{script_dir}/../persistent_{A}accs_size{N}.zok" + sub.run( + f'cat {script_dir}/persistent_template.zok | sed "s/7777/{N}/g" | sed "s/99/{A}/g" > {output}', + shell=True, + check=True, + ) diff --git a/examples/ZoKrates/pf/mem/gen/persistent_template.zok b/examples/ZoKrates/pf/mem/gen/persistent_template.zok new file mode 100644 index 000000000..d6acd62f8 --- /dev/null +++ b/examples/ZoKrates/pf/mem/gen/persistent_template.zok @@ -0,0 +1,16 @@ +// persistent RAM +// TEST_FILE +// FEATURES: r1cs poly +// CMD: $circ $file r1cs --proof-impl mirage --action count +const u32 LEN = 7777 +const field ACC = 99 + +def main(committed field[LEN] array, private field x, private field y, private bool b) -> field: + field x_pow = 1f + for field i in 0..(ACC-1) do + cond_store(array, x+i, x_pow, b) + x_pow = x * x_pow + endfor + return array[y] + + diff --git a/examples/ZoKrates/pf/mem/persistent_10accs_size1024.zok b/examples/ZoKrates/pf/mem/persistent_10accs_size1024.zok new file mode 100644 index 000000000..fb61c8014 --- /dev/null +++ b/examples/ZoKrates/pf/mem/persistent_10accs_size1024.zok @@ -0,0 +1,16 @@ +// persistent RAM +// TEST_FILE +// FEATURES: r1cs poly +// CMD: $circ $file r1cs --proof-impl mirage --action count +const u32 LEN = 1024 +const field ACC = 10 + +def main(committed field[LEN] array, private field x, private field y, private bool b) -> field: + field x_pow = 1f + for field i in 0..(ACC-1) do + cond_store(array, x+i, x_pow, b) + x_pow = x * x_pow + endfor + return array[y] + + diff --git a/examples/ZoKrates/pf/mem/persistent_10accs_size32.zok b/examples/ZoKrates/pf/mem/persistent_10accs_size32.zok new file mode 100644 index 000000000..7f598d802 --- /dev/null +++ b/examples/ZoKrates/pf/mem/persistent_10accs_size32.zok @@ -0,0 +1,16 @@ +// persistent RAM +// TEST_FILE +// FEATURES: r1cs poly +// CMD: $circ $file r1cs --proof-impl mirage --action count +const u32 LEN = 32 +const field ACC = 10 + +def main(committed field[LEN] array, private field x, private field y, private bool b) -> field: + field x_pow = 1f + for field i in 0..(ACC-1) do + cond_store(array, x+i, x_pow, b) + x_pow = x * x_pow + endfor + return array[y] + + diff --git a/examples/ZoKrates/pf/mem/persistent_50accs_size1024.zok b/examples/ZoKrates/pf/mem/persistent_50accs_size1024.zok new file mode 100644 index 000000000..e4498ed82 --- /dev/null +++ b/examples/ZoKrates/pf/mem/persistent_50accs_size1024.zok @@ -0,0 +1,16 @@ +// persistent RAM +// TEST_FILE +// FEATURES: r1cs poly +// CMD: $circ $file r1cs --proof-impl mirage --action count +const u32 LEN = 1024 +const field ACC = 50 + +def main(committed field[LEN] array, private field x, private field y, private bool b) -> field: + field x_pow = 1f + for field i in 0..(ACC-1) do + cond_store(array, x+i, x_pow, b) + x_pow = x * x_pow + endfor + return array[y] + + diff --git a/examples/ZoKrates/pf/mem/persistent_50accs_size32.zok b/examples/ZoKrates/pf/mem/persistent_50accs_size32.zok new file mode 100644 index 000000000..fe27dd6a8 --- /dev/null +++ b/examples/ZoKrates/pf/mem/persistent_50accs_size32.zok @@ -0,0 +1,16 @@ +// persistent RAM +// TEST_FILE +// FEATURES: r1cs poly +// CMD: $circ $file r1cs --proof-impl mirage --action count +const u32 LEN = 32 +const field ACC = 50 + +def main(committed field[LEN] array, private field x, private field y, private bool b) -> field: + field x_pow = 1f + for field i in 0..(ACC-1) do + cond_store(array, x+i, x_pow, b) + x_pow = x * x_pow + endfor + return array[y] + + diff --git a/examples/circ.rs b/examples/circ.rs index 807992921..a43a749c2 100644 --- a/examples/circ.rs +++ b/examples/circ.rs @@ -28,7 +28,7 @@ use circ::ir::{ opt::{opt, Opt}, term::{ check, - text::{parse_value_map, serialize_value_map}, + text::{parse_computations, parse_value_map, serialize_value_map}, }, }; #[cfg(feature = "aby")] @@ -120,6 +120,7 @@ enum Language { Zsharp, Datalog, C, + CircIr, Auto, } @@ -127,6 +128,7 @@ enum Language { pub enum DeterminedLanguage { Zsharp, Datalog, + CircIr, C, } @@ -154,6 +156,7 @@ fn determine_language(l: &Language, input_path: &Path) -> DeterminedLanguage { match *l { Language::Datalog => DeterminedLanguage::Datalog, Language::Zsharp => DeterminedLanguage::Zsharp, + Language::CircIr => DeterminedLanguage::CircIr, Language::C => DeterminedLanguage::C, Language::Auto => { let p = input_path.to_str().unwrap(); @@ -161,6 +164,8 @@ fn determine_language(l: &Language, input_path: &Path) -> DeterminedLanguage { DeterminedLanguage::Zsharp } else if p.ends_with(".pl") { DeterminedLanguage::Datalog + } else if p.ends_with(".circir") { + DeterminedLanguage::CircIr } else if p.ends_with(".c") || p.ends_with(".cpp") || p.ends_with(".cc") { DeterminedLanguage::C } else { @@ -180,7 +185,6 @@ fn main() { let options = Options::parse(); circ::cfg::set(&options.circ); let path_buf = options.path.clone(); - println!("{options:?}"); let mode = match options.backend { Backend::R1cs { .. } => match options.frontend.value_threshold { Some(t) => Mode::ProofOfHighValue(t), @@ -200,6 +204,7 @@ fn main() { }; ZSharpFE::gen(inputs) } + DeterminedLanguage::CircIr => parse_computations(&std::fs::read(&options.path).unwrap()), #[cfg(not(all(feature = "smt", feature = "zok")))] DeterminedLanguage::Zsharp => { panic!("Missing feature: smt,zok"); @@ -274,6 +279,9 @@ fn main() { opts.push(Opt::SetMembership); opts.push(Opt::PersistentRam); opts.push(Opt::VolatileRam); + if options.circ.ir.fits_in_bits_ip { + opts.push(Opt::FitsInBitsIp); + } opts.push(Opt::SkolemizeChallenges); opts.push(Opt::ScalarizeVars); opts.push(Opt::ConstantFold(Box::new([]))); diff --git a/examples/ir/gen/generate_volatile.py b/examples/ir/gen/generate_volatile.py new file mode 100755 index 000000000..c8aa44e10 --- /dev/null +++ b/examples/ir/gen/generate_volatile.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 + +import argparse +import subprocess as sub +import shutil as sh +import os +import textwrap + +script_dir = os.path.dirname(os.path.realpath(__file__)) +for A in [10, 50]: + for logN in [5, 10, 20, 40, 60]: + N = 2**logN + p = 0x73EDA753299D7D483339D80809A1D80553BDA402FFFE5BFEFFFFFFFF00000001 + comp = f""" + (set_default_modulus {p} + (declare + ( + (x (mod {p})) + (y (mod {p})) + (b bool) + ) + (let ( + (a0 (#a (mod {p}) #f0 {N} ())) + (pow0 #f1) + """ + for a_i in range(A - 1): + comp += f""" + (a{a_i + 1} (ite b (store a{a_i} (+ x #f{a_i}) pow{a_i}) a{a_i})) + (pow{a_i + 1} (* pow{a_i} y)) + """ + comp += f""" + (output (select a{A - 1} y)) + ) + """ + comp_suffix = ")))" + contents = textwrap.dedent( + f""" + ; TEST_FILE + ; FEATURES: r1cs poly + ; CMD: $circ $file r1cs --proof-impl mirage --action count + (computations + (main + (computation + (metadata + (parties prover verifier) + (inputs + (x (mod {p})) + (y (mod {p})) + (b bool) + ) + (commitments)) + (precompute + () + ((return (mod {p}))) + (tuple {comp} + output + {comp_suffix}) + ) + (ram_arrays (#a (mod {p}) #f0m{p} {N} ())) + {comp} + (= output y) + {comp_suffix} + )))""" + ) + with open(f"{script_dir}/../volatile_{A}accs_size{N}.circir", "w") as f: + print(contents, file=f) + diff --git a/examples/ir/volatile_10accs_size1024.circir b/examples/ir/volatile_10accs_size1024.circir new file mode 100644 index 000000000..d7dbd120c --- /dev/null +++ b/examples/ir/volatile_10accs_size1024.circir @@ -0,0 +1,109 @@ + +; TEST_FILE +; FEATURES: r1cs poly +; CMD: $circ $file r1cs --proof-impl mirage --action count +(computations + (main + (computation + (metadata + (parties prover verifier) + (inputs + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (commitments)) + (precompute + () + ((return (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513))) + (tuple + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1024 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (output (select a9 y)) + ) + + output + )))) + ) + (ram_arrays (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0m52435875175126190479447740508185965837690552500527637822603658699938581184513 1024 ())) + + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1024 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (output (select a9 y)) + ) + + (= output y) + ))) + ))) diff --git a/examples/ir/volatile_10accs_size1048576.circir b/examples/ir/volatile_10accs_size1048576.circir new file mode 100644 index 000000000..49959957a --- /dev/null +++ b/examples/ir/volatile_10accs_size1048576.circir @@ -0,0 +1,109 @@ + +; TEST_FILE +; FEATURES: r1cs poly +; CMD: $circ $file r1cs --proof-impl mirage --action count +(computations + (main + (computation + (metadata + (parties prover verifier) + (inputs + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (commitments)) + (precompute + () + ((return (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513))) + (tuple + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1048576 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (output (select a9 y)) + ) + + output + )))) + ) + (ram_arrays (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0m52435875175126190479447740508185965837690552500527637822603658699938581184513 1048576 ())) + + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1048576 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (output (select a9 y)) + ) + + (= output y) + ))) + ))) diff --git a/examples/ir/volatile_10accs_size1099511627776.circir b/examples/ir/volatile_10accs_size1099511627776.circir new file mode 100644 index 000000000..7b6b7bf72 --- /dev/null +++ b/examples/ir/volatile_10accs_size1099511627776.circir @@ -0,0 +1,109 @@ + +; TEST_FILE +; FEATURES: r1cs poly +; CMD: $circ $file r1cs --proof-impl mirage --action count +(computations + (main + (computation + (metadata + (parties prover verifier) + (inputs + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (commitments)) + (precompute + () + ((return (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513))) + (tuple + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1099511627776 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (output (select a9 y)) + ) + + output + )))) + ) + (ram_arrays (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0m52435875175126190479447740508185965837690552500527637822603658699938581184513 1099511627776 ())) + + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1099511627776 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (output (select a9 y)) + ) + + (= output y) + ))) + ))) diff --git a/examples/ir/volatile_10accs_size1152921504606846976.circir b/examples/ir/volatile_10accs_size1152921504606846976.circir new file mode 100644 index 000000000..13a81ef12 --- /dev/null +++ b/examples/ir/volatile_10accs_size1152921504606846976.circir @@ -0,0 +1,109 @@ + +; TEST_FILE +; FEATURES: r1cs poly +; CMD: $circ $file r1cs --proof-impl mirage --action count +(computations + (main + (computation + (metadata + (parties prover verifier) + (inputs + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (commitments)) + (precompute + () + ((return (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513))) + (tuple + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1152921504606846976 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (output (select a9 y)) + ) + + output + )))) + ) + (ram_arrays (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0m52435875175126190479447740508185965837690552500527637822603658699938581184513 1152921504606846976 ())) + + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1152921504606846976 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (output (select a9 y)) + ) + + (= output y) + ))) + ))) diff --git a/examples/ir/volatile_10accs_size32.circir b/examples/ir/volatile_10accs_size32.circir new file mode 100644 index 000000000..6af6790a9 --- /dev/null +++ b/examples/ir/volatile_10accs_size32.circir @@ -0,0 +1,109 @@ + +; TEST_FILE +; FEATURES: r1cs poly +; CMD: $circ $file r1cs --proof-impl mirage --action count +(computations + (main + (computation + (metadata + (parties prover verifier) + (inputs + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (commitments)) + (precompute + () + ((return (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513))) + (tuple + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 32 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (output (select a9 y)) + ) + + output + )))) + ) + (ram_arrays (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0m52435875175126190479447740508185965837690552500527637822603658699938581184513 32 ())) + + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 32 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (output (select a9 y)) + ) + + (= output y) + ))) + ))) diff --git a/examples/ir/volatile_50accs_size1024.circir b/examples/ir/volatile_50accs_size1024.circir new file mode 100644 index 000000000..3c32521e3 --- /dev/null +++ b/examples/ir/volatile_50accs_size1024.circir @@ -0,0 +1,349 @@ + +; TEST_FILE +; FEATURES: r1cs poly +; CMD: $circ $file r1cs --proof-impl mirage --action count +(computations + (main + (computation + (metadata + (parties prover verifier) + (inputs + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (commitments)) + (precompute + () + ((return (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513))) + (tuple + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1024 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (a10 (ite b (store a9 (+ x #f9) pow9) a9)) + (pow10 (* pow9 y)) + + (a11 (ite b (store a10 (+ x #f10) pow10) a10)) + (pow11 (* pow10 y)) + + (a12 (ite b (store a11 (+ x #f11) pow11) a11)) + (pow12 (* pow11 y)) + + (a13 (ite b (store a12 (+ x #f12) pow12) a12)) + (pow13 (* pow12 y)) + + (a14 (ite b (store a13 (+ x #f13) pow13) a13)) + (pow14 (* pow13 y)) + + (a15 (ite b (store a14 (+ x #f14) pow14) a14)) + (pow15 (* pow14 y)) + + (a16 (ite b (store a15 (+ x #f15) pow15) a15)) + (pow16 (* pow15 y)) + + (a17 (ite b (store a16 (+ x #f16) pow16) a16)) + (pow17 (* pow16 y)) + + (a18 (ite b (store a17 (+ x #f17) pow17) a17)) + (pow18 (* pow17 y)) + + (a19 (ite b (store a18 (+ x #f18) pow18) a18)) + (pow19 (* pow18 y)) + + (a20 (ite b (store a19 (+ x #f19) pow19) a19)) + (pow20 (* pow19 y)) + + (a21 (ite b (store a20 (+ x #f20) pow20) a20)) + (pow21 (* pow20 y)) + + (a22 (ite b (store a21 (+ x #f21) pow21) a21)) + (pow22 (* pow21 y)) + + (a23 (ite b (store a22 (+ x #f22) pow22) a22)) + (pow23 (* pow22 y)) + + (a24 (ite b (store a23 (+ x #f23) pow23) a23)) + (pow24 (* pow23 y)) + + (a25 (ite b (store a24 (+ x #f24) pow24) a24)) + (pow25 (* pow24 y)) + + (a26 (ite b (store a25 (+ x #f25) pow25) a25)) + (pow26 (* pow25 y)) + + (a27 (ite b (store a26 (+ x #f26) pow26) a26)) + (pow27 (* pow26 y)) + + (a28 (ite b (store a27 (+ x #f27) pow27) a27)) + (pow28 (* pow27 y)) + + (a29 (ite b (store a28 (+ x #f28) pow28) a28)) + (pow29 (* pow28 y)) + + (a30 (ite b (store a29 (+ x #f29) pow29) a29)) + (pow30 (* pow29 y)) + + (a31 (ite b (store a30 (+ x #f30) pow30) a30)) + (pow31 (* pow30 y)) + + (a32 (ite b (store a31 (+ x #f31) pow31) a31)) + (pow32 (* pow31 y)) + + (a33 (ite b (store a32 (+ x #f32) pow32) a32)) + (pow33 (* pow32 y)) + + (a34 (ite b (store a33 (+ x #f33) pow33) a33)) + (pow34 (* pow33 y)) + + (a35 (ite b (store a34 (+ x #f34) pow34) a34)) + (pow35 (* pow34 y)) + + (a36 (ite b (store a35 (+ x #f35) pow35) a35)) + (pow36 (* pow35 y)) + + (a37 (ite b (store a36 (+ x #f36) pow36) a36)) + (pow37 (* pow36 y)) + + (a38 (ite b (store a37 (+ x #f37) pow37) a37)) + (pow38 (* pow37 y)) + + (a39 (ite b (store a38 (+ x #f38) pow38) a38)) + (pow39 (* pow38 y)) + + (a40 (ite b (store a39 (+ x #f39) pow39) a39)) + (pow40 (* pow39 y)) + + (a41 (ite b (store a40 (+ x #f40) pow40) a40)) + (pow41 (* pow40 y)) + + (a42 (ite b (store a41 (+ x #f41) pow41) a41)) + (pow42 (* pow41 y)) + + (a43 (ite b (store a42 (+ x #f42) pow42) a42)) + (pow43 (* pow42 y)) + + (a44 (ite b (store a43 (+ x #f43) pow43) a43)) + (pow44 (* pow43 y)) + + (a45 (ite b (store a44 (+ x #f44) pow44) a44)) + (pow45 (* pow44 y)) + + (a46 (ite b (store a45 (+ x #f45) pow45) a45)) + (pow46 (* pow45 y)) + + (a47 (ite b (store a46 (+ x #f46) pow46) a46)) + (pow47 (* pow46 y)) + + (a48 (ite b (store a47 (+ x #f47) pow47) a47)) + (pow48 (* pow47 y)) + + (a49 (ite b (store a48 (+ x #f48) pow48) a48)) + (pow49 (* pow48 y)) + + (output (select a49 y)) + ) + + output + )))) + ) + (ram_arrays (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0m52435875175126190479447740508185965837690552500527637822603658699938581184513 1024 ())) + + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1024 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (a10 (ite b (store a9 (+ x #f9) pow9) a9)) + (pow10 (* pow9 y)) + + (a11 (ite b (store a10 (+ x #f10) pow10) a10)) + (pow11 (* pow10 y)) + + (a12 (ite b (store a11 (+ x #f11) pow11) a11)) + (pow12 (* pow11 y)) + + (a13 (ite b (store a12 (+ x #f12) pow12) a12)) + (pow13 (* pow12 y)) + + (a14 (ite b (store a13 (+ x #f13) pow13) a13)) + (pow14 (* pow13 y)) + + (a15 (ite b (store a14 (+ x #f14) pow14) a14)) + (pow15 (* pow14 y)) + + (a16 (ite b (store a15 (+ x #f15) pow15) a15)) + (pow16 (* pow15 y)) + + (a17 (ite b (store a16 (+ x #f16) pow16) a16)) + (pow17 (* pow16 y)) + + (a18 (ite b (store a17 (+ x #f17) pow17) a17)) + (pow18 (* pow17 y)) + + (a19 (ite b (store a18 (+ x #f18) pow18) a18)) + (pow19 (* pow18 y)) + + (a20 (ite b (store a19 (+ x #f19) pow19) a19)) + (pow20 (* pow19 y)) + + (a21 (ite b (store a20 (+ x #f20) pow20) a20)) + (pow21 (* pow20 y)) + + (a22 (ite b (store a21 (+ x #f21) pow21) a21)) + (pow22 (* pow21 y)) + + (a23 (ite b (store a22 (+ x #f22) pow22) a22)) + (pow23 (* pow22 y)) + + (a24 (ite b (store a23 (+ x #f23) pow23) a23)) + (pow24 (* pow23 y)) + + (a25 (ite b (store a24 (+ x #f24) pow24) a24)) + (pow25 (* pow24 y)) + + (a26 (ite b (store a25 (+ x #f25) pow25) a25)) + (pow26 (* pow25 y)) + + (a27 (ite b (store a26 (+ x #f26) pow26) a26)) + (pow27 (* pow26 y)) + + (a28 (ite b (store a27 (+ x #f27) pow27) a27)) + (pow28 (* pow27 y)) + + (a29 (ite b (store a28 (+ x #f28) pow28) a28)) + (pow29 (* pow28 y)) + + (a30 (ite b (store a29 (+ x #f29) pow29) a29)) + (pow30 (* pow29 y)) + + (a31 (ite b (store a30 (+ x #f30) pow30) a30)) + (pow31 (* pow30 y)) + + (a32 (ite b (store a31 (+ x #f31) pow31) a31)) + (pow32 (* pow31 y)) + + (a33 (ite b (store a32 (+ x #f32) pow32) a32)) + (pow33 (* pow32 y)) + + (a34 (ite b (store a33 (+ x #f33) pow33) a33)) + (pow34 (* pow33 y)) + + (a35 (ite b (store a34 (+ x #f34) pow34) a34)) + (pow35 (* pow34 y)) + + (a36 (ite b (store a35 (+ x #f35) pow35) a35)) + (pow36 (* pow35 y)) + + (a37 (ite b (store a36 (+ x #f36) pow36) a36)) + (pow37 (* pow36 y)) + + (a38 (ite b (store a37 (+ x #f37) pow37) a37)) + (pow38 (* pow37 y)) + + (a39 (ite b (store a38 (+ x #f38) pow38) a38)) + (pow39 (* pow38 y)) + + (a40 (ite b (store a39 (+ x #f39) pow39) a39)) + (pow40 (* pow39 y)) + + (a41 (ite b (store a40 (+ x #f40) pow40) a40)) + (pow41 (* pow40 y)) + + (a42 (ite b (store a41 (+ x #f41) pow41) a41)) + (pow42 (* pow41 y)) + + (a43 (ite b (store a42 (+ x #f42) pow42) a42)) + (pow43 (* pow42 y)) + + (a44 (ite b (store a43 (+ x #f43) pow43) a43)) + (pow44 (* pow43 y)) + + (a45 (ite b (store a44 (+ x #f44) pow44) a44)) + (pow45 (* pow44 y)) + + (a46 (ite b (store a45 (+ x #f45) pow45) a45)) + (pow46 (* pow45 y)) + + (a47 (ite b (store a46 (+ x #f46) pow46) a46)) + (pow47 (* pow46 y)) + + (a48 (ite b (store a47 (+ x #f47) pow47) a47)) + (pow48 (* pow47 y)) + + (a49 (ite b (store a48 (+ x #f48) pow48) a48)) + (pow49 (* pow48 y)) + + (output (select a49 y)) + ) + + (= output y) + ))) + ))) diff --git a/examples/ir/volatile_50accs_size1048576.circir b/examples/ir/volatile_50accs_size1048576.circir new file mode 100644 index 000000000..2ab042b44 --- /dev/null +++ b/examples/ir/volatile_50accs_size1048576.circir @@ -0,0 +1,349 @@ + +; TEST_FILE +; FEATURES: r1cs poly +; CMD: $circ $file r1cs --proof-impl mirage --action count +(computations + (main + (computation + (metadata + (parties prover verifier) + (inputs + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (commitments)) + (precompute + () + ((return (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513))) + (tuple + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1048576 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (a10 (ite b (store a9 (+ x #f9) pow9) a9)) + (pow10 (* pow9 y)) + + (a11 (ite b (store a10 (+ x #f10) pow10) a10)) + (pow11 (* pow10 y)) + + (a12 (ite b (store a11 (+ x #f11) pow11) a11)) + (pow12 (* pow11 y)) + + (a13 (ite b (store a12 (+ x #f12) pow12) a12)) + (pow13 (* pow12 y)) + + (a14 (ite b (store a13 (+ x #f13) pow13) a13)) + (pow14 (* pow13 y)) + + (a15 (ite b (store a14 (+ x #f14) pow14) a14)) + (pow15 (* pow14 y)) + + (a16 (ite b (store a15 (+ x #f15) pow15) a15)) + (pow16 (* pow15 y)) + + (a17 (ite b (store a16 (+ x #f16) pow16) a16)) + (pow17 (* pow16 y)) + + (a18 (ite b (store a17 (+ x #f17) pow17) a17)) + (pow18 (* pow17 y)) + + (a19 (ite b (store a18 (+ x #f18) pow18) a18)) + (pow19 (* pow18 y)) + + (a20 (ite b (store a19 (+ x #f19) pow19) a19)) + (pow20 (* pow19 y)) + + (a21 (ite b (store a20 (+ x #f20) pow20) a20)) + (pow21 (* pow20 y)) + + (a22 (ite b (store a21 (+ x #f21) pow21) a21)) + (pow22 (* pow21 y)) + + (a23 (ite b (store a22 (+ x #f22) pow22) a22)) + (pow23 (* pow22 y)) + + (a24 (ite b (store a23 (+ x #f23) pow23) a23)) + (pow24 (* pow23 y)) + + (a25 (ite b (store a24 (+ x #f24) pow24) a24)) + (pow25 (* pow24 y)) + + (a26 (ite b (store a25 (+ x #f25) pow25) a25)) + (pow26 (* pow25 y)) + + (a27 (ite b (store a26 (+ x #f26) pow26) a26)) + (pow27 (* pow26 y)) + + (a28 (ite b (store a27 (+ x #f27) pow27) a27)) + (pow28 (* pow27 y)) + + (a29 (ite b (store a28 (+ x #f28) pow28) a28)) + (pow29 (* pow28 y)) + + (a30 (ite b (store a29 (+ x #f29) pow29) a29)) + (pow30 (* pow29 y)) + + (a31 (ite b (store a30 (+ x #f30) pow30) a30)) + (pow31 (* pow30 y)) + + (a32 (ite b (store a31 (+ x #f31) pow31) a31)) + (pow32 (* pow31 y)) + + (a33 (ite b (store a32 (+ x #f32) pow32) a32)) + (pow33 (* pow32 y)) + + (a34 (ite b (store a33 (+ x #f33) pow33) a33)) + (pow34 (* pow33 y)) + + (a35 (ite b (store a34 (+ x #f34) pow34) a34)) + (pow35 (* pow34 y)) + + (a36 (ite b (store a35 (+ x #f35) pow35) a35)) + (pow36 (* pow35 y)) + + (a37 (ite b (store a36 (+ x #f36) pow36) a36)) + (pow37 (* pow36 y)) + + (a38 (ite b (store a37 (+ x #f37) pow37) a37)) + (pow38 (* pow37 y)) + + (a39 (ite b (store a38 (+ x #f38) pow38) a38)) + (pow39 (* pow38 y)) + + (a40 (ite b (store a39 (+ x #f39) pow39) a39)) + (pow40 (* pow39 y)) + + (a41 (ite b (store a40 (+ x #f40) pow40) a40)) + (pow41 (* pow40 y)) + + (a42 (ite b (store a41 (+ x #f41) pow41) a41)) + (pow42 (* pow41 y)) + + (a43 (ite b (store a42 (+ x #f42) pow42) a42)) + (pow43 (* pow42 y)) + + (a44 (ite b (store a43 (+ x #f43) pow43) a43)) + (pow44 (* pow43 y)) + + (a45 (ite b (store a44 (+ x #f44) pow44) a44)) + (pow45 (* pow44 y)) + + (a46 (ite b (store a45 (+ x #f45) pow45) a45)) + (pow46 (* pow45 y)) + + (a47 (ite b (store a46 (+ x #f46) pow46) a46)) + (pow47 (* pow46 y)) + + (a48 (ite b (store a47 (+ x #f47) pow47) a47)) + (pow48 (* pow47 y)) + + (a49 (ite b (store a48 (+ x #f48) pow48) a48)) + (pow49 (* pow48 y)) + + (output (select a49 y)) + ) + + output + )))) + ) + (ram_arrays (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0m52435875175126190479447740508185965837690552500527637822603658699938581184513 1048576 ())) + + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1048576 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (a10 (ite b (store a9 (+ x #f9) pow9) a9)) + (pow10 (* pow9 y)) + + (a11 (ite b (store a10 (+ x #f10) pow10) a10)) + (pow11 (* pow10 y)) + + (a12 (ite b (store a11 (+ x #f11) pow11) a11)) + (pow12 (* pow11 y)) + + (a13 (ite b (store a12 (+ x #f12) pow12) a12)) + (pow13 (* pow12 y)) + + (a14 (ite b (store a13 (+ x #f13) pow13) a13)) + (pow14 (* pow13 y)) + + (a15 (ite b (store a14 (+ x #f14) pow14) a14)) + (pow15 (* pow14 y)) + + (a16 (ite b (store a15 (+ x #f15) pow15) a15)) + (pow16 (* pow15 y)) + + (a17 (ite b (store a16 (+ x #f16) pow16) a16)) + (pow17 (* pow16 y)) + + (a18 (ite b (store a17 (+ x #f17) pow17) a17)) + (pow18 (* pow17 y)) + + (a19 (ite b (store a18 (+ x #f18) pow18) a18)) + (pow19 (* pow18 y)) + + (a20 (ite b (store a19 (+ x #f19) pow19) a19)) + (pow20 (* pow19 y)) + + (a21 (ite b (store a20 (+ x #f20) pow20) a20)) + (pow21 (* pow20 y)) + + (a22 (ite b (store a21 (+ x #f21) pow21) a21)) + (pow22 (* pow21 y)) + + (a23 (ite b (store a22 (+ x #f22) pow22) a22)) + (pow23 (* pow22 y)) + + (a24 (ite b (store a23 (+ x #f23) pow23) a23)) + (pow24 (* pow23 y)) + + (a25 (ite b (store a24 (+ x #f24) pow24) a24)) + (pow25 (* pow24 y)) + + (a26 (ite b (store a25 (+ x #f25) pow25) a25)) + (pow26 (* pow25 y)) + + (a27 (ite b (store a26 (+ x #f26) pow26) a26)) + (pow27 (* pow26 y)) + + (a28 (ite b (store a27 (+ x #f27) pow27) a27)) + (pow28 (* pow27 y)) + + (a29 (ite b (store a28 (+ x #f28) pow28) a28)) + (pow29 (* pow28 y)) + + (a30 (ite b (store a29 (+ x #f29) pow29) a29)) + (pow30 (* pow29 y)) + + (a31 (ite b (store a30 (+ x #f30) pow30) a30)) + (pow31 (* pow30 y)) + + (a32 (ite b (store a31 (+ x #f31) pow31) a31)) + (pow32 (* pow31 y)) + + (a33 (ite b (store a32 (+ x #f32) pow32) a32)) + (pow33 (* pow32 y)) + + (a34 (ite b (store a33 (+ x #f33) pow33) a33)) + (pow34 (* pow33 y)) + + (a35 (ite b (store a34 (+ x #f34) pow34) a34)) + (pow35 (* pow34 y)) + + (a36 (ite b (store a35 (+ x #f35) pow35) a35)) + (pow36 (* pow35 y)) + + (a37 (ite b (store a36 (+ x #f36) pow36) a36)) + (pow37 (* pow36 y)) + + (a38 (ite b (store a37 (+ x #f37) pow37) a37)) + (pow38 (* pow37 y)) + + (a39 (ite b (store a38 (+ x #f38) pow38) a38)) + (pow39 (* pow38 y)) + + (a40 (ite b (store a39 (+ x #f39) pow39) a39)) + (pow40 (* pow39 y)) + + (a41 (ite b (store a40 (+ x #f40) pow40) a40)) + (pow41 (* pow40 y)) + + (a42 (ite b (store a41 (+ x #f41) pow41) a41)) + (pow42 (* pow41 y)) + + (a43 (ite b (store a42 (+ x #f42) pow42) a42)) + (pow43 (* pow42 y)) + + (a44 (ite b (store a43 (+ x #f43) pow43) a43)) + (pow44 (* pow43 y)) + + (a45 (ite b (store a44 (+ x #f44) pow44) a44)) + (pow45 (* pow44 y)) + + (a46 (ite b (store a45 (+ x #f45) pow45) a45)) + (pow46 (* pow45 y)) + + (a47 (ite b (store a46 (+ x #f46) pow46) a46)) + (pow47 (* pow46 y)) + + (a48 (ite b (store a47 (+ x #f47) pow47) a47)) + (pow48 (* pow47 y)) + + (a49 (ite b (store a48 (+ x #f48) pow48) a48)) + (pow49 (* pow48 y)) + + (output (select a49 y)) + ) + + (= output y) + ))) + ))) diff --git a/examples/ir/volatile_50accs_size1099511627776.circir b/examples/ir/volatile_50accs_size1099511627776.circir new file mode 100644 index 000000000..6aea7382e --- /dev/null +++ b/examples/ir/volatile_50accs_size1099511627776.circir @@ -0,0 +1,349 @@ + +; TEST_FILE +; FEATURES: r1cs poly +; CMD: $circ $file r1cs --proof-impl mirage --action count +(computations + (main + (computation + (metadata + (parties prover verifier) + (inputs + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (commitments)) + (precompute + () + ((return (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513))) + (tuple + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1099511627776 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (a10 (ite b (store a9 (+ x #f9) pow9) a9)) + (pow10 (* pow9 y)) + + (a11 (ite b (store a10 (+ x #f10) pow10) a10)) + (pow11 (* pow10 y)) + + (a12 (ite b (store a11 (+ x #f11) pow11) a11)) + (pow12 (* pow11 y)) + + (a13 (ite b (store a12 (+ x #f12) pow12) a12)) + (pow13 (* pow12 y)) + + (a14 (ite b (store a13 (+ x #f13) pow13) a13)) + (pow14 (* pow13 y)) + + (a15 (ite b (store a14 (+ x #f14) pow14) a14)) + (pow15 (* pow14 y)) + + (a16 (ite b (store a15 (+ x #f15) pow15) a15)) + (pow16 (* pow15 y)) + + (a17 (ite b (store a16 (+ x #f16) pow16) a16)) + (pow17 (* pow16 y)) + + (a18 (ite b (store a17 (+ x #f17) pow17) a17)) + (pow18 (* pow17 y)) + + (a19 (ite b (store a18 (+ x #f18) pow18) a18)) + (pow19 (* pow18 y)) + + (a20 (ite b (store a19 (+ x #f19) pow19) a19)) + (pow20 (* pow19 y)) + + (a21 (ite b (store a20 (+ x #f20) pow20) a20)) + (pow21 (* pow20 y)) + + (a22 (ite b (store a21 (+ x #f21) pow21) a21)) + (pow22 (* pow21 y)) + + (a23 (ite b (store a22 (+ x #f22) pow22) a22)) + (pow23 (* pow22 y)) + + (a24 (ite b (store a23 (+ x #f23) pow23) a23)) + (pow24 (* pow23 y)) + + (a25 (ite b (store a24 (+ x #f24) pow24) a24)) + (pow25 (* pow24 y)) + + (a26 (ite b (store a25 (+ x #f25) pow25) a25)) + (pow26 (* pow25 y)) + + (a27 (ite b (store a26 (+ x #f26) pow26) a26)) + (pow27 (* pow26 y)) + + (a28 (ite b (store a27 (+ x #f27) pow27) a27)) + (pow28 (* pow27 y)) + + (a29 (ite b (store a28 (+ x #f28) pow28) a28)) + (pow29 (* pow28 y)) + + (a30 (ite b (store a29 (+ x #f29) pow29) a29)) + (pow30 (* pow29 y)) + + (a31 (ite b (store a30 (+ x #f30) pow30) a30)) + (pow31 (* pow30 y)) + + (a32 (ite b (store a31 (+ x #f31) pow31) a31)) + (pow32 (* pow31 y)) + + (a33 (ite b (store a32 (+ x #f32) pow32) a32)) + (pow33 (* pow32 y)) + + (a34 (ite b (store a33 (+ x #f33) pow33) a33)) + (pow34 (* pow33 y)) + + (a35 (ite b (store a34 (+ x #f34) pow34) a34)) + (pow35 (* pow34 y)) + + (a36 (ite b (store a35 (+ x #f35) pow35) a35)) + (pow36 (* pow35 y)) + + (a37 (ite b (store a36 (+ x #f36) pow36) a36)) + (pow37 (* pow36 y)) + + (a38 (ite b (store a37 (+ x #f37) pow37) a37)) + (pow38 (* pow37 y)) + + (a39 (ite b (store a38 (+ x #f38) pow38) a38)) + (pow39 (* pow38 y)) + + (a40 (ite b (store a39 (+ x #f39) pow39) a39)) + (pow40 (* pow39 y)) + + (a41 (ite b (store a40 (+ x #f40) pow40) a40)) + (pow41 (* pow40 y)) + + (a42 (ite b (store a41 (+ x #f41) pow41) a41)) + (pow42 (* pow41 y)) + + (a43 (ite b (store a42 (+ x #f42) pow42) a42)) + (pow43 (* pow42 y)) + + (a44 (ite b (store a43 (+ x #f43) pow43) a43)) + (pow44 (* pow43 y)) + + (a45 (ite b (store a44 (+ x #f44) pow44) a44)) + (pow45 (* pow44 y)) + + (a46 (ite b (store a45 (+ x #f45) pow45) a45)) + (pow46 (* pow45 y)) + + (a47 (ite b (store a46 (+ x #f46) pow46) a46)) + (pow47 (* pow46 y)) + + (a48 (ite b (store a47 (+ x #f47) pow47) a47)) + (pow48 (* pow47 y)) + + (a49 (ite b (store a48 (+ x #f48) pow48) a48)) + (pow49 (* pow48 y)) + + (output (select a49 y)) + ) + + output + )))) + ) + (ram_arrays (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0m52435875175126190479447740508185965837690552500527637822603658699938581184513 1099511627776 ())) + + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1099511627776 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (a10 (ite b (store a9 (+ x #f9) pow9) a9)) + (pow10 (* pow9 y)) + + (a11 (ite b (store a10 (+ x #f10) pow10) a10)) + (pow11 (* pow10 y)) + + (a12 (ite b (store a11 (+ x #f11) pow11) a11)) + (pow12 (* pow11 y)) + + (a13 (ite b (store a12 (+ x #f12) pow12) a12)) + (pow13 (* pow12 y)) + + (a14 (ite b (store a13 (+ x #f13) pow13) a13)) + (pow14 (* pow13 y)) + + (a15 (ite b (store a14 (+ x #f14) pow14) a14)) + (pow15 (* pow14 y)) + + (a16 (ite b (store a15 (+ x #f15) pow15) a15)) + (pow16 (* pow15 y)) + + (a17 (ite b (store a16 (+ x #f16) pow16) a16)) + (pow17 (* pow16 y)) + + (a18 (ite b (store a17 (+ x #f17) pow17) a17)) + (pow18 (* pow17 y)) + + (a19 (ite b (store a18 (+ x #f18) pow18) a18)) + (pow19 (* pow18 y)) + + (a20 (ite b (store a19 (+ x #f19) pow19) a19)) + (pow20 (* pow19 y)) + + (a21 (ite b (store a20 (+ x #f20) pow20) a20)) + (pow21 (* pow20 y)) + + (a22 (ite b (store a21 (+ x #f21) pow21) a21)) + (pow22 (* pow21 y)) + + (a23 (ite b (store a22 (+ x #f22) pow22) a22)) + (pow23 (* pow22 y)) + + (a24 (ite b (store a23 (+ x #f23) pow23) a23)) + (pow24 (* pow23 y)) + + (a25 (ite b (store a24 (+ x #f24) pow24) a24)) + (pow25 (* pow24 y)) + + (a26 (ite b (store a25 (+ x #f25) pow25) a25)) + (pow26 (* pow25 y)) + + (a27 (ite b (store a26 (+ x #f26) pow26) a26)) + (pow27 (* pow26 y)) + + (a28 (ite b (store a27 (+ x #f27) pow27) a27)) + (pow28 (* pow27 y)) + + (a29 (ite b (store a28 (+ x #f28) pow28) a28)) + (pow29 (* pow28 y)) + + (a30 (ite b (store a29 (+ x #f29) pow29) a29)) + (pow30 (* pow29 y)) + + (a31 (ite b (store a30 (+ x #f30) pow30) a30)) + (pow31 (* pow30 y)) + + (a32 (ite b (store a31 (+ x #f31) pow31) a31)) + (pow32 (* pow31 y)) + + (a33 (ite b (store a32 (+ x #f32) pow32) a32)) + (pow33 (* pow32 y)) + + (a34 (ite b (store a33 (+ x #f33) pow33) a33)) + (pow34 (* pow33 y)) + + (a35 (ite b (store a34 (+ x #f34) pow34) a34)) + (pow35 (* pow34 y)) + + (a36 (ite b (store a35 (+ x #f35) pow35) a35)) + (pow36 (* pow35 y)) + + (a37 (ite b (store a36 (+ x #f36) pow36) a36)) + (pow37 (* pow36 y)) + + (a38 (ite b (store a37 (+ x #f37) pow37) a37)) + (pow38 (* pow37 y)) + + (a39 (ite b (store a38 (+ x #f38) pow38) a38)) + (pow39 (* pow38 y)) + + (a40 (ite b (store a39 (+ x #f39) pow39) a39)) + (pow40 (* pow39 y)) + + (a41 (ite b (store a40 (+ x #f40) pow40) a40)) + (pow41 (* pow40 y)) + + (a42 (ite b (store a41 (+ x #f41) pow41) a41)) + (pow42 (* pow41 y)) + + (a43 (ite b (store a42 (+ x #f42) pow42) a42)) + (pow43 (* pow42 y)) + + (a44 (ite b (store a43 (+ x #f43) pow43) a43)) + (pow44 (* pow43 y)) + + (a45 (ite b (store a44 (+ x #f44) pow44) a44)) + (pow45 (* pow44 y)) + + (a46 (ite b (store a45 (+ x #f45) pow45) a45)) + (pow46 (* pow45 y)) + + (a47 (ite b (store a46 (+ x #f46) pow46) a46)) + (pow47 (* pow46 y)) + + (a48 (ite b (store a47 (+ x #f47) pow47) a47)) + (pow48 (* pow47 y)) + + (a49 (ite b (store a48 (+ x #f48) pow48) a48)) + (pow49 (* pow48 y)) + + (output (select a49 y)) + ) + + (= output y) + ))) + ))) diff --git a/examples/ir/volatile_50accs_size1152921504606846976.circir b/examples/ir/volatile_50accs_size1152921504606846976.circir new file mode 100644 index 000000000..33c802a2d --- /dev/null +++ b/examples/ir/volatile_50accs_size1152921504606846976.circir @@ -0,0 +1,349 @@ + +; TEST_FILE +; FEATURES: r1cs poly +; CMD: $circ $file r1cs --proof-impl mirage --action count +(computations + (main + (computation + (metadata + (parties prover verifier) + (inputs + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (commitments)) + (precompute + () + ((return (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513))) + (tuple + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1152921504606846976 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (a10 (ite b (store a9 (+ x #f9) pow9) a9)) + (pow10 (* pow9 y)) + + (a11 (ite b (store a10 (+ x #f10) pow10) a10)) + (pow11 (* pow10 y)) + + (a12 (ite b (store a11 (+ x #f11) pow11) a11)) + (pow12 (* pow11 y)) + + (a13 (ite b (store a12 (+ x #f12) pow12) a12)) + (pow13 (* pow12 y)) + + (a14 (ite b (store a13 (+ x #f13) pow13) a13)) + (pow14 (* pow13 y)) + + (a15 (ite b (store a14 (+ x #f14) pow14) a14)) + (pow15 (* pow14 y)) + + (a16 (ite b (store a15 (+ x #f15) pow15) a15)) + (pow16 (* pow15 y)) + + (a17 (ite b (store a16 (+ x #f16) pow16) a16)) + (pow17 (* pow16 y)) + + (a18 (ite b (store a17 (+ x #f17) pow17) a17)) + (pow18 (* pow17 y)) + + (a19 (ite b (store a18 (+ x #f18) pow18) a18)) + (pow19 (* pow18 y)) + + (a20 (ite b (store a19 (+ x #f19) pow19) a19)) + (pow20 (* pow19 y)) + + (a21 (ite b (store a20 (+ x #f20) pow20) a20)) + (pow21 (* pow20 y)) + + (a22 (ite b (store a21 (+ x #f21) pow21) a21)) + (pow22 (* pow21 y)) + + (a23 (ite b (store a22 (+ x #f22) pow22) a22)) + (pow23 (* pow22 y)) + + (a24 (ite b (store a23 (+ x #f23) pow23) a23)) + (pow24 (* pow23 y)) + + (a25 (ite b (store a24 (+ x #f24) pow24) a24)) + (pow25 (* pow24 y)) + + (a26 (ite b (store a25 (+ x #f25) pow25) a25)) + (pow26 (* pow25 y)) + + (a27 (ite b (store a26 (+ x #f26) pow26) a26)) + (pow27 (* pow26 y)) + + (a28 (ite b (store a27 (+ x #f27) pow27) a27)) + (pow28 (* pow27 y)) + + (a29 (ite b (store a28 (+ x #f28) pow28) a28)) + (pow29 (* pow28 y)) + + (a30 (ite b (store a29 (+ x #f29) pow29) a29)) + (pow30 (* pow29 y)) + + (a31 (ite b (store a30 (+ x #f30) pow30) a30)) + (pow31 (* pow30 y)) + + (a32 (ite b (store a31 (+ x #f31) pow31) a31)) + (pow32 (* pow31 y)) + + (a33 (ite b (store a32 (+ x #f32) pow32) a32)) + (pow33 (* pow32 y)) + + (a34 (ite b (store a33 (+ x #f33) pow33) a33)) + (pow34 (* pow33 y)) + + (a35 (ite b (store a34 (+ x #f34) pow34) a34)) + (pow35 (* pow34 y)) + + (a36 (ite b (store a35 (+ x #f35) pow35) a35)) + (pow36 (* pow35 y)) + + (a37 (ite b (store a36 (+ x #f36) pow36) a36)) + (pow37 (* pow36 y)) + + (a38 (ite b (store a37 (+ x #f37) pow37) a37)) + (pow38 (* pow37 y)) + + (a39 (ite b (store a38 (+ x #f38) pow38) a38)) + (pow39 (* pow38 y)) + + (a40 (ite b (store a39 (+ x #f39) pow39) a39)) + (pow40 (* pow39 y)) + + (a41 (ite b (store a40 (+ x #f40) pow40) a40)) + (pow41 (* pow40 y)) + + (a42 (ite b (store a41 (+ x #f41) pow41) a41)) + (pow42 (* pow41 y)) + + (a43 (ite b (store a42 (+ x #f42) pow42) a42)) + (pow43 (* pow42 y)) + + (a44 (ite b (store a43 (+ x #f43) pow43) a43)) + (pow44 (* pow43 y)) + + (a45 (ite b (store a44 (+ x #f44) pow44) a44)) + (pow45 (* pow44 y)) + + (a46 (ite b (store a45 (+ x #f45) pow45) a45)) + (pow46 (* pow45 y)) + + (a47 (ite b (store a46 (+ x #f46) pow46) a46)) + (pow47 (* pow46 y)) + + (a48 (ite b (store a47 (+ x #f47) pow47) a47)) + (pow48 (* pow47 y)) + + (a49 (ite b (store a48 (+ x #f48) pow48) a48)) + (pow49 (* pow48 y)) + + (output (select a49 y)) + ) + + output + )))) + ) + (ram_arrays (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0m52435875175126190479447740508185965837690552500527637822603658699938581184513 1152921504606846976 ())) + + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 1152921504606846976 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (a10 (ite b (store a9 (+ x #f9) pow9) a9)) + (pow10 (* pow9 y)) + + (a11 (ite b (store a10 (+ x #f10) pow10) a10)) + (pow11 (* pow10 y)) + + (a12 (ite b (store a11 (+ x #f11) pow11) a11)) + (pow12 (* pow11 y)) + + (a13 (ite b (store a12 (+ x #f12) pow12) a12)) + (pow13 (* pow12 y)) + + (a14 (ite b (store a13 (+ x #f13) pow13) a13)) + (pow14 (* pow13 y)) + + (a15 (ite b (store a14 (+ x #f14) pow14) a14)) + (pow15 (* pow14 y)) + + (a16 (ite b (store a15 (+ x #f15) pow15) a15)) + (pow16 (* pow15 y)) + + (a17 (ite b (store a16 (+ x #f16) pow16) a16)) + (pow17 (* pow16 y)) + + (a18 (ite b (store a17 (+ x #f17) pow17) a17)) + (pow18 (* pow17 y)) + + (a19 (ite b (store a18 (+ x #f18) pow18) a18)) + (pow19 (* pow18 y)) + + (a20 (ite b (store a19 (+ x #f19) pow19) a19)) + (pow20 (* pow19 y)) + + (a21 (ite b (store a20 (+ x #f20) pow20) a20)) + (pow21 (* pow20 y)) + + (a22 (ite b (store a21 (+ x #f21) pow21) a21)) + (pow22 (* pow21 y)) + + (a23 (ite b (store a22 (+ x #f22) pow22) a22)) + (pow23 (* pow22 y)) + + (a24 (ite b (store a23 (+ x #f23) pow23) a23)) + (pow24 (* pow23 y)) + + (a25 (ite b (store a24 (+ x #f24) pow24) a24)) + (pow25 (* pow24 y)) + + (a26 (ite b (store a25 (+ x #f25) pow25) a25)) + (pow26 (* pow25 y)) + + (a27 (ite b (store a26 (+ x #f26) pow26) a26)) + (pow27 (* pow26 y)) + + (a28 (ite b (store a27 (+ x #f27) pow27) a27)) + (pow28 (* pow27 y)) + + (a29 (ite b (store a28 (+ x #f28) pow28) a28)) + (pow29 (* pow28 y)) + + (a30 (ite b (store a29 (+ x #f29) pow29) a29)) + (pow30 (* pow29 y)) + + (a31 (ite b (store a30 (+ x #f30) pow30) a30)) + (pow31 (* pow30 y)) + + (a32 (ite b (store a31 (+ x #f31) pow31) a31)) + (pow32 (* pow31 y)) + + (a33 (ite b (store a32 (+ x #f32) pow32) a32)) + (pow33 (* pow32 y)) + + (a34 (ite b (store a33 (+ x #f33) pow33) a33)) + (pow34 (* pow33 y)) + + (a35 (ite b (store a34 (+ x #f34) pow34) a34)) + (pow35 (* pow34 y)) + + (a36 (ite b (store a35 (+ x #f35) pow35) a35)) + (pow36 (* pow35 y)) + + (a37 (ite b (store a36 (+ x #f36) pow36) a36)) + (pow37 (* pow36 y)) + + (a38 (ite b (store a37 (+ x #f37) pow37) a37)) + (pow38 (* pow37 y)) + + (a39 (ite b (store a38 (+ x #f38) pow38) a38)) + (pow39 (* pow38 y)) + + (a40 (ite b (store a39 (+ x #f39) pow39) a39)) + (pow40 (* pow39 y)) + + (a41 (ite b (store a40 (+ x #f40) pow40) a40)) + (pow41 (* pow40 y)) + + (a42 (ite b (store a41 (+ x #f41) pow41) a41)) + (pow42 (* pow41 y)) + + (a43 (ite b (store a42 (+ x #f42) pow42) a42)) + (pow43 (* pow42 y)) + + (a44 (ite b (store a43 (+ x #f43) pow43) a43)) + (pow44 (* pow43 y)) + + (a45 (ite b (store a44 (+ x #f44) pow44) a44)) + (pow45 (* pow44 y)) + + (a46 (ite b (store a45 (+ x #f45) pow45) a45)) + (pow46 (* pow45 y)) + + (a47 (ite b (store a46 (+ x #f46) pow46) a46)) + (pow47 (* pow46 y)) + + (a48 (ite b (store a47 (+ x #f47) pow47) a47)) + (pow48 (* pow47 y)) + + (a49 (ite b (store a48 (+ x #f48) pow48) a48)) + (pow49 (* pow48 y)) + + (output (select a49 y)) + ) + + (= output y) + ))) + ))) diff --git a/examples/ir/volatile_50accs_size32.circir b/examples/ir/volatile_50accs_size32.circir new file mode 100644 index 000000000..82f411ab5 --- /dev/null +++ b/examples/ir/volatile_50accs_size32.circir @@ -0,0 +1,349 @@ + +; TEST_FILE +; FEATURES: r1cs poly +; CMD: $circ $file r1cs --proof-impl mirage --action count +(computations + (main + (computation + (metadata + (parties prover verifier) + (inputs + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (commitments)) + (precompute + () + ((return (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513))) + (tuple + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 32 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (a10 (ite b (store a9 (+ x #f9) pow9) a9)) + (pow10 (* pow9 y)) + + (a11 (ite b (store a10 (+ x #f10) pow10) a10)) + (pow11 (* pow10 y)) + + (a12 (ite b (store a11 (+ x #f11) pow11) a11)) + (pow12 (* pow11 y)) + + (a13 (ite b (store a12 (+ x #f12) pow12) a12)) + (pow13 (* pow12 y)) + + (a14 (ite b (store a13 (+ x #f13) pow13) a13)) + (pow14 (* pow13 y)) + + (a15 (ite b (store a14 (+ x #f14) pow14) a14)) + (pow15 (* pow14 y)) + + (a16 (ite b (store a15 (+ x #f15) pow15) a15)) + (pow16 (* pow15 y)) + + (a17 (ite b (store a16 (+ x #f16) pow16) a16)) + (pow17 (* pow16 y)) + + (a18 (ite b (store a17 (+ x #f17) pow17) a17)) + (pow18 (* pow17 y)) + + (a19 (ite b (store a18 (+ x #f18) pow18) a18)) + (pow19 (* pow18 y)) + + (a20 (ite b (store a19 (+ x #f19) pow19) a19)) + (pow20 (* pow19 y)) + + (a21 (ite b (store a20 (+ x #f20) pow20) a20)) + (pow21 (* pow20 y)) + + (a22 (ite b (store a21 (+ x #f21) pow21) a21)) + (pow22 (* pow21 y)) + + (a23 (ite b (store a22 (+ x #f22) pow22) a22)) + (pow23 (* pow22 y)) + + (a24 (ite b (store a23 (+ x #f23) pow23) a23)) + (pow24 (* pow23 y)) + + (a25 (ite b (store a24 (+ x #f24) pow24) a24)) + (pow25 (* pow24 y)) + + (a26 (ite b (store a25 (+ x #f25) pow25) a25)) + (pow26 (* pow25 y)) + + (a27 (ite b (store a26 (+ x #f26) pow26) a26)) + (pow27 (* pow26 y)) + + (a28 (ite b (store a27 (+ x #f27) pow27) a27)) + (pow28 (* pow27 y)) + + (a29 (ite b (store a28 (+ x #f28) pow28) a28)) + (pow29 (* pow28 y)) + + (a30 (ite b (store a29 (+ x #f29) pow29) a29)) + (pow30 (* pow29 y)) + + (a31 (ite b (store a30 (+ x #f30) pow30) a30)) + (pow31 (* pow30 y)) + + (a32 (ite b (store a31 (+ x #f31) pow31) a31)) + (pow32 (* pow31 y)) + + (a33 (ite b (store a32 (+ x #f32) pow32) a32)) + (pow33 (* pow32 y)) + + (a34 (ite b (store a33 (+ x #f33) pow33) a33)) + (pow34 (* pow33 y)) + + (a35 (ite b (store a34 (+ x #f34) pow34) a34)) + (pow35 (* pow34 y)) + + (a36 (ite b (store a35 (+ x #f35) pow35) a35)) + (pow36 (* pow35 y)) + + (a37 (ite b (store a36 (+ x #f36) pow36) a36)) + (pow37 (* pow36 y)) + + (a38 (ite b (store a37 (+ x #f37) pow37) a37)) + (pow38 (* pow37 y)) + + (a39 (ite b (store a38 (+ x #f38) pow38) a38)) + (pow39 (* pow38 y)) + + (a40 (ite b (store a39 (+ x #f39) pow39) a39)) + (pow40 (* pow39 y)) + + (a41 (ite b (store a40 (+ x #f40) pow40) a40)) + (pow41 (* pow40 y)) + + (a42 (ite b (store a41 (+ x #f41) pow41) a41)) + (pow42 (* pow41 y)) + + (a43 (ite b (store a42 (+ x #f42) pow42) a42)) + (pow43 (* pow42 y)) + + (a44 (ite b (store a43 (+ x #f43) pow43) a43)) + (pow44 (* pow43 y)) + + (a45 (ite b (store a44 (+ x #f44) pow44) a44)) + (pow45 (* pow44 y)) + + (a46 (ite b (store a45 (+ x #f45) pow45) a45)) + (pow46 (* pow45 y)) + + (a47 (ite b (store a46 (+ x #f46) pow46) a46)) + (pow47 (* pow46 y)) + + (a48 (ite b (store a47 (+ x #f47) pow47) a47)) + (pow48 (* pow47 y)) + + (a49 (ite b (store a48 (+ x #f48) pow48) a48)) + (pow49 (* pow48 y)) + + (output (select a49 y)) + ) + + output + )))) + ) + (ram_arrays (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0m52435875175126190479447740508185965837690552500527637822603658699938581184513 32 ())) + + (set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 + (declare + ( + (x (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (y (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513)) + (b bool) + ) + (let ( + (a0 (#a (mod 52435875175126190479447740508185965837690552500527637822603658699938581184513) #f0 32 ())) + (pow0 #f1) + + (a1 (ite b (store a0 (+ x #f0) pow0) a0)) + (pow1 (* pow0 y)) + + (a2 (ite b (store a1 (+ x #f1) pow1) a1)) + (pow2 (* pow1 y)) + + (a3 (ite b (store a2 (+ x #f2) pow2) a2)) + (pow3 (* pow2 y)) + + (a4 (ite b (store a3 (+ x #f3) pow3) a3)) + (pow4 (* pow3 y)) + + (a5 (ite b (store a4 (+ x #f4) pow4) a4)) + (pow5 (* pow4 y)) + + (a6 (ite b (store a5 (+ x #f5) pow5) a5)) + (pow6 (* pow5 y)) + + (a7 (ite b (store a6 (+ x #f6) pow6) a6)) + (pow7 (* pow6 y)) + + (a8 (ite b (store a7 (+ x #f7) pow7) a7)) + (pow8 (* pow7 y)) + + (a9 (ite b (store a8 (+ x #f8) pow8) a8)) + (pow9 (* pow8 y)) + + (a10 (ite b (store a9 (+ x #f9) pow9) a9)) + (pow10 (* pow9 y)) + + (a11 (ite b (store a10 (+ x #f10) pow10) a10)) + (pow11 (* pow10 y)) + + (a12 (ite b (store a11 (+ x #f11) pow11) a11)) + (pow12 (* pow11 y)) + + (a13 (ite b (store a12 (+ x #f12) pow12) a12)) + (pow13 (* pow12 y)) + + (a14 (ite b (store a13 (+ x #f13) pow13) a13)) + (pow14 (* pow13 y)) + + (a15 (ite b (store a14 (+ x #f14) pow14) a14)) + (pow15 (* pow14 y)) + + (a16 (ite b (store a15 (+ x #f15) pow15) a15)) + (pow16 (* pow15 y)) + + (a17 (ite b (store a16 (+ x #f16) pow16) a16)) + (pow17 (* pow16 y)) + + (a18 (ite b (store a17 (+ x #f17) pow17) a17)) + (pow18 (* pow17 y)) + + (a19 (ite b (store a18 (+ x #f18) pow18) a18)) + (pow19 (* pow18 y)) + + (a20 (ite b (store a19 (+ x #f19) pow19) a19)) + (pow20 (* pow19 y)) + + (a21 (ite b (store a20 (+ x #f20) pow20) a20)) + (pow21 (* pow20 y)) + + (a22 (ite b (store a21 (+ x #f21) pow21) a21)) + (pow22 (* pow21 y)) + + (a23 (ite b (store a22 (+ x #f22) pow22) a22)) + (pow23 (* pow22 y)) + + (a24 (ite b (store a23 (+ x #f23) pow23) a23)) + (pow24 (* pow23 y)) + + (a25 (ite b (store a24 (+ x #f24) pow24) a24)) + (pow25 (* pow24 y)) + + (a26 (ite b (store a25 (+ x #f25) pow25) a25)) + (pow26 (* pow25 y)) + + (a27 (ite b (store a26 (+ x #f26) pow26) a26)) + (pow27 (* pow26 y)) + + (a28 (ite b (store a27 (+ x #f27) pow27) a27)) + (pow28 (* pow27 y)) + + (a29 (ite b (store a28 (+ x #f28) pow28) a28)) + (pow29 (* pow28 y)) + + (a30 (ite b (store a29 (+ x #f29) pow29) a29)) + (pow30 (* pow29 y)) + + (a31 (ite b (store a30 (+ x #f30) pow30) a30)) + (pow31 (* pow30 y)) + + (a32 (ite b (store a31 (+ x #f31) pow31) a31)) + (pow32 (* pow31 y)) + + (a33 (ite b (store a32 (+ x #f32) pow32) a32)) + (pow33 (* pow32 y)) + + (a34 (ite b (store a33 (+ x #f33) pow33) a33)) + (pow34 (* pow33 y)) + + (a35 (ite b (store a34 (+ x #f34) pow34) a34)) + (pow35 (* pow34 y)) + + (a36 (ite b (store a35 (+ x #f35) pow35) a35)) + (pow36 (* pow35 y)) + + (a37 (ite b (store a36 (+ x #f36) pow36) a36)) + (pow37 (* pow36 y)) + + (a38 (ite b (store a37 (+ x #f37) pow37) a37)) + (pow38 (* pow37 y)) + + (a39 (ite b (store a38 (+ x #f38) pow38) a38)) + (pow39 (* pow38 y)) + + (a40 (ite b (store a39 (+ x #f39) pow39) a39)) + (pow40 (* pow39 y)) + + (a41 (ite b (store a40 (+ x #f40) pow40) a40)) + (pow41 (* pow40 y)) + + (a42 (ite b (store a41 (+ x #f41) pow41) a41)) + (pow42 (* pow41 y)) + + (a43 (ite b (store a42 (+ x #f42) pow42) a42)) + (pow43 (* pow42 y)) + + (a44 (ite b (store a43 (+ x #f43) pow43) a43)) + (pow44 (* pow43 y)) + + (a45 (ite b (store a44 (+ x #f44) pow44) a44)) + (pow45 (* pow44 y)) + + (a46 (ite b (store a45 (+ x #f45) pow45) a45)) + (pow46 (* pow45 y)) + + (a47 (ite b (store a46 (+ x #f46) pow46) a46)) + (pow47 (* pow46 y)) + + (a48 (ite b (store a47 (+ x #f47) pow47) a47)) + (pow48 (* pow47 y)) + + (a49 (ite b (store a48 (+ x #f48) pow48) a48)) + (pow49 (* pow48 y)) + + (output (select a49 y)) + ) + + (= output y) + ))) + ))) diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index dd49261b0..000000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -tqdm==4.63.0 diff --git a/scripts/assert_no_default_features.zsh b/scripts/assert_no_default_features.zsh new file mode 100755 index 000000000..491e14b21 --- /dev/null +++ b/scripts/assert_no_default_features.zsh @@ -0,0 +1,12 @@ +#!/usr/bin/env zsh +set -e +default_features_line=$(grep 'default = ' ${0:a:h:h}/Cargo.toml) +if [[ $default_features_line != "default = []" ]] +then + echo "There are default features in Cargo.toml" + echo + echo $default_features_line + echo + echo "Please remove them before pushing" + exit 1 +fi diff --git a/scripts/file_test.py b/scripts/file_test.py new file mode 100755 index 000000000..6f26d5b64 --- /dev/null +++ b/scripts/file_test.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python3 + +import argparse +import re +import os +import subprocess +import sys + +from dataclasses import dataclass +from abc import ABC +from typing import Optional + +comment_pattern = "(?:;|//|#)" +test_file_pattern = re.compile(rf"{comment_pattern}\s*TEST_FILE") +features_pattern = re.compile(rf"{comment_pattern}\s*FEATURES:\s*(\S[^\n]*\S)") +circ_cmdline_pattern = re.compile(rf"{comment_pattern}\s*CMD:\s*(\S[^\n]*\S)") + +# compute the repository root +repo_root = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) +while not os.path.exists(f"{repo_root}/.git") and repo_root != "/": + repo_root = os.path.abspath(f"{repo_root}/..") +if repo_root == "/": + print("Not in a git directory") + sys.exit(1) + + +@dataclass +class TestConfig(ABC): + command_templates: list[str] + features: set[str] + + +class FileTestResult(ABC): + pass + + +@dataclass +class Skipped(FileTestResult): + missing_features: set[str] + + +@dataclass +class Fail(FileTestResult): + command: str + output: str + error: str + exit_code: int + + +@dataclass +class Pass(FileTestResult): + pass + + +@dataclass +class Binaries: + circ: Optional[str] + zk: Optional[str] + cp: Optional[str] + + +def parse_test_config(path: str) -> TestConfig: + cfg = TestConfig([], set()) + test_file_found = False + for line in open(path).readlines(): + if (m := features_pattern.search(line)) is not None: + cfg.features |= set(m.group(1).replace(",", " ").split(" ")) + elif (m := circ_cmdline_pattern.search(line)) is not None: + cfg.command_templates.append(m.group(1)) + elif (m := test_file_pattern.search(line)) is not None: + test_file_found = True + else: + pass + if not test_file_found: + print(f"Missing TEST_FILE comment in {path}") + sys.exit(1) + return cfg + + +def expand_circ_binaries(cmd: str) -> str: + for base in ["circ", "cp", "zk"]: + cmd = re.sub(rf"\${base}\b", f"{repo_root}/target/release/examples/{base}", cmd) + return cmd + + +def run_test(features: set[str], path: str) -> FileTestResult: + path = os.path.abspath(path) + cfg = parse_test_config(path) + missing_features = cfg.features - features + if missing_features: + return Skipped(missing_features) + + for cmd in cfg.command_templates: + cmd = cmd.replace("$file", path) + cmd = expand_circ_binaries(cmd) + process = subprocess.run(cmd, shell=True, capture_output=True) + if process.returncode != 0: + return Fail( + cmd, + process.stdout.decode(), + process.stderr.decode(), + process.returncode, + ) + return Pass() + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("features", help="comma-separated feature list") + parser.add_argument("file") + args = parser.parse_args() + features = set(args.features.split(",")) + file = args.file + result = run_test(features, file) + match result: + case Pass(): + print(f" passed '{file}'") + case Fail(command, output, error, exit_code): + print(f" failed '{file}'") + print(f"== output ==") + print(output) + print(f"== error ==") + print(error) + print(f"== exit code ==") + print(exit_code) + print(f"== command ==") + print(command) + print(f" failed '{file}'") + sys.exit(1) + case Skipped(missing_features): + print(f"skipped '{file}'; missing features {missing_features}") + + +main() diff --git a/scripts/file_tests.zsh b/scripts/file_tests.zsh new file mode 100755 index 000000000..493f01b6e --- /dev/null +++ b/scripts/file_tests.zsh @@ -0,0 +1,10 @@ +#!/usr/bin/env zsh + +set -eu + +disable -r time + +for file in $(grep -r -l TEST_FILE ${0:a:h:h}/examples | grep -v /gen/) +do + ${0:a:h}/file_test.py $1 $file +done diff --git a/src/ir/opt/fits_in_bits_ip.rs b/src/ir/opt/fits_in_bits_ip.rs new file mode 100644 index 000000000..5b079835c --- /dev/null +++ b/src/ir/opt/fits_in_bits_ip.rs @@ -0,0 +1,156 @@ +//! Replace [Op::PfFitsInBits] with an interactive protocol. + +use super::mem::ram::haboeck_range_check; +use crate::ir::term::*; +use crate::util::ns::Namespace; +use circ_fields::FieldT; +use fxhash::FxHashMap as HashMap; +use log::debug; + +/// Replace [Op::PfFitsInBits] with an interactive protocol. +pub fn fits_in_bits_ip(c: &mut Computation) { + let mut constraints = Vec::new(); + assert_eq!(c.outputs.len(), 1); + collect_constraints(&c.outputs[0], &mut constraints); + // (field, num bits) -> terms in that range + let mut by_field_and_size: HashMap<(FieldT, usize), Vec> = HashMap::default(); + for constraint in &constraints { + if let Op::PfFitsInBits(bits) = constraint.op() { + let field = check(&constraint.cs()[0]).as_pf().clone(); + by_field_and_size + .entry((field, *bits)) + .or_default() + .push(constraint.cs()[0].clone()); + } else { + unreachable!() + } + } + if constraints.is_empty() { + return; + } + let mut new_assertions = Vec::new(); + let ns = Namespace::default(); + let mut substitution_cache = TermMap::default(); + for (i, ((field, num_bits), terms)) in by_field_and_size.into_iter().enumerate() { + let ns = ns.subspace(format!("fib_{}_{}", i, num_bits)); + debug!( + "Found {} values that fit in {} bits in field {}", + terms.len(), + num_bits, + field + ); + let (cost, k) = (0..=num_bits as u32) + .filter_map(|k| { + let cost = subrange_cost(terms.len(), num_bits, k)?; + debug!("subrange size {} => cost {}", k, cost); + Some((cost, k)) + }) + .min() + .unwrap(); + debug!("Using subranges of size {}, for cost {}", k, cost); + if k > 0 { + for t in &terms { + substitution_cache + .insert(term![Op::PfFitsInBits(num_bits); t.clone()], bool_lit(true)); + } + if k < num_bits as u32 { + let field_bits = field.modulus().significant_bits() as usize; + let num_subranges = num_bits / k as usize; + let end_length = num_bits - num_subranges * k as usize; + let mut subterms = Vec::new(); + for (j, t) in terms.into_iter().enumerate() { + let ns = ns.subspace(format!("t{}", j)); + let bv = term_c![Op::PfToBv(field_bits); t]; + let mut pf_summands = Vec::new(); + for ii in 0..num_subranges { + let sub_bv = + term_c![Op::BvExtract(k as usize * (ii + 1) - 1, k as usize * ii); &bv]; + let sub_f = c.new_var( + &ns.fqn(format!("sub{}", ii)), + Sort::Field(field.clone()), + Some(super::super::proof::PROVER_ID), + Some(term![Op::UbvToPf(field.clone()); sub_bv]), + ); + pf_summands.push( + term![PF_MUL.clone(); pf_lit(field.new_v(1).pow(k as u64 * ii as u64)), sub_f.clone()], + ); + subterms.push(sub_f); + } + if end_length > 0 { + let end_start = num_subranges * k as usize; + let sub_bv = term_c![Op::BvExtract(num_bits - 1, end_start); &bv]; + let sub_f = c.new_var( + &ns.fqn("end"), + Sort::Field(field.clone()), + Some(super::super::proof::PROVER_ID), + Some(term![Op::UbvToPf(field.clone()); sub_bv]), + ); + pf_summands.push(term![PF_MUL.clone(); pf_lit(field.new_v(1 << end_start)), sub_f.clone()]); + new_assertions.push(term![Op::PfFitsInBits(end_length); sub_f]); + } + new_assertions.push(term![EQ; t, term(PF_ADD.clone(), pf_summands)]); + } + let upper_bound = 1usize.checked_shl(k).unwrap(); + haboeck_range_check( + c, + subterms, + &ns.subspace("range"), + &mut new_assertions, + upper_bound, + &field, + ) + } else { + let upper_bound = 1usize.checked_shl(k).unwrap(); + haboeck_range_check( + c, + terms, + &ns.subspace("range"), + &mut new_assertions, + upper_bound, + &field, + ) + } + } else { + for t in terms { + new_assertions.push(term![Op::PfFitsInBits(num_bits); t.clone()]); + } + } + } + new_assertions.push(extras::substitute_cache( + &c.outputs[0], + &mut substitution_cache, + )); + assert!(new_assertions.len() > 1); + c.outputs[0] = term(AND, new_assertions); +} + +/// The cost of doing k-bit ranges for n b-bit values. +fn subrange_cost(n: usize, b: usize, k: u32) -> Option { + if k == 0 { + Some(n * b) + } else { + let n_ranges = b / k as usize; + let n_leftover_bits = b - n_ranges * k as usize; + n_ranges + .checked_mul(n)? + .checked_add(1usize.checked_shl(k)?)? + .checked_mul(3)? + .checked_add(n_leftover_bits.checked_mul(n)?) + } +} + +/// Given a boolean assertion `t`, collect any implied bitsize constraints into `constraints`. +/// +/// Each constraint most have operator [Op::PfFitsInBits]. +fn collect_constraints(t: &Term, constraints: &mut Vec) { + debug_assert_eq!(check(t), Sort::Bool); + match t.op() { + Op::PfFitsInBits(_) => constraints.push(t.clone()), + &AND => { + for c in t.cs() { + collect_constraints(c, constraints); + } + } + _ => {} + } +} diff --git a/src/ir/opt/mem/obliv.rs b/src/ir/opt/mem/obliv.rs index 9514692b4..d33e01d50 100644 --- a/src/ir/opt/mem/obliv.rs +++ b/src/ir/opt/mem/obliv.rs @@ -22,6 +22,8 @@ use crate::ir::term::*; use log::trace; +const OBLIV_SIZE_THRESH: usize = 8096; + #[derive(Default)] struct OblivRewriter { tups: TermMap, @@ -43,7 +45,13 @@ impl OblivRewriter { fn visit(&mut self, t: &Term) { let (tup_opt, term_opt) = match t.op() { Op::Var(_, sort) if sort.is_scalar() => (Some(t.clone()), None), - Op::Const(v @ Value::Array(_)) => (Some(leaf_term(Op::Const(arr_val_to_tup(v)))), None), + Op::Const(v @ Value::Array(a)) => { + if a.size <= OBLIV_SIZE_THRESH { + (Some(leaf_term(Op::Const(arr_val_to_tup(v)))), None) + } else { + (None, None) + } + } Op::Array(_k, _v) => ( Some(term( Op::Tuple, @@ -51,10 +59,16 @@ impl OblivRewriter { )), None, ), - Op::Fill(_k, size) => ( - Some(term(Op::Tuple, vec![self.get_t(&t.cs()[0]).clone(); *size])), - None, - ), + Op::Fill(_k, size) => { + if *size < OBLIV_SIZE_THRESH { + ( + Some(term(Op::Tuple, vec![self.get_t(&t.cs()[0]).clone(); *size])), + None, + ) + } else { + (None, None) + } + } Op::Store => { let a = &t.cs()[0]; let i = &t.cs()[1]; @@ -62,7 +76,7 @@ impl OblivRewriter { ( if let Some(aa) = self.tups.get(a) { if suitable_const(i) { - trace!("simplify store {}", i); + trace!("simplify store at {}", i); Some(term![Op::Update(get_const(i)); aa.clone(), self.get_t(v).clone()]) } else { None @@ -78,7 +92,7 @@ impl OblivRewriter { let i = &t.cs()[1]; if let Some(aa) = self.tups.get(a) { if suitable_const(i) { - trace!("simplify select {}", i); + trace!("simplify select at {}", i); let tt = term![Op::Field(get_const(i)); aa.clone()]; ( Some(tt.clone()), diff --git a/src/ir/opt/mem/ram.rs b/src/ir/opt/mem/ram.rs index 3cd49d2af..420c5770a 100644 --- a/src/ir/opt/mem/ram.rs +++ b/src/ir/opt/mem/ram.rs @@ -18,6 +18,7 @@ mod hash; pub mod persistent; pub mod set; pub mod volatile; +pub use checker::haboeck_range_check; #[derive(Debug)] /// An access to a RAM diff --git a/src/ir/opt/mem/ram/checker.rs b/src/ir/opt/mem/ram/checker.rs index ab14d34e8..43ce8b054 100644 --- a/src/ir/opt/mem/ram/checker.rs +++ b/src/ir/opt/mem/ram/checker.rs @@ -248,7 +248,7 @@ fn range_check( } /// Haboeck range check -fn haboeck_range_check( +pub fn haboeck_range_check( c: &mut Computation, values: Vec, ns: &Namespace, diff --git a/src/ir/opt/mod.rs b/src/ir/opt/mod.rs index 974e274a8..466179932 100644 --- a/src/ir/opt/mod.rs +++ b/src/ir/opt/mod.rs @@ -3,6 +3,7 @@ pub mod binarize; pub mod cfold; pub mod chall; pub mod cstore; +pub mod fits_in_bits_ip; pub mod flat; pub mod inline; pub mod link; @@ -54,6 +55,8 @@ pub enum Opt { SkolemizeChallenges, /// Replace witness terms with variables DeskolemizeWitnesses, + /// Check bit-constaints with challenges. + FitsInBitsIp, } /// Run optimizations on `cs`, in this order, returning the new constraint system. @@ -85,6 +88,9 @@ pub fn opt>(mut cs: Computations, optimizations: I) .iter() .map(|a| cfold::fold_cache(a, &mut cache, &ignore.clone())) .collect(); + for p in &mut c.persistent_arrays { + p.1 = cfold::fold_cache(&p.1, &mut cache, &ignore.clone()); + } } Opt::Sha => { for a in &mut c.outputs { @@ -146,6 +152,9 @@ pub fn opt>(mut cs: Computations, optimizations: I) Opt::SkolemizeChallenges => { chall::deskolemize_challenges(c); } + Opt::FitsInBitsIp => { + fits_in_bits_ip::fits_in_bits_ip(c); + } } debug!("After {:?}: {} outputs", i, c.outputs.len()); trace!("After {:?}: {}", i, c.outputs[0]); diff --git a/util.py b/util.py deleted file mode 100644 index 01272e8aa..000000000 --- a/util.py +++ /dev/null @@ -1,42 +0,0 @@ -import os -from os import path - -# Gloable variables -feature_path = ".features.txt" -mode_path = ".mode.txt" - -# TODO: add in "kahip", "kahypar" binaries dependencies when adding new MPC changes -cargo_features = {"aby", "c", "lp", "r1cs", "smt", - "zok", "datalog", "bellman", "spartan", "poly"} - - -def save_mode(mode): - """ Save mode to file """ - with open(mode_path, 'w') as f: - f.write(mode) - - -def load_mode(): - """ Load mode from file """ - if path.exists(mode_path): - with open(mode_path, 'r') as f: - return f.read().strip() - else: - return "" - - -def save_features(features): - """ Save features to file """ - with open(feature_path, 'w') as f: - feature_str = "\n".join(features) - f.write(feature_str) - - -def load_features(): - """ Load features from file """ - if path.exists(feature_path): - with open(feature_path, 'r') as f: - features = f.read().splitlines() - return features - else: - return [] From 42f0ef953d797a7bfcb9a5a712766d4009d0bccd Mon Sep 17 00:00:00 2001 From: Alex Ozdemir Date: Tue, 11 Jun 2024 15:45:28 -0700 Subject: [PATCH 2/3] python3 --- .github/workflows/ci.yml | 2 +- driver.py | 4 ++-- scripts/aby_tests/c_benchmark_aby.py | 2 +- scripts/aby_tests/c_test_aby.py | 2 +- scripts/aby_tests/zokrates_test_aby.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 382b87f93..fb13d0d69 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: - name: No default features pushed run: zsh ./scripts/assert_no_default_features.zsh - name: Set all features on - run: python3 driver.py --all_features + run: python3 driver.py --all-features - name: Install python reqs run: python3 driver.py --install - name: Check diff --git a/driver.py b/driver.py index 7bc8ac37f..6bbdccbd3 100755 --- a/driver.py +++ b/driver.py @@ -355,10 +355,10 @@ def format_sub_process_cmd(r: subprocess.CalledProcessError) -> str: "-m", "--mode", type=str, help="set `debug` or `release` mode" ) parser.add_argument( - "-A", "--all_features", action="store_true", help="set all features on" + "-A", "--all-features", action="store_true", help="set all features on" ) parser.add_argument( - "-L", "--list_features", action="store_true", help="print active features" + "-L", "--list-features", action="store_true", help="print active features" ) parser.add_argument( "-s", diff --git a/scripts/aby_tests/c_benchmark_aby.py b/scripts/aby_tests/c_benchmark_aby.py index cc7e40520..8f0f24492 100755 --- a/scripts/aby_tests/c_benchmark_aby.py +++ b/scripts/aby_tests/c_benchmark_aby.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from util import run_benchmarks from test_suite import * diff --git a/scripts/aby_tests/c_test_aby.py b/scripts/aby_tests/c_test_aby.py index 2cbfd1345..d13bcc24c 100755 --- a/scripts/aby_tests/c_test_aby.py +++ b/scripts/aby_tests/c_test_aby.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from util import run_tests from test_suite import * diff --git a/scripts/aby_tests/zokrates_test_aby.py b/scripts/aby_tests/zokrates_test_aby.py index 5b5376969..1d20ca4ca 100755 --- a/scripts/aby_tests/zokrates_test_aby.py +++ b/scripts/aby_tests/zokrates_test_aby.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from util import run_tests from test_suite import * From 222659bf59bb83bd4ea6f1dd1403277951dd1780 Mon Sep 17 00:00:00 2001 From: Alex Ozdemir Date: Tue, 11 Jun 2024 15:46:01 -0700 Subject: [PATCH 3/3] add back requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..dd49261b0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +tqdm==4.63.0