forked from powdr-labs/powdr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add variant of
fingerprint()
that yields intermediate columns (powd…
…r-labs#2072) Depends on powdr-labs#2151. This PR solves all performance issues with `std::fingerprint`. It now has two functions: - `fingerprint()`: Is similar to a pre-powdr-labs#1985 version of `fingerprint()`. It computes the fingerprint in a recursive way. It should *not* be used to generate expressions, because they would be exponentially large. To prevent that, I changed the type so that it can only be applied to `fe`. - `fingerprint_inter()`: Is the analog for expressions. It stores intermediate results in intermediate columns. Because of that, it needs to be a `constr` function. It generates $O(n)$ intermediate columns of constant size. I also added a test for the `fingerprint_inter` function and changed all protocols (bus, permutation, lookup) to use `fingerprint_inter` to generate constraints.
- Loading branch information
1 parent
0d67ef1
commit 3813a4a
Showing
7 changed files
with
116 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::math::fp2::from_base; | ||
use std::math::fp2::Fp2; | ||
use std::math::fp2::eval_ext; | ||
use std::math::fp2::unpack_ext_array; | ||
use std::math::fp2::constrain_eq_ext; | ||
use std::prover::challenge; | ||
use std::protocols::fingerprint::fingerprint; | ||
use std::protocols::fingerprint::fingerprint_inter; | ||
use std::array; | ||
use std::convert::expr; | ||
use std::prover::eval; | ||
|
||
machine Main with degree: 2048 { | ||
|
||
col witness x(i) query Query::Hint(42); | ||
|
||
// Fold tuple [x, x + 1, ..., x + n - 1] | ||
// Note that, by setting a fairly large `n`, we test that performance is not exponential in `n`. | ||
let n = 100; | ||
let tuple = array::new(n, |i| x + 1); | ||
|
||
// Add `fingerprint_value` witness columns and constrain them using `fingerprint_inter` | ||
col witness stage(1) fingerprint_value0, fingerprint_value1; | ||
let fingerprint_value = Fp2::Fp2(fingerprint_value0, fingerprint_value1); | ||
let alpha = Fp2::Fp2(challenge(0, 0), challenge(0, 1)); | ||
constrain_eq_ext(fingerprint_inter(tuple, alpha), fingerprint_value); | ||
|
||
// Add `fingerprint_value_hint` witness columns and compute the fingerprint in a hint using `fingerprint` | ||
let fingerprint_hint: -> fe[] = query || { | ||
let tuple_eval = array::new(array::len(tuple), |i| eval(tuple[i])); | ||
unpack_ext_array(fingerprint(tuple_eval, alpha)) | ||
}; | ||
|
||
col witness stage(1) fingerprint_value0_hint(i) query Query::Hint(fingerprint_hint()[0]); | ||
col witness stage(1) fingerprint_value1_hint(i) query Query::Hint(fingerprint_hint()[1]); | ||
|
||
// Assert consistency between `fingerprint` and `fingerprint_inter` | ||
fingerprint_value0 = fingerprint_value0_hint; | ||
fingerprint_value1 = fingerprint_value1_hint; | ||
|
||
} |