Skip to content

Commit

Permalink
adapted to pil2-proofman feature/minor_clean pil2-proofman PR#132
Browse files Browse the repository at this point in the history
  • Loading branch information
xavi-pinsach committed Dec 10, 2024
1 parent 65422a1 commit 661e871
Show file tree
Hide file tree
Showing 40 changed files with 289 additions and 482 deletions.
4 changes: 2 additions & 2 deletions emulator/src/emu_full_trace.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use zisk_pil::MainRow;
use zisk_pil::MainTraceRow;

pub type EmuFullTraceStep<F> = MainRow<F>;
pub type EmuFullTraceStep<F> = MainTraceRow<F>;
17 changes: 8 additions & 9 deletions executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
sync::Arc,
};
use zisk_core::ZiskRom;
use zisk_pil::{MAIN_AIR_IDS, ZISK_AIRGROUP_ID};
use zisk_pil::{MainTrace, MAIN_AIR_IDS, ZISK_AIRGROUP_ID};
use ziskemu::{EmuOptions, EmuTrace, ZiskEmulator};

use crate::MetricsProxy;
Expand Down Expand Up @@ -49,7 +49,7 @@ impl<F: PrimeField> ZiskExecutor<F> {
pub fn execute(
&self,
public_inputs_path: &Path,
pctx: Arc<ProofCtx<F>>,
_: Arc<ProofCtx<F>>,
ectx: Arc<ExecutionCtx>,
_: Arc<SetupCtx>,
) {
Expand Down Expand Up @@ -79,12 +79,11 @@ impl<F: PrimeField> ZiskExecutor<F> {
let main_task = {
let main_sm = self.main_sm.clone();
let zisk_rom = self.zisk_rom.clone();
let pctx = pctx.clone();
let minimal_traces = min_traces.clone();

std::thread::spawn(move || {
main_layouts.par_iter_mut().for_each(|main_instance| {
main_sm.prove_main(&zisk_rom, &minimal_traces, main_instance, &pctx);
main_sm.prove_main(&zisk_rom, &minimal_traces, main_instance);
});
main_layouts
})
Expand All @@ -104,7 +103,9 @@ impl<F: PrimeField> ZiskExecutor<F> {
let mut sec_instances = Vec::new();
for (i, plans_by_sm) in plans.iter_mut().enumerate() {
for plan in plans_by_sm.drain(..) {
if let (true, global_idx) = dctx.add_instance(plan.airgroup_id, plan.air_id, 1) {
let (is_mine, global_idx) = dctx.add_instance(plan.airgroup_id, plan.air_id, 1);

if is_mine || plan.instance_type == InstanceType::Table {
let iectx = InstanceExpanderCtx::new(global_idx, plan);

let instance = self.secondary_sm[i].get_instance(iectx);
Expand Down Expand Up @@ -176,14 +177,11 @@ impl<F: PrimeField> ZiskExecutor<F> {
fn compute_minimal_traces(&self, public_inputs: Vec<u8>, num_threads: usize) -> Vec<EmuTrace> {
timer_start_debug!(PHASE1_FAST_PROCESS_ROM);

let pctx = self.wcm.get_pctx();
let air_main = pctx.pilout.get_air(ZISK_AIRGROUP_ID, MAIN_AIR_IDS[0]);

// Prepare the settings for the emulator
let emu_options = EmuOptions {
elf: None, //Some(rom_path.to_path_buf().display().to_string()),
inputs: None, //Some(public_inputs_path.display().to_string()),
trace_steps: Some(air_main.num_rows() as u64 - 1),
trace_steps: Some(MainTrace::<F>::NUM_ROWS as u64 - 1),
..EmuOptions::default()
};

Expand All @@ -208,6 +206,7 @@ impl<F: PrimeField> ZiskExecutor<F> {
ZISK_AIRGROUP_ID,
MAIN_AIR_IDS[0],
Some(segment_id),
InstanceType::Instance,
Some(CheckPoint::new(segment_id, 0)),
None,
)
Expand Down
3 changes: 1 addition & 2 deletions pil/src/pil_helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// WARNING: This file has been autogenerated from the PILOUT file.
// Manual modifications are not recommended and may be overwritten.
mod pilout;
#[rustfmt::skip]
mod traces;

pub use pilout::*;
pub use traces::*;
45 changes: 0 additions & 45 deletions pil/src/pil_helpers/pilout.rs

This file was deleted.

57 changes: 44 additions & 13 deletions pil/src/pil_helpers/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,62 @@
// Manual modifications are not recommended and may be overwritten.
use proofman_common as common;
pub use proofman_macros::trace;
pub use proofman_macros::values;

trace!(MainRow, MainTrace<F> {
#[allow(dead_code)]
type FieldExtension<F> = [F; 3];

pub const PILOUT_HASH: &[u8] = b"ZiskMain2-hash";

//AIRGROUP CONSTANTS

pub const ZISK_AIRGROUP_ID: usize = 0;

//AIR CONSTANTS

pub const MAIN_AIR_IDS: &[usize] = &[0];

pub const ROM_AIR_IDS: &[usize] = &[1];

pub const BINARY_AIR_IDS: &[usize] = &[2];

pub const BINARY_TABLE_AIR_IDS: &[usize] = &[3];

pub const BINARY_EXTENSION_AIR_IDS: &[usize] = &[4];

pub const BINARY_EXTENSION_TABLE_AIR_IDS: &[usize] = &[5];

pub const SPECIFIED_RANGES_AIR_IDS: &[usize] = &[6];


trace!(MainTrace<F> {
a: [F; 2], b: [F; 2], c: [F; 2], flag: F, pc: F, a_src_imm: F, a_src_mem: F, a_offset_imm0: F, a_imm1: F, a_src_step: F, b_src_imm: F, b_src_mem: F, b_offset_imm0: F, b_imm1: F, b_src_ind: F, ind_width: F, is_external_op: F, op: F, store_ra: F, store_mem: F, store_ind: F, store_offset: F, set_pc: F, jmp_offset1: F, jmp_offset2: F, m32: F, addr1: F, __debug_operation_bus_enabled: F,
});
}, 0, 0, 2097152 );

trace!(RomRow, RomTrace<F> {
trace!(RomTrace<F> {
line: F, a_offset_imm0: F, a_imm1: F, b_offset_imm0: F, b_imm1: F, ind_width: F, op: F, store_offset: F, jmp_offset1: F, jmp_offset2: F, flags: F, multiplicity: F,
});
}, 0, 1, 1048576 );

trace!(BinaryRow, BinaryTrace<F> {
trace!(BinaryTrace<F> {
m_op: F, mode32: F, free_in_a: [F; 8], free_in_b: [F; 8], free_in_c: [F; 8], carry: [F; 8], use_last_carry: F, op_is_min_max: F, multiplicity: F, main_step: F,
});
}, 0, 2, 2097152 );

trace!(BinaryTableRow, BinaryTableTrace<F> {
trace!(BinaryTableTrace<F> {
multiplicity: F,
});
}, 0, 3, 4194304 );

trace!(BinaryExtensionRow, BinaryExtensionTrace<F> {
trace!(BinaryExtensionTrace<F> {
op: F, in1: [F; 8], in2_low: F, out: [[F; 2]; 8], op_is_shift: F, in2: [F; 2], main_step: F, multiplicity: F,
});
}, 0, 4, 2097152 );

trace!(BinaryExtensionTableRow, BinaryExtensionTableTrace<F> {
trace!(BinaryExtensionTableTrace<F> {
multiplicity: F,
});
}, 0, 5, 4194304 );

trace!(SpecifiedRangesRow, SpecifiedRangesTrace<F> {
trace!(SpecifiedRangesTrace<F> {
mul: [F; 1],
}, 0, 6, 16777216 );

values!(MainAirValues<F> {
main_last_segment: FieldExtension<F>, main_segment: FieldExtension<F>,
});
53 changes: 25 additions & 28 deletions rom-merkle/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use clap::{Arg, Command};
use colored::Colorize;
use p3_goldilocks::Goldilocks;
use proofman_common::{GlobalInfo, ProofType, SetupCtx};
use sm_rom::RomSM;
use stark::StarkBufferAllocator;
use zisk_core::Riscv2zisk;
use std::{path::Path, sync::Arc};
// use proofman_common::{GlobalInfo, ProofType, SetupCtx};
// use stark::StarkBufferAllocator;
use std::path::Path;
use sysinfo::System;
// use zisk_core::Riscv2zisk;

fn main() {
let matches = Command::new("ROM Handler")
Expand All @@ -32,12 +30,12 @@ fn main() {
// Get the value of the `rom` argument as a path
let rom_path_str = matches.get_one::<String>("rom").expect("ROM path is required");
let rom_path = Path::new(rom_path_str);
let proving_key_path_str =
matches.get_one::<String>("proving_key").expect("Proving key path is required");
let proving_key_path = Path::new(proving_key_path_str);
let global_info_path_str =
matches.get_one::<String>("global_info").expect("Global info path is required");
let global_info_path = Path::new(global_info_path_str);
// let proving_key_path_str =
// matches.get_one::<String>("proving_key").expect("Proving key path is required");
// let proving_key_path = Path::new(proving_key_path_str);
// let global_info_path_str =
// matches.get_one::<String>("global_info").expect("Global info path is required");
// let global_info_path = Path::new(global_info_path_str);

env_logger::builder()
.format_timestamp(None)
Expand Down Expand Up @@ -82,27 +80,26 @@ fn main() {
// If all checks pass, continue with the program
println!("ROM Path is valid: {}", rom_path.display());

let buffer_allocator: Arc<StarkBufferAllocator> =
Arc::new(StarkBufferAllocator::new(proving_key_path.to_path_buf()));
let global_info = GlobalInfo::new(global_info_path);
let sctx = Arc::new(SetupCtx::<Goldilocks>::new(&global_info, &ProofType::Basic));
// let _buffer_allocator: Arc<StarkBufferAllocator> =
// Arc::new(StarkBufferAllocator::new(proving_key_path.to_path_buf()));
// let global_info = GlobalInfo::new(global_info_path);
// let _sctx = Arc::new(SetupCtx::new(&global_info, &ProofType::Basic));

// Get the ELF file path as a string
let elf_filename: String = rom_path.to_str().unwrap().into();
println!("Proving ROM for ELF file={}", elf_filename);
// // Get the ELF file path as a string
// let elf_filename: String = rom_path.to_str().unwrap().into();
// println!("Proving ROM for ELF file={}", elf_filename);

// Create an instance of the RISCV -> ZisK program converter
let riscv2zisk = Riscv2zisk::new(elf_filename, String::new(), String::new(), String::new());
// // Create an instance of the RISCV -> ZisK program converter
// let riscv2zisk = Riscv2zisk::new(elf_filename, String::new(), String::new(), String::new());

// Convert program to rom
let rom = riscv2zisk.run().expect("RomSM::prover() failed running rom");
// // Convert program to rom
// let _rom = riscv2zisk.run().expect("RomSM::prover() failed running rom");

// Compute the trace
// RomSM::<Goldilocks>::prove_instance(wcm, rom, plan, buffer, trace_rows);
// // Compute the trace
// // RomSM::<Goldilocks>::prove_instance(wcm, rom, plan, buffer, trace_rows);

// Compute LDE and Merkelize and get the root of the rom
// TODO: Implement the logic to compute the trace
// // Compute LDE and Merkelize and get the root of the rom
// // TODO: Implement the logic to compute the trace

log::info!("ROM proof successful");
}

2 changes: 1 addition & 1 deletion state-machines/arith/src/arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl ArithSM {
};
let arith_sm = Arc::new(arith_sm);

wcm.register_component(arith_sm.clone(), None, None);
wcm.register_proxy_component(arith_sm.clone());

arith_sm.arith32_sm.register_predecessor();
arith_sm.arith64_sm.register_predecessor();
Expand Down
2 changes: 1 addition & 1 deletion state-machines/arith/src/arith_32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Arith32SM {
Self { registered_predecessors: AtomicU32::new(0), inputs: Mutex::new(Vec::new()) };
let arith32_sm = Arc::new(arith32_sm);

wcm.register_component(arith32_sm.clone(), Some(ARITH_AIRGROUP_ID), Some(ARITH32_AIR_IDS));
wcm.register_component(arith32_sm.clone(), ARITH_AIRGROUP_ID, ARITH32_AIR_IDS[0]);

arith32_sm
}
Expand Down
6 changes: 1 addition & 5 deletions state-machines/arith/src/arith_3264.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ impl Arith3264SM {
Self { registered_predecessors: AtomicU32::new(0), inputs: Mutex::new(Vec::new()) };
let arith3264_sm = Arc::new(arith3264_sm);

wcm.register_component(
arith3264_sm.clone(),
Some(ARITH_AIRGROUP_ID),
Some(ARITH3264_AIR_IDS),
);
wcm.register_component(arith3264_sm.clone(), ARITH_AIRGROUP_ID, ARITH3264_AIR_IDS[0]);

arith3264_sm
}
Expand Down
2 changes: 1 addition & 1 deletion state-machines/arith/src/arith_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Arith64SM {
Self { registered_predecessors: AtomicU32::new(0), inputs: Mutex::new(Vec::new()) };
let arith64_sm = Arc::new(arith64_sm);

wcm.register_component(arith64_sm.clone(), Some(ARITH_AIRGROUP_ID), Some(ARITH64_AIR_IDS));
wcm.register_component(arith64_sm.clone(), ARITH_AIRGROUP_ID, ARITH64_AIR_IDS[0]);

arith64_sm
}
Expand Down
6 changes: 0 additions & 6 deletions state-machines/arith/src/arith_traces.rs

This file was deleted.

2 changes: 0 additions & 2 deletions state-machines/arith/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ mod arith;
mod arith_32;
mod arith_3264;
mod arith_64;
mod arith_traces;

pub use arith::*;
pub use arith_32::*;
pub use arith_3264::*;
pub use arith_64::*;
pub use arith_traces::*;
15 changes: 7 additions & 8 deletions state-machines/binary/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ pub struct BinarySM<F: PrimeField> {

// Secondary State machines
binary_basic_sm: Arc<BinaryBasicSM<F>>,
binary_basic_table_sm: Arc<BinaryBasicTableSM<F>>,
binary_basic_table_sm: Arc<BinaryBasicTableSM>,
binary_extension_sm: Arc<BinaryExtensionSM<F>>,
binary_extension_table_sm: Arc<BinaryExtensionTableSM<F>>,
binary_extension_table_sm: Arc<BinaryExtensionTableSM>,
}

impl<F: PrimeField> BinarySM<F> {
pub fn new(wcm: Arc<WitnessManager<F>>, std: Arc<Std<F>>) -> Arc<Self> {
let binary_basic_table_sm = BinaryBasicTableSM::new(wcm.clone());
let binary_basic_sm = BinaryBasicSM::new(wcm.clone(), binary_basic_table_sm.clone());
let binary_basic_table_sm = BinaryBasicTableSM::new::<F>();
let binary_basic_sm = BinaryBasicSM::new(binary_basic_table_sm.clone());

let binary_extension_table_sm = BinaryExtensionTableSM::new(wcm.clone());
let binary_extension_sm =
BinaryExtensionSM::new(wcm.clone(), std, binary_extension_table_sm.clone());
let binary_extension_table_sm = BinaryExtensionTableSM::new::<F>();
let binary_extension_sm = BinaryExtensionSM::new(std, binary_extension_table_sm.clone());

let binary_sm = Self {
wcm: wcm.clone(),
Expand All @@ -52,7 +51,7 @@ impl<F: PrimeField> ComponentProvider<F> for BinarySM<F> {
}

fn get_planner(&self) -> Box<dyn Planner> {
Box::new(BinaryPlanner::new(self.wcm.clone()))
Box::new(BinaryPlanner::<F>::new())
}

fn get_instance(&self, iectx: InstanceExpanderCtx) -> Box<dyn Instance> {
Expand Down
Loading

0 comments on commit 661e871

Please sign in to comment.