Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add balance_not_in_range
Browse files Browse the repository at this point in the history
enricobottazzi committed Dec 11, 2023
1 parent b8aceb3 commit 7063c82
Showing 2 changed files with 45 additions and 1 deletion.
Binary file modified kzg_prover/prints/univariate-grand-sum-layout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 45 additions & 1 deletion kzg_prover/src/circuits/tests.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,8 @@ mod test {
use crate::cryptocurrency::Cryptocurrency;
use crate::entry::Entry;
use crate::utils::parse_csv_to_entries;
use halo2_proofs::dev::MockProver;
use halo2_proofs::dev::{FailureLocation, MockProver, VerifyFailure};
use halo2_proofs::plonk::Any;
use num_bigint::BigUint;

const K: u32 = 9;
@@ -151,6 +152,49 @@ mod test {
}
}

// Building a proof using as input a csv file with an entry that is not in range [0, 2^N_BYTES*8 - 1] should fail the range check constraint on the leaf balance
#[test]
fn test_balance_not_in_range() {
let path = "../csv/entry_16_overflow.csv";

let mut entries: Vec<Entry<N_CURRENCIES>> = vec![Entry::init_empty(); N_USERS];
let mut cryptos = vec![Cryptocurrency::init_empty(); N_CURRENCIES];
parse_csv_to_entries::<&str, N_CURRENCIES, N_BYTES>(path, &mut entries, &mut cryptos)
.unwrap();

let circuit = UnivariateGrandSum::<N_BYTES, N_USERS, N_CURRENCIES>::init(entries.to_vec());

let invalid_prover = MockProver::run(K, &circuit, vec![vec![]]).unwrap();

assert_eq!(
invalid_prover.verify(),
Err(vec![
VerifyFailure::Permutation {
column: (Any::Fixed, 0).into(),
location: FailureLocation::OutsideRegion { row: 256 }
},
VerifyFailure::Permutation {
column: (Any::Fixed, 0).into(),
location: FailureLocation::OutsideRegion { row: 259 }
},
VerifyFailure::Permutation {
column: (Any::advice(), 10).into(),
location: FailureLocation::InRegion {
region: (2, "Perform range check on balance 0 of user 0").into(),
offset: 0
}
},
VerifyFailure::Permutation {
column: (Any::advice(), 18).into(),
location: FailureLocation::InRegion {
region: (5, "Perform range check on balance 1 of user 1").into(),
offset: 0
}
},
])
);
}

#[cfg(feature = "dev-graph")]
#[test]
fn print_solvency_v2_circuit() {

0 comments on commit 7063c82

Please sign in to comment.