Skip to content

Commit

Permalink
Adding cust-commits to instruction observer
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerTaule committed Dec 11, 2024
1 parent c32ace9 commit 5bf568d
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 109 deletions.
51 changes: 47 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
proofman-common = { workspace = true }
proofman-macros = { workspace = true }
proofman = { workspace = true }
serde = { version = "1.0.204", features = ["derive"] }

[features]
default = []
Expand Down
25 changes: 21 additions & 4 deletions pil/src/pil_helpers/traces.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// WARNING: This file has been autogenerated from the PILOUT file.
// Manual modifications are not recommended and may be overwritten.
use proofman_common as common;
pub use proofman_macros::trace;
pub use proofman_macros::values;

#[allow(dead_code)]
type FieldExtension<F> = [F; 3];

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

//AIRGROUP CONSTANTS

Expand Down Expand Up @@ -35,13 +34,27 @@ pub const BINARY_EXTENSION_TABLE_AIR_IDS: &[usize] = &[8];

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


//PUBLICS
use serde::Deserialize;
use serde::Serialize;
#[derive(Default, Debug, Serialize, Deserialize)]
pub struct ZiskPublics {
#[serde(default)]
pub rom_root: [u64; 4],

}

values!(ZiskPublicValues<F> {
rom_root: [F; 4],
});

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!(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,
multiplicity: F,
}, 0, 1, 1048576 );

trace!(ArithTrace<F> {
Expand Down Expand Up @@ -76,6 +89,10 @@ trace!(SpecifiedRangesTrace<F> {
mul: [F; 1],
}, 0, 9, 16777216 );

trace!(RomRomTrace<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,
}, 0, 1, 1048576, 0 );

values!(MainAirValues<F> {
main_last_segment: FieldExtension<F>, main_segment: FieldExtension<F>,
main_last_segment: F, main_segment: F,
});
5 changes: 3 additions & 2 deletions rom-merkle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ sm-rom = { path = "../state-machines/rom" }
log = { workspace = true }
stark = { workspace = true }
proofman-common = { workspace = true }
zisk-core = { path = "../core" }
proofman-util = { workspace = true }
zisk-pil = { path="../pil" }

p3-goldilocks = { git = "https://github.com/Plonky3/Plonky3.git", rev = "c3d754ef77b9fce585b46b972af751fe6e7a9803" }
p3-field = { workspace = true }
clap = { version = "4.5.13", features = ["derive", "env"] }
env_logger = "0.11"
sysinfo = "0.33"
sysinfo = "0.32"
colored = "2"
73 changes: 36 additions & 37 deletions rom-merkle/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
use clap::{Arg, Command};
use colored::Colorize;
// use proofman_common::{GlobalInfo, ProofType, SetupCtx};
// use stark::StarkBufferAllocator;
use std::path::Path;
use p3_goldilocks::Goldilocks;
use proofman_common::{get_custom_commit_trace, GlobalInfo, ProofType, SetupCtx};
use proofman_util::create_buffer_fast;
use sm_rom::RomSM;
use std::{path::Path, sync::Arc};
use sysinfo::System;
// use zisk_core::Riscv2zisk;
use zisk_pil::RomRomTrace;

fn main() {
let matches = Command::new("ROM Handler")
.version("1.0")
.about("Compute the Merkle Root of a ROM file")
.arg(Arg::new("rom").value_name("FILE").help("The ROM file path").required(true).index(1))
.arg(
Arg::new("rom").long("rom").value_name("FILE").help("The ROM file path").required(true),
)
.arg(
Arg::new("proving_key")
.long("proving-key")
.value_name("FILE")
.help("The proving key folder path")
.required(true)
.index(2),
.required(true),
)
.arg(
Arg::new("global_info")
Arg::new("rom_buffer")
.long("rom-buffer")
.value_name("FILE")
.help("The global info file path")
.required(true)
.index(3),
.help("The rom buffer path")
.required(true),
)
.get_matches();

// 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 rom_buffer_str =
matches.get_one::<String>("rom_buffer").expect("Buffer file path is required");

env_logger::builder()
.format_timestamp(None)
Expand Down Expand Up @@ -77,29 +80,25 @@ fn main() {
std::process::exit(1);
}

// 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::new(&global_info, &ProofType::Basic));
let global_info = GlobalInfo::new(proving_key_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);
let mut custom_rom_trace: RomRomTrace<Goldilocks> = RomRomTrace::new();
let setup = sctx.get_setup(custom_rom_trace.airgroup_id(), custom_rom_trace.air_id);

// // Create an instance of the RISCV -> ZisK program converter
// let riscv2zisk = Riscv2zisk::new(elf_filename, String::new(), String::new(), String::new());
RomSM::<Goldilocks>::compute_custom_trace_rom(rom_path.to_path_buf(), &mut custom_rom_trace);

// // Convert program to rom
// let _rom = riscv2zisk.run().expect("RomSM::prover() failed running rom");
let n_ext = (1 << setup.stark_info.stark_struct.n_bits_ext) as usize;
let n_cols = custom_rom_trace.num_rows();

// // Compute the trace
// // RomSM::<Goldilocks>::prove_instance(wcm, rom, plan, buffer, trace_rows);
let buffer_ext = create_buffer_fast(n_ext * n_cols);

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

log::info!("ROM proof successful");
get_custom_commit_trace(
custom_rom_trace.commit_id.unwrap() as u64,
0,
setup,
custom_rom_trace.get_buffer(),
buffer_ext,
rom_buffer_str.as_str(),
);
}
4 changes: 2 additions & 2 deletions state-machines/main/pil/main.pil
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,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_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);
direct_global_update(MAIN_CONTINUATION_ID, cols: [0, 0, 4096, 0, 0, 0, 0, 0], bus_type: PIOP_BUS_SUM, proves: 1);
direct_global_update(MAIN_CONTINUATION_ID, cols: [0, 1, 0x10000000, 0, 0, 0, 0, 0], bus_type: PIOP_BUS_SUM, proves: 0);
}
4 changes: 2 additions & 2 deletions state-machines/main/src/main_sm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ impl<F: PrimeField> MainSM<F> {
let main_segment = F::from_canonical_usize(current_segment);

let mut main_air_values = MainAirValues::<F>::new();
main_air_values.main_last_segment[0] = main_last_segment;
main_air_values.main_segment[0] = main_segment;
main_air_values.main_last_segment = main_last_segment;
main_air_values.main_segment = main_segment;

let air_instance = AirInstance::new_from_trace(
self.wcm.get_sctx(),
Expand Down
25 changes: 14 additions & 11 deletions state-machines/rom/pil/rom.pil
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ require "std_lookup.pil"

const int ROM_BUS_ID = 7890;

public rom_root[4];

airtemplate Rom(int N = 2**21, int stack_enabled = 0, const int rom_bus_id = ROM_BUS_ID) {
commit stage(0) public(rom_root) rom;

col witness line;
col witness a_offset_imm0;
col witness a_imm1;
col witness b_offset_imm0;
col witness b_imm1;
col witness ind_width;
col witness op;
col witness store_offset;
col witness jmp_offset1;
col witness jmp_offset2;
col witness flags;
col rom line;
col rom a_offset_imm0;
col rom a_imm1;
col rom b_offset_imm0;
col rom b_imm1;
col rom ind_width;
col rom op;
col rom store_offset;
col rom jmp_offset1;
col rom jmp_offset2;
col rom flags;


col witness multiplicity;
Expand Down
Loading

0 comments on commit 5bf568d

Please sign in to comment.