mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-04 06:43:07 +00:00
Allow multiple extra_looking_sums for the same looked table (#1591)
This commit is contained in:
parent
8030ea43ff
commit
42e048f45d
@ -35,6 +35,7 @@ use core::fmt::Debug;
|
|||||||
use core::iter::once;
|
use core::iter::once;
|
||||||
|
|
||||||
use anyhow::{ensure, Result};
|
use anyhow::{ensure, Result};
|
||||||
|
use hashbrown::HashMap;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use plonky2::field::extension::{Extendable, FieldExtension};
|
use plonky2::field::extension::{Extendable, FieldExtension};
|
||||||
use plonky2::field::packed::PackedField;
|
use plonky2::field::packed::PackedField;
|
||||||
@ -920,10 +921,11 @@ pub(crate) fn eval_cross_table_lookup_checks_circuit<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Verifies all cross-table lookups.
|
/// Verifies all cross-table lookups.
|
||||||
|
/// The key of `ctl_extra_looking_sums` is the corresponding CTL's position within `cross_table_lookups`.
|
||||||
pub fn verify_cross_table_lookups<F: RichField + Extendable<D>, const D: usize, const N: usize>(
|
pub fn verify_cross_table_lookups<F: RichField + Extendable<D>, const D: usize, const N: usize>(
|
||||||
cross_table_lookups: &[CrossTableLookup<F>],
|
cross_table_lookups: &[CrossTableLookup<F>],
|
||||||
ctl_zs_first: [Vec<F>; N],
|
ctl_zs_first: [Vec<F>; N],
|
||||||
ctl_extra_looking_sums: Option<&[Vec<F>]>,
|
ctl_extra_looking_sums: &HashMap<usize, Vec<F>>,
|
||||||
config: &StarkConfig,
|
config: &StarkConfig,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut ctl_zs_openings = ctl_zs_first.iter().map(|v| v.iter()).collect::<Vec<_>>();
|
let mut ctl_zs_openings = ctl_zs_first.iter().map(|v| v.iter()).collect::<Vec<_>>();
|
||||||
@ -935,6 +937,7 @@ pub fn verify_cross_table_lookups<F: RichField + Extendable<D>, const D: usize,
|
|||||||
},
|
},
|
||||||
) in cross_table_lookups.iter().enumerate()
|
) in cross_table_lookups.iter().enumerate()
|
||||||
{
|
{
|
||||||
|
let ctl_extra_looking_sum = ctl_extra_looking_sums.get(&index);
|
||||||
// We want to iterate on each looking table only once.
|
// We want to iterate on each looking table only once.
|
||||||
let mut filtered_looking_tables = vec![];
|
let mut filtered_looking_tables = vec![];
|
||||||
for table in looking_tables {
|
for table in looking_tables {
|
||||||
@ -950,8 +953,7 @@ pub fn verify_cross_table_lookups<F: RichField + Extendable<D>, const D: usize,
|
|||||||
.map(|&table| *ctl_zs_openings[table].next().unwrap())
|
.map(|&table| *ctl_zs_openings[table].next().unwrap())
|
||||||
.sum::<F>()
|
.sum::<F>()
|
||||||
// Get elements looking into `looked_table` that are not associated to any STARK.
|
// Get elements looking into `looked_table` that are not associated to any STARK.
|
||||||
+ ctl_extra_looking_sums
|
+ ctl_extra_looking_sum.map(|v| v[c]).unwrap_or_default();
|
||||||
.map(|v| v[looked_table.table][c]).unwrap_or_default();
|
|
||||||
|
|
||||||
// Get the looked table CTL polynomial opening.
|
// Get the looked table CTL polynomial opening.
|
||||||
let looked_z = *ctl_zs_openings[looked_table.table].next().unwrap();
|
let looked_z = *ctl_zs_openings[looked_table.table].next().unwrap();
|
||||||
@ -969,6 +971,7 @@ pub fn verify_cross_table_lookups<F: RichField + Extendable<D>, const D: usize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Circuit version of `verify_cross_table_lookups`. Verifies all cross-table lookups.
|
/// Circuit version of `verify_cross_table_lookups`. Verifies all cross-table lookups.
|
||||||
|
/// The key of `ctl_extra_looking_sums` is the corresponding CTL's position within `cross_table_lookups`.
|
||||||
pub fn verify_cross_table_lookups_circuit<
|
pub fn verify_cross_table_lookups_circuit<
|
||||||
F: RichField + Extendable<D>,
|
F: RichField + Extendable<D>,
|
||||||
const D: usize,
|
const D: usize,
|
||||||
@ -977,15 +980,19 @@ pub fn verify_cross_table_lookups_circuit<
|
|||||||
builder: &mut CircuitBuilder<F, D>,
|
builder: &mut CircuitBuilder<F, D>,
|
||||||
cross_table_lookups: Vec<CrossTableLookup<F>>,
|
cross_table_lookups: Vec<CrossTableLookup<F>>,
|
||||||
ctl_zs_first: [Vec<Target>; N],
|
ctl_zs_first: [Vec<Target>; N],
|
||||||
ctl_extra_looking_sums: Option<&[Vec<Target>]>,
|
ctl_extra_looking_sums: &HashMap<usize, Vec<Target>>,
|
||||||
inner_config: &StarkConfig,
|
inner_config: &StarkConfig,
|
||||||
) {
|
) {
|
||||||
let mut ctl_zs_openings = ctl_zs_first.iter().map(|v| v.iter()).collect::<Vec<_>>();
|
let mut ctl_zs_openings = ctl_zs_first.iter().map(|v| v.iter()).collect::<Vec<_>>();
|
||||||
for CrossTableLookup {
|
for (
|
||||||
looking_tables,
|
index,
|
||||||
looked_table,
|
CrossTableLookup {
|
||||||
} in cross_table_lookups.into_iter()
|
looking_tables,
|
||||||
|
looked_table,
|
||||||
|
},
|
||||||
|
) in cross_table_lookups.into_iter().enumerate()
|
||||||
{
|
{
|
||||||
|
let ctl_extra_looking_sum = ctl_extra_looking_sums.get(&index);
|
||||||
// We want to iterate on each looking table only once.
|
// We want to iterate on each looking table only once.
|
||||||
let mut filtered_looking_tables = vec![];
|
let mut filtered_looking_tables = vec![];
|
||||||
for table in looking_tables {
|
for table in looking_tables {
|
||||||
@ -1002,9 +1009,7 @@ pub fn verify_cross_table_lookups_circuit<
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Get elements looking into `looked_table` that are not associated to any STARK.
|
// Get elements looking into `looked_table` that are not associated to any STARK.
|
||||||
let extra_sum = ctl_extra_looking_sums
|
let extra_sum = ctl_extra_looking_sum.map(|v| v[c]).unwrap_or_default();
|
||||||
.map(|v| v[looked_table.table][c])
|
|
||||||
.unwrap_or_default();
|
|
||||||
looking_zs_sum = builder.add(looking_zs_sum, extra_sum);
|
looking_zs_sum = builder.add(looking_zs_sum, extra_sum);
|
||||||
|
|
||||||
// Get the looked table CTL polynomial opening.
|
// Get the looked table CTL polynomial opening.
|
||||||
@ -1033,10 +1038,11 @@ pub mod debug_utils {
|
|||||||
type MultiSet<F> = HashMap<Vec<F>, Vec<(TableIdx, usize)>>;
|
type MultiSet<F> = HashMap<Vec<F>, Vec<(TableIdx, usize)>>;
|
||||||
|
|
||||||
/// Check that the provided traces and cross-table lookups are consistent.
|
/// Check that the provided traces and cross-table lookups are consistent.
|
||||||
|
/// The key of `extra_looking_values` is the corresponding CTL's position within `cross_table_lookups`.
|
||||||
pub fn check_ctls<F: Field>(
|
pub fn check_ctls<F: Field>(
|
||||||
trace_poly_values: &[Vec<PolynomialValues<F>>],
|
trace_poly_values: &[Vec<PolynomialValues<F>>],
|
||||||
cross_table_lookups: &[CrossTableLookup<F>],
|
cross_table_lookups: &[CrossTableLookup<F>],
|
||||||
extra_looking_values: &HashMap<TableIdx, Vec<Vec<F>>>,
|
extra_looking_values: &HashMap<usize, Vec<Vec<F>>>,
|
||||||
) {
|
) {
|
||||||
for (i, ctl) in cross_table_lookups.iter().enumerate() {
|
for (i, ctl) in cross_table_lookups.iter().enumerate() {
|
||||||
check_ctl(trace_poly_values, ctl, i, extra_looking_values.get(&i));
|
check_ctl(trace_poly_values, ctl, i, extra_looking_values.get(&i));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user