implement lookup arguments from logarithmic derivatives in pil (#1477)

This PR solves #1374

There are 3 examples included in the PR:

1. `lookup_via_challenges_ext_simple.asm` is the most basic example
which implements {a} in {b} using extension field without using
selectors
2. `lookup_via_challenges_ext_no_selector.asm` implements {a1, a2} in
{b1, b2} using extension field without using selectors
3. `lookup_via_challenges_ext.asm` is a more complex example than others
which implements {a1, a2, a3} in {b1, b2, b3} using extension field
(which also handles tuples using Reed-Solomon fingerprinting). It also
use different lhs and rhs selectors.

---------

Co-authored-by: Georg Wiese <georgwiese@gmail.com>
This commit is contained in:
onurinanc
2024-06-30 16:04:15 +03:00
committed by GitHub
parent 9da261105b
commit 9cce7ea4f9
6 changed files with 288 additions and 1 deletions

View File

@@ -0,0 +1,27 @@
use std::prover::Query;
use std::convert::fe;
use std::protocols::lookup::lookup;
machine Main with degree: 8 {
col fixed random_six = [1, 1, 1, 0, 1, 1, 1, 0];
col fixed first_seven = [1, 1, 1, 1, 1, 1, 1, 0];
col fixed a1 = [1, 2, 4, 3, 1, 1, 4, 1];
col fixed a2 = [1, 2, 4, 1, 1, 1, 4, 1];
col fixed a3 = [1, 2, 4, 1, 1, 1, 4, 3];
col witness b1(i) query Query::Hint(fe(i+1));
col witness b2(i) query Query::Hint(fe(i+1));
col witness b3(i) query Query::Hint(fe(i+1));
col fixed m = [3, 1, 0, 2, 0, 0, 0, 0];
let lookup_constraint = Constr::Lookup(
(Option::Some(random_six), Option::Some(first_seven)),
[(a1, b1), (a2, b2), (a3, b3)]
);
// TODO: Functions currently cannot add witness columns at later stages,
// so we have to manually create it here and pass it to permutation().
col witness stage(1) z;
lookup([z], lookup_constraint, m);
}

View File

@@ -0,0 +1,38 @@
use std::prover::Query;
use std::convert::fe;
use std::protocols::lookup::lookup;
use std::protocols::lookup::compute_next_z;
use std::math::fp2::Fp2;
machine Main with degree: 8 {
col fixed a_sel = [0, 1, 1, 1, 0, 1, 0, 0];
col fixed b_sel = [1, 1, 0, 1, 1, 1, 1, 0];
col fixed a1 = [16, 20, 22, 17, 16, 20, 4, 1];
col fixed a2 = [12, 5, 7, 2, 5, 5, 4, 1];
col fixed a3 = [20, 36, 38, 33, 36, 36, 4, 3];
col witness b1(i) query Query::Hint(fe(i+16));
col witness b2(i) query Query::Hint(fe(i+1));
col witness b3(i) query Query::Hint(fe(i+32));
col fixed m = [0, 1, 0, 0, 2, 0, 1, 0];
let lookup_constraint = Constr::Lookup(
(Option::Some(a_sel), Option::Some(b_sel)),
[(a1, b1), (a2, b2), (a3, b3)]
);
// TODO: Functions currently cannot add witness columns at later stages,
// so we have to manually create it here and pass it to lookup().
col witness stage(1) z1;
col witness stage(1) z2;
lookup([z1, z2], lookup_constraint, m);
// TODO: Helper columns, because we can't access the previous row in hints
let hint = query |i| Query::Hint(compute_next_z(Fp2::Fp2(z1, z2), lookup_constraint, m)[i]);
col witness stage(1) z1_next(i) query hint(0);
col witness stage(1) z2_next(i) query hint(1);
z1' = z1_next;
z2' = z2_next;
}

View File

@@ -0,0 +1,31 @@
use std::prover::Query;
use std::convert::fe;
use std::protocols::lookup::lookup;
use std::protocols::lookup::compute_next_z;
use std::math::fp2::Fp2;
machine Main with degree: 8 {
col fixed a = [1, 1, 4, 1, 1, 2, 1, 1];
col witness b(i) query Query::Hint(fe(i+1));
col fixed m = [6, 1, 0, 1, 0, 0, 0, 0];
let lookup_constraint = Constr::Lookup(
(Option::None, Option::None),
[(a, b)]
);
// TODO: Functions currently cannot add witness columns at later stages,
// so we have to manually create it here and pass it to lookup().
col witness stage(1) z1;
col witness stage(1) z2;
lookup([z1, z2], lookup_constraint, m);
// TODO: Helper columns, because we can't access the previous row in hints
let hint = query |i| Query::Hint(compute_next_z(Fp2::Fp2(z1, z2), lookup_constraint, m)[i]);
col witness stage(1) z1_next(i) query hint(0);
col witness stage(1) z2_next(i) query hint(1);
z1' = z1_next;
z2' = z2_next;
}