From 19779e7109aca16dc0d2a030f74fde62bf486e22 Mon Sep 17 00:00:00 2001 From: DavePearce Date: Mon, 22 Jul 2024 12:34:38 +1200 Subject: [PATCH] Correct Build Action This corrects the placement of `CORSET_TEST_LIMIT` in the build action. In particular, this includes a new cost model to limit the number of traces considered. --- .github/workflows/rust.yml | 4 ++-- Cargo.lock | 2 +- build.rs | 3 +-- tests/models.rs | 46 ++++++++++++++++++++++++++++---------- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index c1b83ed..7c34bff 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,7 +21,7 @@ jobs: rustflags: "" - name: Build run: cargo build -vv + env: + CORSET_TEST_LIMIT: 1000 - name: Run tests run: cargo test -v - env: - CORSET_TEST_LIMIT: 4 diff --git a/Cargo.lock b/Cargo.lock index c350e68..fd7037e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -511,7 +511,7 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "corset" -version = "9.7.12" +version = "9.7.13" dependencies = [ "anyhow", "ark-bls12-377", diff --git a/build.rs b/build.rs index 65cabac..33001d7 100644 --- a/build.rs +++ b/build.rs @@ -58,7 +58,7 @@ fn generate_tests_from_lisp_files() { let out_dir = std::env::var("OUT_DIR").unwrap(); let limit = match env::var("CORSET_TEST_LIMIT") { Ok(s) => s.parse().unwrap(), - Err(_) => 0, + Err(_) => 100, }; let target = std::path::Path::new(&out_dir).join("lisp_tests.rs"); let mut f = fs::File::create(target).unwrap(); @@ -70,7 +70,6 @@ fn generate_tests_from_lisp_files() { writeln!(f, "fn test_{}() {{ check(\"{}\"); }}", m.name, m.name).unwrap(); // Check whether oracle provided or not if m.oracle.is_some() { - let limit = limit.max(m.limit); // Generate trace inputs (accepts / rejects) let (accepts, rejects) = m.generate_traces_upto(limit); // Write them out. diff --git a/tests/models.rs b/tests/models.rs index 06bd128..d080d1f 100644 --- a/tests/models.rs +++ b/tests/models.rs @@ -10,8 +10,6 @@ struct Model { name: &'static str, /// The column names needed for this test. cols: &'static [&'static str], - /// Number of rows to generate for. - limit: usize, /// The oracle determines, for a given set of column data, whether /// or not it should be accepted or rejected. oracle: Option bool>, @@ -25,14 +23,16 @@ impl Model { /// length `n`, and split them into the `accepts` and `rejects`. /// The former are those traces which are expected to pass, whilst /// the latter are those which are expected to fail. - pub fn generate_traces_upto(&self, n: usize) -> (Vec, Vec) { + pub fn generate_traces_upto(&self, m: usize) -> (Vec, Vec) { + let max_rows = Self::determine_max_rows(self.cols.len(), m); + // let Some(oracle) = self.oracle else { panic!(); }; let mut accepts = Vec::new(); let mut rejects = Vec::new(); // - for i in 0..n { + for i in 0..max_rows { for tr in self.generate_all_traces(i) { // Test the trace using the given oracle to check whether // (or not) it should be accepted. @@ -77,6 +77,36 @@ impl Model { // no more return false; } + + // Determine maximum number of trace rows we can generate within + // the given budget (i.e. maximum number of traces). + fn determine_max_rows(n: usize, m: usize) -> usize { + let mut cost = 0; + // You can compute this with pow + for i in 0..10 { + let ith = Self::cost_max_rows(i, n); + // + if (cost + ith) >= m { + return i; + } + // + cost += ith; + } + // Should be + unreachable!() + } + + fn cost_max_rows(i: usize, n: usize) -> usize { + let diff = 1 + (Self::MAX_ELEMENT - Self::MIN_ELEMENT) as usize; + // + let mut acc = 1; + // You can compute this with pow + for _ in 0..(i * n) { + acc *= diff; + } + // + acc + } } /// Represents an individial trace which, for a given number of rows, @@ -163,49 +193,41 @@ static MODELS: &[Model] = &[ Model { name: "arrays_1", cols: &["A", "B_1", "B_2", "B_3"], - limit: 2, oracle: Some(arrays_1_oracle), }, Model { name: "iszero", cols: &["A", "B"], - limit: 3, oracle: Some(iszero_oracle), }, Model { name: "shift_1", cols: &["A", "B"], - limit: 3, oracle: Some(shift_1_oracle), }, Model { name: "shift_2", cols: &["A", "B"], - limit: 3, oracle: Some(shift_2_oracle), }, Model { name: "shift_3", cols: &["A", "B"], - limit: 3, oracle: Some(shift_3_oracle), }, Model { name: "shift_5", cols: &["A", "B", "C"], - limit: 2, oracle: Some(shift_5_oracle), }, Model { name: "vanish_1", cols: &["X"], - limit: 3, oracle: Some(|_| false), }, Model { name: "vanish_2", cols: &["X"], - limit: 3, oracle: Some(|_| false), }, ];