Skip to content

Commit 102bd1f

Browse files
authored
Pick #8 (#17)
* wip * wip2 * wip3 * wip4 * wip5 * replace variable position by name * wip6 * wip7 * clippy * wip8 * wip9 * wip10 * wip11 * wip12 * wip13 * wip14 * wip15 * clippy
1 parent d73de3e commit 102bd1f

File tree

22 files changed

+2292
-39
lines changed

22 files changed

+2292
-39
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Cargo.lock
99
**/.env
1010
.DS_Store
1111

12+
# Log outputs
13+
*.log
14+
1215
.cache/
1316
rustc-*
1417

crates/sdk/src/prover/agg.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ where
2727
E: StarkFriEngine<SC = SC>,
2828
NativeBuilder: VmBuilder<E, VmConfig = NativeConfig>,
2929
{
30-
leaf_prover: VmInstance<E, NativeBuilder>,
31-
leaf_controller: LeafProvingController,
30+
pub leaf_prover: VmInstance<E, NativeBuilder>,
31+
pub leaf_controller: LeafProvingController,
3232

3333
pub internal_prover: VmInstance<E, NativeBuilder>,
3434
#[cfg(feature = "evm-prove")]
35-
root_prover: RootVerifierLocalProver,
35+
pub root_prover: RootVerifierLocalProver,
3636
pub num_children_internal: usize,
3737
pub max_internal_wrapper_layers: usize,
3838
}

extensions/native/circuit/src/extension/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use openvm_instructions::{program::DEFAULT_PC_STEP, LocalOpcode, PhantomDiscrimi
1717
use openvm_native_compiler::{
1818
CastfOpcode, FieldArithmeticOpcode, FieldExtensionOpcode, FriOpcode, NativeBranchEqualOpcode,
1919
NativeJalOpcode, NativeLoadStore4Opcode, NativeLoadStoreOpcode, NativePhantom,
20-
NativeRangeCheckOpcode, Poseidon2Opcode, VerifyBatchOpcode, BLOCK_LOAD_STORE_SIZE,
20+
NativeRangeCheckOpcode, Poseidon2Opcode, SumcheckOpcode, VerifyBatchOpcode,
21+
BLOCK_LOAD_STORE_SIZE,
2122
};
2223
use openvm_poseidon2_air::Poseidon2Config;
2324
use openvm_rv32im_circuit::BranchEqualCoreAir;
@@ -61,6 +62,10 @@ use crate::{
6162
chip::{NativePoseidon2Executor, NativePoseidon2Filler},
6263
NativePoseidon2Chip,
6364
},
65+
sumcheck::{
66+
air::NativeSumcheckAir,
67+
chip::{NativeSumcheckChip, NativeSumcheckExecutor, NativeSumcheckFiller},
68+
},
6469
};
6570

6671
cfg_if::cfg_if! {
@@ -94,6 +99,7 @@ pub enum NativeExecutor<F: Field> {
9499
FieldExtension(FieldExtensionExecutor),
95100
FriReducedOpening(FriReducedOpeningExecutor),
96101
VerifyBatch(NativePoseidon2Executor<F, 1>),
102+
TowerVerify(NativeSumcheckExecutor),
97103
}
98104

99105
impl<F: PrimeField32> VmExecutionExtension<F> for Native {
@@ -169,6 +175,12 @@ impl<F: PrimeField32> VmExecutionExtension<F> for Native {
169175
],
170176
)?;
171177

178+
let tower_verify = NativeSumcheckExecutor::new();
179+
inventory.add_executor(
180+
tower_verify,
181+
[SumcheckOpcode::SUMCHECK_LAYER_EVAL.global_opcode()],
182+
)?;
183+
172184
inventory.add_phantom_sub_executor(
173185
NativeHintInputSubEx,
174186
PhantomDiscriminant(NativePhantom::HintInput as u16),
@@ -262,6 +274,9 @@ where
262274
);
263275
inventory.add_air(verify_batch);
264276

277+
let tower_evaluate = NativeSumcheckAir::new(exec_bridge, memory_bridge);
278+
inventory.add_air(tower_evaluate);
279+
265280
Ok(())
266281
}
267282
}
@@ -342,6 +357,9 @@ where
342357
);
343358
inventory.add_executor_chip(poseidon2);
344359

360+
let tower_verify = NativeSumcheckChip::new(NativeSumcheckFiller::new(), mem_helper.clone());
361+
inventory.add_executor_chip(tower_verify);
362+
345363
Ok(())
346364
}
347365
}

extensions/native/circuit/src/field_extension/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ pub(crate) struct FieldExtension;
254254
impl FieldExtension {
255255
pub(crate) fn add<V, E>(x: [V; EXT_DEG], y: [V; EXT_DEG]) -> [E; EXT_DEG]
256256
where
257-
V: Copy,
257+
V: Clone,
258258
V: Add<V, Output = E>,
259259
{
260-
array::from_fn(|i| x[i] + y[i])
260+
array::from_fn(|i| x[i].clone() + y[i].clone())
261261
}
262262

263263
pub(crate) fn subtract<V, E>(x: [V; EXT_DEG], y: [V; EXT_DEG]) -> [E; EXT_DEG]

extensions/native/circuit/src/fri/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ fn assert_array_eq<AB: AirBuilder, I1: Into<AB::Expr>, I2: Into<AB::Expr>, const
542542
}
543543
}
544544

545-
fn elem_to_ext<F: Field>(elem: F) -> [F; EXT_DEG] {
545+
pub fn elem_to_ext<F: Field>(elem: F) -> [F; EXT_DEG] {
546546
let mut ret = [F::ZERO; EXT_DEG];
547547
ret[0] = elem;
548548
ret

extensions/native/circuit/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ mod fri;
4242
mod jal_rangecheck;
4343
mod loadstore;
4444
mod poseidon2;
45+
mod sumcheck;
4546

4647
mod extension;
4748
pub use extension::*;
49+
pub use field_extension::EXT_DEG;
4850

4951
mod utils;
5052
#[cfg(any(test, feature = "test-utils"))]

extensions/native/circuit/src/poseidon2/chip.rs

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ use std::borrow::{Borrow, BorrowMut};
33
use openvm_circuit::{
44
arch::*,
55
system::{
6-
memory::{offline_checker::MemoryBaseAuxCols, online::TracingMemory, MemoryAuxColsFactory},
7-
native_adapter::util::{
8-
memory_read_native, tracing_read_native, tracing_write_native_inplace,
9-
},
6+
memory::{online::TracingMemory, MemoryAuxColsFactory},
7+
native_adapter::util::{memory_read_native, tracing_write_native_inplace},
108
},
119
};
1210
use openvm_instructions::{instruction::Instruction, program::DEFAULT_PC_STEP, LocalOpcode};
@@ -23,12 +21,16 @@ use openvm_stark_backend::{
2321
p3_maybe_rayon::prelude::{IntoParallelIterator, ParallelSliceMut, *},
2422
};
2523

26-
use crate::poseidon2::{
27-
columns::{
28-
InsideRowSpecificCols, MultiObserveCols, NativePoseidon2Cols, SimplePoseidonSpecificCols,
29-
TopLevelSpecificCols,
24+
use crate::{
25+
mem_fill_helper,
26+
poseidon2::{
27+
columns::{
28+
InsideRowSpecificCols, MultiObserveCols, NativePoseidon2Cols,
29+
SimplePoseidonSpecificCols, TopLevelSpecificCols,
30+
},
31+
CHUNK,
3032
},
31-
CHUNK,
33+
tracing_read_native_helper,
3234
};
3335

3436
#[derive(Clone)]
@@ -1240,24 +1242,3 @@ impl<F: PrimeField32, const SBOX_REGISTERS: usize> NativePoseidon2Filler<F, SBOX
12401242
&inner.ending_full_rounds.last().unwrap().post
12411243
}
12421244
}
1243-
1244-
fn tracing_read_native_helper<F: PrimeField32, const BLOCK_SIZE: usize>(
1245-
memory: &mut TracingMemory,
1246-
ptr: u32,
1247-
base_aux: &mut MemoryBaseAuxCols<F>,
1248-
) -> [F; BLOCK_SIZE] {
1249-
let mut prev_ts = 0;
1250-
let ret = tracing_read_native(memory, ptr, &mut prev_ts);
1251-
base_aux.set_prev(F::from_canonical_u32(prev_ts));
1252-
ret
1253-
}
1254-
1255-
/// Fill `MemoryBaseAuxCols`, assuming that the `prev_timestamp` is already set in `base_aux`.
1256-
fn mem_fill_helper<F: PrimeField32>(
1257-
mem_helper: &MemoryAuxColsFactory<F>,
1258-
timestamp: u32,
1259-
base_aux: &mut MemoryBaseAuxCols<F>,
1260-
) {
1261-
let prev_ts = base_aux.prev_timestamp.as_canonical_u32();
1262-
mem_helper.fill(prev_ts, timestamp, base_aux);
1263-
}

0 commit comments

Comments
 (0)