Skip to content

Commit

Permalink
Merge branch 'currentChanges' of https://github.com/karnotxyz/proof-g…
Browse files Browse the repository at this point in the history
…enerator into currentChanges
  • Loading branch information
byteZorvin committed Sep 10, 2024
2 parents 4d2f8bf + f8223cc commit 64c238c
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 26 deletions.
193 changes: 193 additions & 0 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", rev = "05352b1c678
bincode = { version = "2.0.0-rc.3", default-features = false, features = [
"serde",
] }
clap = { version = "4.5.17", features = ["derive"] }
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ run: compile
@echo "Running Successfull !!"

run_bootloader: compile
@echo "Running with bootloader..."
cargo run -- $(COMPILED_OUTPUT) $(PUBLIC_INPUT) $(PRIVATE_INPUT) $(MEMORY_FILE) $(TRACE_FILE)
cargo run -- -c $(COMPILED_OUTPUT) -u $(PUBLIC_INPUT) -p $(PRIVATE_INPUT) -m $(MEMORY_FILE) -t $(TRACE_FILE)
node format.js $(PUBLIC_INPUT)
@echo "Running with bootloader Successfull !!"

Expand Down
60 changes: 36 additions & 24 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use cairo_bootloader::{
PackedOutput, SimpleBootloaderInput, TaskSpec,
};
use std::{
env,
io::{self, Write},
// path::PathBuf,
path::Path,
};

use clap::Parser;

fn cairo_run_bootloader_in_proof_mode(
bootloader_program: &Program,
tasks: Vec<TaskSpec>,
Expand Down Expand Up @@ -103,54 +103,66 @@ impl FileWriter {
}
}

fn main() -> Result<(), Box<dyn Error>> {
let args: Vec<String> = env::args().collect();
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
#[arg(short, long, required = true)]
compiled_program: String,

if args.len() != 6 {
eprintln!(
"Usage: cargo run --release -- <cairo_program_compiled.json> <air_public_input> <air_private_input> <memory_file> <trace_file>",
);
std::process::exit(1);
}
#[arg(short='u', long, required = true)]
air_public_input: String,

#[arg(short='p', long, required = true)]
air_private_input: String,

#[arg(short, long, required = true)]
memory_file: String,

for (_, path) in args[1..].iter().enumerate() {
#[arg(short, long, required = true)]
trace: String,
}

fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();

for path in [
&args.compiled_program,
&args.air_public_input,
&args.air_private_input,
&args.memory_file,
&args.trace,
] {
if !Path::new(path).exists() {
eprintln!("Error: File '{}' does not exist", path);
continue;
std::process::exit(1);
}
}

let compiled_program = args[1].clone();
let air_public_input = args[2].clone();
let air_private_input_file = args[3].clone();
let memory_file = args[4].clone();
let trace_file = args[5].clone();

let bootloader_program = load_bootloader()?;
let dummy_snos_program = std::fs::read(compiled_program)?;
let dummy_snos_program = std::fs::read(args.compiled_program)?;
let tasks = make_bootloader_tasks(&[&dummy_snos_program], &[])?;

let mut runner = cairo_run_bootloader_in_proof_mode(&bootloader_program, tasks)?;

// Air public input
{
let json = runner.get_air_public_input().unwrap().serialize_json()?;
std::fs::write(air_public_input, json)?;
std::fs::write(args.air_public_input, json)?;
}

// Air private input
{
let json = runner
.get_air_private_input()
.to_serializable(trace_file.clone(), memory_file.clone())
.to_serializable(args.trace.clone(), args.memory_file.clone())
.serialize_json()?;
// print!("{:?}", json);
std::fs::write(air_private_input_file, json)?;
std::fs::write(args.air_private_input, json)?;
}

// memory_file
{
let memory_file = std::fs::File::create(memory_file)?;
let memory_file = std::fs::File::create(args.memory_file)?;
let mut memory_writer =
FileWriter::new(io::BufWriter::with_capacity(5 * 1024 * 1024, memory_file));

Expand All @@ -161,7 +173,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// Trace file
{
let relocated_trace = runner.relocated_trace.clone().unwrap().clone();
let trace_file = std::fs::File::create(trace_file)?;
let trace_file = std::fs::File::create(args.trace)?;
let mut trace_writer =
FileWriter::new(io::BufWriter::with_capacity(3 * 1024 * 1024, trace_file));

Expand Down

0 comments on commit 64c238c

Please sign in to comment.