Skip to content

Commit 95b6b7a

Browse files
committed
Merge branch 'main' into cleaning
2 parents c350e95 + 011b1f9 commit 95b6b7a

File tree

7 files changed

+106
-11
lines changed

7 files changed

+106
-11
lines changed

Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "lean-multisig"
2+
name = "modular-precompiles"
33
version.workspace = true
44
edition.workspace = true
55

crates/lean_prover/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const TWO_POW_UNIVARIATE_SKIPS: usize = 1 << UNIVARIATE_SKIPS;
1616

1717
pub const LOG_SMALLEST_DECOMPOSITION_CHUNK: usize = 12; // TODO optimize
1818

19+
const DOT_PRODUCT_UNIVARIATE_SKIPS: usize = 1;
20+
const TWO_POW_DOT_PRODUCT_UNIVARIATE_SKIPS: usize = 1 << DOT_PRODUCT_UNIVARIATE_SKIPS;
21+
1922
pub fn whir_config_builder() -> WhirConfigBuilder {
2023
WhirConfigBuilder {
2124
folding_factor: FoldingFactor::new(7, 4),

crates/lean_prover/src/prove_execution.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::array;
2+
13
use crate::common::*;
24
use crate::*;
35
use air::prove_air;
@@ -8,7 +10,6 @@ use multilinear_toolkit::prelude::*;
810
use p3_air::Air;
911
use p3_util::{log2_ceil_usize, log2_strict_usize};
1012
use poseidon_circuit::{PoseidonGKRLayers, prove_poseidon_gkr};
11-
use std::array;
1213
use sub_protocols::*;
1314
use tracing::info_span;
1415
use utils::{build_prover_state, padd_with_zero_to_next_power_of_two};
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
use lean_vm::{DIMENSION, EF, WitnessDotProduct};
2+
use multilinear_toolkit::prelude::*;
3+
4+
pub fn build_dot_product_columns(
5+
witness: &[WitnessDotProduct],
6+
min_n_rows: usize,
7+
) -> (Vec<Vec<EF>>, usize) {
8+
let (
9+
mut flag,
10+
mut len,
11+
mut index_a,
12+
mut index_b,
13+
mut index_res,
14+
mut value_a,
15+
mut value_b,
16+
mut res,
17+
mut computation,
18+
) = (
19+
Vec::new(),
20+
Vec::new(),
21+
Vec::new(),
22+
Vec::new(),
23+
Vec::new(),
24+
Vec::new(),
25+
Vec::new(),
26+
Vec::new(),
27+
Vec::new(),
28+
);
29+
for dot_product in witness {
30+
assert!(dot_product.len > 0);
31+
32+
// computation
33+
{
34+
computation.extend(EF::zero_vec(dot_product.len));
35+
let new_size = computation.len();
36+
computation[new_size - 1] =
37+
dot_product.slice_0[dot_product.len - 1] * dot_product.slice_1[dot_product.len - 1];
38+
for i in 0..dot_product.len - 1 {
39+
computation[new_size - 2 - i] = computation[new_size - 1 - i]
40+
+ dot_product.slice_0[dot_product.len - 2 - i]
41+
* dot_product.slice_1[dot_product.len - 2 - i];
42+
}
43+
}
44+
45+
flag.push(EF::ONE);
46+
flag.extend(EF::zero_vec(dot_product.len - 1));
47+
len.extend(((1..=dot_product.len).rev()).map(EF::from_usize));
48+
index_a.extend(
49+
(0..dot_product.len).map(|i| EF::from_usize(dot_product.addr_0 + i * DIMENSION)),
50+
);
51+
index_b.extend(
52+
(0..dot_product.len).map(|i| EF::from_usize(dot_product.addr_1 + i * DIMENSION)),
53+
);
54+
index_res.extend(vec![EF::from_usize(dot_product.addr_res); dot_product.len]);
55+
value_a.extend(dot_product.slice_0.clone());
56+
value_b.extend(dot_product.slice_1.clone());
57+
res.extend(vec![dot_product.res; dot_product.len]);
58+
}
59+
60+
let padding_len = flag.len().next_power_of_two().max(min_n_rows) - flag.len();
61+
flag.extend(vec![EF::ONE; padding_len]);
62+
len.extend(vec![EF::ONE; padding_len]);
63+
index_a.extend(EF::zero_vec(padding_len));
64+
index_b.extend(EF::zero_vec(padding_len));
65+
index_res.extend(EF::zero_vec(padding_len));
66+
value_a.extend(EF::zero_vec(padding_len));
67+
value_b.extend(EF::zero_vec(padding_len));
68+
res.extend(EF::zero_vec(padding_len));
69+
computation.extend(EF::zero_vec(padding_len));
70+
71+
(
72+
vec![
73+
flag,
74+
len,
75+
index_a,
76+
index_b,
77+
index_res,
78+
value_a,
79+
value_b,
80+
res,
81+
computation,
82+
],
83+
padding_len,
84+
)
85+
}

crates/lean_vm/src/core/constants.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ pub const POSEIDON_24_NULL_HASH_PTR: usize = 5;
4343

4444
/// Normal pointer to start of program input
4545
pub const NONRESERVED_PROGRAM_INPUT_START: usize = 6 * 8;
46+
47+
/// Precompiles Indexes
48+
pub const TABLE_INDEX_POSEIDONS_16: usize = 1; // should be != 0
49+
pub const TABLE_INDEX_POSEIDONS_24: usize = 2;
50+
pub const TABLE_INDEX_DOT_PRODUCTS: usize = 3;
51+
pub const TABLE_INDEX_MULTILINEAR_EVAL: usize = 4;

minimal_zkVM.pdf

6 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)