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

Lookups: Improve assertions and tests regarding empty rows and table duplicates #1263

Merged
merged 12 commits into from
Nov 21, 2023

Conversation

volhovm
Copy link
Member

@volhovm volhovm commented Oct 2, 2023

This resolves MinaProtocol/mina#14070 and MinaProtocol/mina#14097.

@volhovm volhovm changed the base branch from master to develop October 2, 2023 20:19
@volhovm volhovm force-pushed the volhovm/mina14070-table-id-zero-row branch from 09684d6 to fa03ec4 Compare October 2, 2023 20:21
@volhovm
Copy link
Member Author

volhovm commented Oct 2, 2023

@mimoo Question: test_zero_table_zero_row will return true if at least one element of the row is zero. While the description of the function implies it should return true when all the elements of the row are zero. Is this a bug or a documentation issue?

https://github.com/o1-labs/proof-systems/blob/develop/kimchi/src/circuits/lookup/tables/mod.rs#L35

(You were in git blame for this line, feel free to redirect me to someone else if you're not the author)

@volhovm volhovm force-pushed the volhovm/mina14070-table-id-zero-row branch 2 times, most recently from 798f83f to 77fbfc1 Compare October 4, 2023 21:56
@volhovm volhovm force-pushed the volhovm/mina14070-table-id-zero-row branch from c799649 to f9b2ce7 Compare October 12, 2023 11:59
@volhovm volhovm force-pushed the volhovm/mina14070-table-id-zero-row branch 2 times, most recently from 442a784 to 670bf26 Compare October 12, 2023 12:00
@volhovm volhovm force-pushed the volhovm/mina14070-table-id-zero-row branch from 670bf26 to eaf3184 Compare October 12, 2023 12:05
@volhovm volhovm force-pushed the volhovm/mina14070-table-id-zero-row branch from e7a23cc to f004e8b Compare October 30, 2023 09:27
@volhovm volhovm changed the title Add a unit test for lookup table zero table zero row condition Lookups: Improve assertions and tests regarding empty rows and table duplicates Oct 30, 2023
@volhovm volhovm force-pushed the volhovm/mina14070-table-id-zero-row branch from f004e8b to 0e772a2 Compare October 30, 2023 09:42
@@ -411,6 +433,8 @@ impl<F: PrimeField + SquareRootField> LookupConstraintSystem<F> {
lookup_table8.push(eval);
}

// @volhovm: Do we need to enforce that there is at least one table
Copy link
Member

Choose a reason for hiding this comment

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

We should actually ensure that either we have a table with ID 0 or that there was space for us to insert a 0 value.

Copy link
Member Author

Choose a reason for hiding this comment

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

"space to insert zero value" is checking that the total number of lookup table rows is one less than d1 domain minus zk rows?

@@ -204,7 +204,7 @@ impl LookupInfo {
&self,
domain: &EvaluationDomains<F>,
gates: &[CircuitGate<F>],
) -> (LookupSelectors<Evaluations<F>>, Vec<LookupTable<F>>) {
) -> (LookupSelectors<Evaluations<F>>, HashSet<LookupTable<F>>) {
Copy link
Member

Choose a reason for hiding this comment

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

HashSet ordering is non-deterministic (and we probably shouldn't be hashing a whole lookup table). Revert.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hashset order being nondeterministic is true, but the problem is deeper then: we build tables right now on the result of this hashset converted to a vector: we return gate_tables.iter().convert(), where gate_tables is a hashset. What I did instead is to return it directly without converting to vec, because it might be more convenient to check for duplicates.

The question is: how do you want tables sorted between each other, and is there any difference at all?

/// A table of values that can be used for a lookup, along with the ID for the table.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Copy link
Member

Choose a reason for hiding this comment

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

Don't hash/check equality on a Vec<Vec<F>>. It could be large!

Copy link
Member Author

Choose a reason for hiding this comment

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

It is absolutely true and I realise it, but otherwise we can't really check if there are any truly duplicate tables in our setup. In that case we would only be able to check table id collisions. I guess it's fine.

kimchi/src/prover_index.rs Outdated Show resolved Hide resolved
kimchi/src/tests/lookup.rs Show resolved Hide resolved
@volhovm volhovm force-pushed the volhovm/mina14070-table-id-zero-row branch from bdd89db to fba1add Compare October 30, 2023 19:37
@volhovm volhovm force-pushed the volhovm/mina14070-table-id-zero-row branch from fba1add to 1f59b81 Compare November 2, 2023 11:55
@volhovm volhovm force-pushed the volhovm/mina14070-table-id-zero-row branch from 1f59b81 to 7c4e977 Compare November 2, 2023 11:56
@volhovm volhovm force-pushed the volhovm/mina14070-table-id-zero-row branch from 7c4e977 to 2121c7f Compare November 2, 2023 12:21
@dannywillems
Copy link
Member

dannywillems commented Nov 13, 2023

Opened PR: MinaProtocol/mina#14549.
Checking if it does not break anything in Mina.
Feel free to push on this branch and update the PR.

@dannywillems
Copy link
Member

Changes have to be done in https://github.com/o1-labs/o1js-bindings/tree/main/kimchi/wasm.

error[E0451]: field `id` of struct `kimchi::circuits::lookup::tables::LookupTable` is private
  --> src/pasta_fp_plonk_index.rs:47:13
   |
47 |             id: wasm_lt.id.into(),
   |             ^^^^^^^^^^^^^^^^^^^^^ private field

error[E0451]: field `data` of struct `kimchi::circuits::lookup::tables::LookupTable` is private
  --> src/pasta_fp_plonk_index.rs:48:13
   |
48 |             data: wasm_lt.data.0,
   |             ^^^^^^^^^^^^^^^^^^^^ private field

error[E0451]: field `id` of struct `kimchi::circuits::lookup::tables::LookupTable` is private
  --> src/pasta_fq_plonk_index.rs:44:13
   |
44 |             id: wasm_lt.id.into(),
   |             ^^^^^^^^^^^^^^^^^^^^^ private field

error[E0451]: field `data` of struct `kimchi::circuits::lookup::tables::LookupTable` is private
  --> src/pasta_fq_plonk_index.rs:45:13
   |
45 |             data: wasm_lt.data.0,
   |             ^^^^^^^^^^^^^^^^^^^^ private field

@dannywillems
Copy link
Member

Please git merge develop and check again against mina.

@dannywillems dannywillems merged commit 7f6eba0 into develop Nov 21, 2023
4 checks passed
@dannywillems dannywillems deleted the volhovm/mina14070-table-id-zero-row branch November 21, 2023 13:49
runtime_tables_ids
.iter()
.chain(fixed_lookup_tables_ids.iter()),
"duplicates between runtime and fixed tables",
Copy link
Member

Choose a reason for hiding this comment

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

We explicitly don't want this. This should never have landed without backing this out.

mrmr1993 added a commit that referenced this pull request Dec 4, 2023
…-id-zero-row"

This reverts commit 7f6eba0, reversing
changes made to 88c1776.
mrmr1993 added a commit that referenced this pull request Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants