Skip to content

Commit

Permalink
Zisk working with last proofman version
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerTaule authored and hecmas committed Dec 11, 2024
1 parent e610706 commit 27695e7
Show file tree
Hide file tree
Showing 24 changed files with 184 additions and 250 deletions.
153 changes: 74 additions & 79 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion book/getting_started/quickstart_dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ To generate the aggregated proofs, add `-a`
(cargo build --release && cd ../pil2-proofman; cargo run --release --bin proofman-cli prove --witness-lib ../zisk/target/release/libzisk_witness.so --rom ../zisk/emulator/benches/data/my.elf -i ../zisk/emulator/benches/data/input_two_segments.bin --proving-key ../zisk/build/provingKey --output-dir ../zisk/proofs -d -a -v)

// Using input.bin
(cargo build --release && cd ../pil2-proofman; cargo run --release --bin proofman-cli prove --witness-lib ../zisk/target/release/libzisk_witness.so --rom ../zisk/emulator/benches/data/my.elf -i ../zisk/emulator/benches/data/input.bin --proving-key ../zisk/build/provingKey --output-dir ../zisk/proofs -d -a -v)
(cargo build --release && cd ../pil2-proofman; cargo run --release --bin proofman-cli prove --witness-lib ../zisk/target/release/libzisk_witness.so --rom ../zisk/emulator/benches/data/my.elf -i ../zisk/emulator/benches/data/input.bin --proving-key ../zisk/build/provingKey --output-dir ../zisk/proofs -a -v -f)
```

### Verify the Proof
Expand Down
3 changes: 1 addition & 2 deletions state-machines/arith/src/arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ impl<F: Field> ArithSM<F> {
&self,
operations: Vec<ZiskRequiredOperation>,
prover_buffer: &mut [F],
offset: u64,
) {
self.arith_full_sm.prove_instance(operations, prover_buffer, offset);
self.arith_full_sm.prove_instance(operations, prover_buffer);
}
}

Expand Down
4 changes: 1 addition & 3 deletions state-machines/arith/src/arith_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ impl<F: Field> ArithFullSM<F> {
&self,
input: Vec<ZiskRequiredOperation>,
prover_buffer: &mut [F],
offset: u64,
) {
let mut range_table_inputs = ArithRangeTableInputs::new();
let mut table_inputs = ArithTableInputs::new();
Expand All @@ -83,11 +82,10 @@ impl<F: Field> ArithFullSM<F> {
assert!(input.len() <= num_rows);

let mut traces =
ArithTrace::<F>::map_buffer(prover_buffer, num_rows, offset as usize).unwrap();
ArithTrace::<F>::map_buffer(prover_buffer, num_rows, 0).unwrap();

let mut aop = ArithOperation::new();
for (irow, input) in input.iter().enumerate() {
println!("#{} ARITH op:0x{:X} a:0x{:X} b:0x{:X}", irow, input.opcode, input.a, input.b);
aop.calculate(input.opcode, input.a, input.b);
let mut t: ArithRow<F> = Default::default();
for i in [0, 2] {
Expand Down
22 changes: 8 additions & 14 deletions state-machines/arith/src/arith_range_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use p3_field::Field;
use proofman::{WitnessComponent, WitnessManager};
use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx};
use rayon::prelude::*;
use sm_common::create_prover_buffer;
use zisk_pil::{ARITH_RANGE_TABLE_AIR_IDS, ZISK_AIRGROUP_ID};
use zisk_pil::{ArithRangeTableTrace, ARITH_RANGE_TABLE_AIR_IDS, ZISK_AIRGROUP_ID};

pub struct ArithRangeTableSM<F> {
wcm: Arc<WitnessManager<F>>,
Expand Down Expand Up @@ -49,8 +48,8 @@ impl<F: Field> ArithRangeTableSM<F> {
}

pub fn unregister_predecessor(&self) {
if self.registered_predecessors.fetch_sub(1, Ordering::SeqCst) == 1 &&
self.used.load(Ordering::SeqCst)
if self.registered_predecessors.fetch_sub(1, Ordering::SeqCst) == 1
&& self.used.load(Ordering::SeqCst)
{
self.create_air_instance();
}
Expand Down Expand Up @@ -78,14 +77,9 @@ impl<F: Field> ArithRangeTableSM<F> {
dctx.distribute_multiplicity(&mut multiplicity_, owner);

if is_myne {
// Create the prover buffer
let (mut prover_buffer, offset) = create_prover_buffer(
&self.wcm.get_ectx(),
&self.wcm.get_sctx(),
ZISK_AIRGROUP_ID,
ARITH_RANGE_TABLE_AIR_IDS[0],
);
prover_buffer[offset as usize..offset as usize + self.num_rows]
let trace: ArithRangeTableTrace<'_, _> = ArithRangeTableTrace::new(self.num_rows);
let mut prover_buffer = trace.buffer.unwrap();
prover_buffer[0..self.num_rows]
.par_iter_mut()
.enumerate()
.for_each(|(i, input)| *input = F::from_canonical_u64(multiplicity_[i]));
Expand Down Expand Up @@ -116,8 +110,8 @@ impl<F: Field> WitnessComponent<F> for ArithRangeTableSM<F> {
_stage: u32,
_air_instance: Option<usize>,
_pctx: Arc<ProofCtx<F>>,
_ectx: Arc<ExecutionCtx<F>>,
_sctx: Arc<SetupCtx<F>>,
_ectx: Arc<ExecutionCtx>,
_sctx: Arc<SetupCtx>,
) {
}
}
22 changes: 8 additions & 14 deletions state-machines/arith/src/arith_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use p3_field::Field;
use proofman::{WitnessComponent, WitnessManager};
use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx};
use rayon::prelude::*;
use sm_common::create_prover_buffer;
use zisk_pil::{ARITH_TABLE_AIR_IDS, ZISK_AIRGROUP_ID};
use zisk_pil::{ArithTableTrace, ARITH_TABLE_AIR_IDS, ZISK_AIRGROUP_ID};

pub struct ArithTableSM<F> {
wcm: Arc<WitnessManager<F>>,
Expand Down Expand Up @@ -49,8 +48,8 @@ impl<F: Field> ArithTableSM<F> {
}

pub fn unregister_predecessor(&self) {
if self.registered_predecessors.fetch_sub(1, Ordering::SeqCst) == 1 &&
self.used.load(Ordering::SeqCst)
if self.registered_predecessors.fetch_sub(1, Ordering::SeqCst) == 1
&& self.used.load(Ordering::SeqCst)
{
self.create_air_instance();
}
Expand Down Expand Up @@ -80,14 +79,9 @@ impl<F: Field> ArithTableSM<F> {
dctx.distribute_multiplicity(&mut multiplicity_, owner);

if is_myne {
// Create the prover buffer
let (mut prover_buffer, offset) = create_prover_buffer(
&self.wcm.get_ectx(),
&self.wcm.get_sctx(),
ZISK_AIRGROUP_ID,
ARITH_TABLE_AIR_IDS[0],
);
prover_buffer[offset as usize..offset as usize + self.num_rows]
let trace: ArithTableTrace<'_, _> = ArithTableTrace::new(self.num_rows);
let mut prover_buffer = trace.buffer.unwrap();
prover_buffer[0..self.num_rows]
.par_iter_mut()
.enumerate()
.for_each(|(i, input)| *input = F::from_canonical_u64(multiplicity_[i]));
Expand Down Expand Up @@ -118,8 +112,8 @@ impl<F: Field> WitnessComponent<F> for ArithTableSM<F> {
_stage: u32,
_air_instance: Option<usize>,
_pctx: Arc<ProofCtx<F>>,
_ectx: Arc<ExecutionCtx<F>>,
_sctx: Arc<SetupCtx<F>>,
_ectx: Arc<ExecutionCtx>,
_sctx: Arc<SetupCtx>,
) {
}
}
5 changes: 2 additions & 3 deletions state-machines/binary/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,11 @@ impl<F: PrimeField> BinarySM<F> {
operations: Vec<ZiskRequiredOperation>,
is_extension: bool,
prover_buffer: &mut [F],
offset: u64,
) {
if !is_extension {
self.binary_basic_sm.prove_instance(operations, prover_buffer, offset);
self.binary_basic_sm.prove_instance(operations, prover_buffer);
} else {
self.binary_extension_sm.prove_instance(operations, prover_buffer, offset);
self.binary_extension_sm.prove_instance(operations, prover_buffer);
}
}
}
Expand Down
18 changes: 5 additions & 13 deletions state-machines/binary/src/binary_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use proofman::{WitnessComponent, WitnessManager};
use proofman_common::AirInstance;
use proofman_util::{timer_start_trace, timer_stop_and_log_trace};
use rayon::Scope;
use sm_common::{create_prover_buffer, OpResult, Provable};
use sm_common::{OpResult, Provable};
use std::cmp::Ordering as CmpOrdering;
use zisk_core::{zisk_ops::ZiskOp, ZiskRequiredOperation};
use zisk_pil::*;
Expand Down Expand Up @@ -715,14 +715,12 @@ impl<F: Field> BinaryBasicSM<F> {
&self,
operations: Vec<ZiskRequiredOperation>,
prover_buffer: &mut [F],
offset: u64,
) {
Self::prove_internal(
&self.wcm,
&self.binary_basic_table_sm,
operations,
prover_buffer,
offset,
);
}

Expand All @@ -731,7 +729,6 @@ impl<F: Field> BinaryBasicSM<F> {
binary_basic_table_sm: &BinaryBasicTableSM<F>,
operations: Vec<ZiskRequiredOperation>,
prover_buffer: &mut [F],
offset: u64,
) {
timer_start_trace!(BINARY_TRACE);
let pctx = wcm.get_pctx();
Expand All @@ -749,7 +746,7 @@ impl<F: Field> BinaryBasicSM<F> {

let mut multiplicity_table = vec![0u64; air_binary_table.num_rows()];
let mut trace_buffer =
BinaryTrace::<F>::map_buffer(prover_buffer, air.num_rows(), offset as usize).unwrap();
BinaryTrace::<F>::map_buffer(prover_buffer, air.num_rows(), 0).unwrap();

for (i, operation) in operations.iter().enumerate() {
let row = Self::process_slice(operation, &mut multiplicity_table);
Expand Down Expand Up @@ -818,19 +815,14 @@ impl<F: Field> Provable<ZiskRequiredOperation, OpResult> for BinaryBasicSM<F> {

let sctx = self.wcm.get_sctx().clone();

let (mut prover_buffer, offset) = create_prover_buffer(
&wcm.get_ectx(),
&wcm.get_sctx(),
ZISK_AIRGROUP_ID,
BINARY_AIR_IDS[0],
);

let trace: BinaryTrace<'_, _> = BinaryTrace::new(air.num_rows());
let mut prover_buffer = trace.buffer.unwrap();

Self::prove_internal(
&wcm,
&binary_basic_table_sm,
drained_inputs,
&mut prover_buffer,
offset,
);

let air_instance = AirInstance::new(
Expand Down
14 changes: 5 additions & 9 deletions state-machines/binary/src/binary_basic_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use p3_field::Field;
use proofman::{WitnessComponent, WitnessManager};
use proofman_common::AirInstance;
use rayon::prelude::*;
use sm_common::create_prover_buffer;
use zisk_core::{zisk_ops::ZiskOp, P2_16, P2_17, P2_18, P2_19, P2_8, P2_9};
use zisk_pil::{BINARY_TABLE_AIR_IDS, ZISK_AIRGROUP_ID};
use zisk_pil::{BinaryTableTrace, BINARY_TABLE_AIR_IDS, ZISK_AIRGROUP_ID};

#[derive(Debug, Clone, PartialEq, Copy)]
#[repr(u8)]
Expand Down Expand Up @@ -247,13 +246,10 @@ impl<F: Field> BinaryBasicTableSM<F> {

if is_myne {
// Create the prover buffer
let (mut prover_buffer, offset) = create_prover_buffer(
&self.wcm.get_ectx(),
&self.wcm.get_sctx(),
ZISK_AIRGROUP_ID,
BINARY_TABLE_AIR_IDS[0],
);
prover_buffer[offset as usize..offset as usize + self.num_rows]
let trace: BinaryTableTrace<'_, _> = BinaryTableTrace::new(self.num_rows);
let mut prover_buffer = trace.buffer.unwrap();

prover_buffer[0..self.num_rows]
.par_iter_mut()
.enumerate()
.for_each(|(i, input)| *input = F::from_canonical_u64(multiplicity_[i]));
Expand Down
18 changes: 5 additions & 13 deletions state-machines/binary/src/binary_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use proofman::{WitnessComponent, WitnessManager};
use proofman_common::AirInstance;
use proofman_util::{timer_start_debug, timer_stop_and_log_debug};
use rayon::Scope;
use sm_common::{create_prover_buffer, OpResult, Provable};
use sm_common::{OpResult, Provable};
use zisk_core::{zisk_ops::ZiskOp, ZiskRequiredOperation};
use zisk_pil::*;

Expand Down Expand Up @@ -366,15 +366,13 @@ impl<F: PrimeField> BinaryExtensionSM<F> {
&self,
operations: Vec<ZiskRequiredOperation>,
prover_buffer: &mut [F],
offset: u64,
) {
Self::prove_internal(
&self.wcm,
&self.binary_extension_table_sm,
&self.std,
operations,
prover_buffer,
offset,
);
}

Expand All @@ -384,7 +382,6 @@ impl<F: PrimeField> BinaryExtensionSM<F> {
std: &Std<F>,
operations: Vec<ZiskRequiredOperation>,
prover_buffer: &mut [F],
offset: u64,
) {
timer_start_debug!(BINARY_EXTENSION_TRACE);
let pctx = wcm.get_pctx();
Expand All @@ -405,7 +402,7 @@ impl<F: PrimeField> BinaryExtensionSM<F> {
let mut multiplicity_table = vec![0u64; air_binary_extension_table.num_rows()];
let mut range_check: HashMap<u64, u64> = HashMap::new();
let mut trace_buffer =
BinaryExtensionTrace::<F>::map_buffer(prover_buffer, air.num_rows(), offset as usize)
BinaryExtensionTrace::<F>::map_buffer(prover_buffer, air.num_rows(), 0)
.unwrap();

for (i, operation) in operations.iter().enumerate() {
Expand Down Expand Up @@ -479,20 +476,15 @@ impl<F: PrimeField> Provable<ZiskRequiredOperation, OpResult> for BinaryExtensio

let sctx = self.wcm.get_sctx().clone();

let (mut prover_buffer, offset) = create_prover_buffer(
&wcm.get_ectx(),
&wcm.get_sctx(),
ZISK_AIRGROUP_ID,
BINARY_EXTENSION_AIR_IDS[0],
);

let trace: BinaryExtensionTrace<'_, _> = BinaryExtensionTrace::new(air.num_rows());
let mut prover_buffer = trace.buffer.unwrap();

Self::prove_internal(
&wcm,
&binary_extension_table_sm,
&std,
drained_inputs,
&mut prover_buffer,
offset,
);

let air_instance = AirInstance::new(
Expand Down
14 changes: 4 additions & 10 deletions state-machines/binary/src/binary_extension_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use p3_field::Field;
use proofman::{WitnessComponent, WitnessManager};
use proofman_common::AirInstance;
use rayon::prelude::*;
use sm_common::create_prover_buffer;
use zisk_core::{zisk_ops::ZiskOp, P2_11, P2_19, P2_8};
use zisk_pil::{BINARY_EXTENSION_TABLE_AIR_IDS, ZISK_AIRGROUP_ID};
use zisk_pil::{BinaryExtensionTableTrace, BINARY_EXTENSION_TABLE_AIR_IDS, ZISK_AIRGROUP_ID};

#[derive(Debug, Clone, PartialEq, Copy)]
#[repr(u8)]
Expand Down Expand Up @@ -136,15 +135,10 @@ impl<F: Field> BinaryExtensionTableSM<F> {
dctx.distribute_multiplicity(&mut multiplicity_, owner);

if is_myne {
// Create the prover buffer
let (mut prover_buffer, offset) = create_prover_buffer(
&self.wcm.get_ectx(),
&self.wcm.get_sctx(),
ZISK_AIRGROUP_ID,
BINARY_EXTENSION_TABLE_AIR_IDS[0],
);
let trace: BinaryExtensionTableTrace<'_, _> = BinaryExtensionTableTrace::new(self.num_rows);
let mut prover_buffer = trace.buffer.unwrap();

prover_buffer[offset as usize..offset as usize + self.num_rows]
prover_buffer[0..self.num_rows]
.par_iter_mut()
.enumerate()
.for_each(|(i, input)| *input = F::from_canonical_u64(multiplicity_[i]));
Expand Down
22 changes: 1 addition & 21 deletions state-machines/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,7 @@ mod worker;

pub use field::*;
pub use operations::*;
use proofman_common::{ExecutionCtx, SetupCtx};
use proofman_util::create_buffer_fast;
pub use provable::*;
pub use session::*;
pub use temp::*;
pub use worker::*;

pub fn create_prover_buffer<F>(
ectx: &ExecutionCtx<F>,
sctx: &SetupCtx<F>,
airgroup_id: usize,
air_id: usize,
) -> (Vec<F>, u64) {
// Compute buffer size using the BufferAllocator
let (buffer_size, offsets) = ectx
.buffer_allocator
.as_ref()
.get_buffer_info(sctx, airgroup_id, air_id)
.unwrap_or_else(|err| panic!("Error getting buffer info: {}", err));

let buffer = create_buffer_fast(buffer_size as usize);

(buffer, offsets[0])
}
pub use worker::*;
4 changes: 2 additions & 2 deletions state-machines/freq-ops/src/freq_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ impl<F> WitnessComponent<F> for FreqOpsSM {
_stage: u32,
_air_instance: Option<usize>,
_pctx: Arc<ProofCtx<F>>,
_ectx: Arc<ExecutionCtx<F>>,
_sctx: Arc<SetupCtx<F>>,
_ectx: Arc<ExecutionCtx>,
_sctx: Arc<SetupCtx>,
) {
}
}
Expand Down
4 changes: 2 additions & 2 deletions state-machines/main/pil/main.pil
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,6 @@ airtemplate Main(int N = 2**21, int RC = 2, int stack_enabled = 0, const int ope
lookup_assumes(ROM_BUS_ID, [pc, a_offset_imm0, a_imm1, b_offset_imm0, b_imm1, ind_width,
op, store_offset, jmp_offset1, jmp_offset2, rom_flags], sel: 1 - SEGMENT_L1);

direct_update(MAIN_CONTINUATION_ID, cols: [0, 0, 4096, 0, 0], bus_type: PIOP_BUS_SUM, proves: 1);
direct_update(MAIN_CONTINUATION_ID, cols: [0, 1, 0x10000000, 0, 0], bus_type: PIOP_BUS_SUM, proves: 0);
direct_global_update(MAIN_CONTINUATION_ID, cols: [0, 0, 4096, 0, 0], bus_type: PIOP_BUS_SUM, proves: 1);
direct_global_update(MAIN_CONTINUATION_ID, cols: [0, 1, 0x10000000, 0, 0], bus_type: PIOP_BUS_SUM, proves: 0);
}
Loading

0 comments on commit 27695e7

Please sign in to comment.