Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[develop] Lookup: a table with ID 0 *must* contain a row with 0 only #1454

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions kimchi/src/tests/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,55 @@ fn test_runtime_table_only_one_table_with_id_zero_with_non_zero_entries_random_v
setup_successfull_runtime_table_test(vec![cfg], vec![runtime_table], lookups);
}

// This test verifies that if there is a table with ID 0, it contains a row with only zeroes.
// This is to enforce the constraint we have on the so-called "dummy value".
// FIXME: see https://github.com/o1-labs/proof-systems/issues/1460
// We should test the error message, "expected" argument of the macro won't be
// allowed anymore in future release, see clippy output.
#[test]
#[should_panic]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the correct semantics is that no "automatic dummy value" is added by default?

fn test_lookup_with_a_table_with_id_zero_but_no_zero_entry() {
let max_len: u32 = 100u32;
let seed: [u8; 32] = thread_rng().gen();
eprintln!("Seed: {:?}", seed);
let mut rng = StdRng::from_seed(seed);

// Non zero-length table
let len = 1u32 + rng.gen_range(0u32..max_len);
let table_id: i32 = 0;
// No index 0 in the table.
let indices: Vec<Fp> = (0..len)
.map(|_| 1 + rng.gen_range(0u32..max_len))
.map(Into::into)
.collect();
// No zero value
let values: Vec<Fp> = (0..len)
.map(|_| rng.gen_range(1u32..max_len))
.map(Into::into)
.collect();
let lookup_table = LookupTable {
id: table_id,
data: vec![indices, values],
};
let lookup_tables = vec![lookup_table];
let num_lookups = 20;

// circuit gates
let gates = (0..num_lookups)
.map(|i| CircuitGate::new(GateType::Lookup, Wire::for_row(i), vec![]))
.collect();

// 0 everywhere, it should handle the case (0, 0, 0). We simulate a lot of
// lookups with (0, 0, 0).
let witness = array::from_fn(|_col| vec![Fp::zero(); num_lookups]);

let _ = TestFramework::<Vesta>::default()
.gates(gates)
.witness(witness)
.lookup_tables(lookup_tables)
.setup();
}

#[test]
fn test_dummy_value_is_added_in_an_arbitraly_created_table_when_no_table_with_id_0() {
let seed: [u8; 32] = thread_rng().gen();
Expand Down