Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
[proof-chunk] check rwtable fingerprint equality in last chunk (#1674)
Browse files Browse the repository at this point in the history
### Description

Depends on #1641 with extra commit: adding fingerprint equality check on
chronological/by address rw_table
Fingerprint check gate will be enable in last chunk last row

### instance columns, top down order match instance array order

chunk ctx
- [current chunk index, total chunk, initial rwc] // equal with
chunk_{i-1}
- [next chunk index, total chunk, next rwc] equal with chunk_{i+1}

pi circuit
- [pi digest lo, pi digest hi] // same across all chunks

state circuit
- [prev permutation fingerprint] // equal with chunk_{i-1}
- [next permutation fingerprint] // equal with chunk_{i+1}
- [alpha, gamma] // same across all chunks

evm circuit
- [prev permutation fingerprint] // equal with chunk_{i-1}
- [next permutation fingerprint] // equal with chunk_{i+1}
- [alpha, gamma] // same across all chunks

### Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update
  • Loading branch information
hero78119 authored Nov 13, 2023
1 parent f5db508 commit 29189a6
Show file tree
Hide file tree
Showing 10 changed files with 423 additions and 248 deletions.
31 changes: 24 additions & 7 deletions gadgets/src/permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
//! power of gamma are defined in columns to trade more columns with less degrees
use std::iter;
#[rustfmt::skip]
// | q_row_non_first | q_row_enable | alpha | gamma | gamma power 2 | ... | row fingerprint | accmulated fingerprint |
// |-----------------|--------------|-----------|-----------|-----------------| | --------------- | ---------------------- |
// | 0 |1 |alpha | gamma | gamma **2 | ... | F | F |
// | 1 |1 |alpha | gamma | gamma **2 | ... | F | F |
// | 1 |1 |alpha | gamma | gamma **2 | ... | F | F |
// | q_row_non_first | q_row_enable | q_row_last | alpha | gamma | gamma power 2 | ... | row fingerprint | accmulated fingerprint |
// |-----------------|--------------|------------|-----------|-----------|-----------------| | --------------- | ---------------------- |
// | 0 |1 |0 |alpha | gamma | gamma **2 | ... | F | F |
// | 1 |1 |0 |alpha | gamma | gamma **2 | ... | F | F |
// | 1 |1 |1 |alpha | gamma | gamma **2 | ... | F | F |

use std::marker::PhantomData;

Expand All @@ -23,16 +23,20 @@ use itertools::Itertools;
/// Config for PermutationChipConfig
#[derive(Clone, Debug)]
pub struct PermutationChipConfig<F> {
// column
acc_fingerprints: Column<Advice>,
/// acc_fingerprints
pub acc_fingerprints: Column<Advice>,
row_fingerprints: Column<Advice>,
alpha: Column<Advice>,
power_of_gamma: Vec<Column<Advice>>,
// selector
q_row_non_first: Selector, // 1 between (first, end], exclude first
q_row_enable: Selector, // 1 for all rows (including first)
/// q_row_last
pub q_row_last: Selector, // 1 in the last row

_phantom: PhantomData<F>,

acc_fingerprints_cur_expr: Expression<F>,
}

/// (alpha, gamma, prev_acc_fingerprints, next_acc_fingerprints)
Expand Down Expand Up @@ -122,6 +126,7 @@ impl<F: Field> PermutationChipConfig<F> {
// last offset
if offset == fingerprints.len() - 1 {
last_fingerprint_cell = Some(row_acc_fingerprint_cell);
self.q_row_last.enable(region, offset)?;
}
}

Expand Down Expand Up @@ -159,6 +164,11 @@ impl<F: Field> PermutationChipConfig<F> {
}))
.for_each(|(col, ann)| region.name_column(|| format!("{}_{}", prefix, ann), col));
}

/// acc_fingerprints_cur_expr
pub fn acc_fingerprints_cur_expr(&self) -> Expression<F> {
self.acc_fingerprints_cur_expr.clone()
}
}

/// permutation fingerprint gadget
Expand All @@ -185,11 +195,14 @@ impl<F: Field> PermutationChip<F> {

let q_row_non_first = meta.selector();
let q_row_enable = meta.selector();
let q_row_last = meta.selector();

meta.enable_equality(acc_fingerprints);
meta.enable_equality(alpha);
meta.enable_equality(power_of_gamma[0]);

let mut acc_fingerprints_cur_expr: Expression<F> = 0.expr();

meta.create_gate(
"acc_fingerprints_cur = acc_fingerprints_prev * row_fingerprints_cur",
|meta| {
Expand All @@ -198,6 +211,8 @@ impl<F: Field> PermutationChip<F> {
let acc_fingerprints_cur = meta.query_advice(acc_fingerprints, Rotation::cur());
let row_fingerprints_cur = meta.query_advice(row_fingerprints, Rotation::cur());

acc_fingerprints_cur_expr = acc_fingerprints_cur.clone();

[q_row_non_first
* (acc_fingerprints_cur - acc_fingerprints_prev * row_fingerprints_cur)]
},
Expand Down Expand Up @@ -266,9 +281,11 @@ impl<F: Field> PermutationChip<F> {

PermutationChipConfig {
acc_fingerprints,
acc_fingerprints_cur_expr,
row_fingerprints,
q_row_non_first,
q_row_enable,
q_row_last,
alpha,
power_of_gamma,
_phantom: PhantomData::<F> {},
Expand Down
Loading

0 comments on commit 29189a6

Please sign in to comment.