Skip to content

Commit

Permalink
Fetch absolute paths in cli and remove feature-gate
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoletta committed Jan 11, 2024
1 parent e91b523 commit 93ee579
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
22 changes: 21 additions & 1 deletion cairo-vm-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,29 @@ fn run(args: impl Iterator<Item = String>) -> Result<(), Error> {
}

if let Some(file_path) = args.air_private_input {
// Get absolute paths of trace_file & memory_file
let trace_path = args
.trace_file
.clone()
.unwrap()
.as_path()
.canonicalize()
.unwrap_or(args.trace_file.unwrap())
.to_string_lossy()
.to_string();
let memory_path = args
.memory_file
.clone()
.unwrap()
.as_path()
.canonicalize()
.unwrap_or(args.memory_file.unwrap())
.to_string_lossy()
.to_string();

let json = cairo_runner
.get_air_private_input(&vm)
.to_serializable(args.trace_file.unwrap(), args.memory_file.unwrap())
.to_serializable(trace_path, memory_path)
.serialize_json()
.map_err(PublicInputError::Serde)?;
std::fs::write(file_path, json)?;
Expand Down
18 changes: 6 additions & 12 deletions vm/src/air_private_input.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[cfg(feature = "std")]
use std::path::PathBuf;

use crate::{
stdlib::collections::HashMap,
vm::runners::builtin_runner::{
Expand All @@ -13,11 +10,10 @@ use serde::{Deserialize, Serialize};
use crate::Felt252;

// Serializable format, matches the file output of the python implementation
#[cfg(feature = "std")]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct AirPrivateInputSerializable {
trace_path: PathBuf,
memory_path: PathBuf,
trace_path: String,
memory_path: String,
pedersen: Vec<PrivateInput>,
range_check: Vec<PrivateInput>,
ecdsa: Vec<PrivateInput>,
Expand Down Expand Up @@ -100,16 +96,15 @@ pub struct SignatureInput {
pub w: Felt252,
}

#[cfg(feature = "std")]
impl AirPrivateInput {
pub fn to_serializable(
&self,
trace_file: PathBuf,
memory_file: PathBuf,
trace_path: String,
memory_path: String,
) -> AirPrivateInputSerializable {
AirPrivateInputSerializable {
trace_path: trace_file.as_path().canonicalize().unwrap_or(trace_file),
memory_path: memory_file.as_path().canonicalize().unwrap_or(memory_file),
trace_path,
memory_path,
pedersen: self.0.get(HASH_BUILTIN_NAME).cloned().unwrap_or_default(),
range_check: self
.0
Expand Down Expand Up @@ -137,7 +132,6 @@ impl AirPrivateInput {
}
}

#[cfg(feature = "std")]
impl AirPrivateInputSerializable {
pub fn serialize_json(&self) -> Result<String, serde_json::Error> {
serde_json::to_string_pretty(&self)
Expand Down

0 comments on commit 93ee579

Please sign in to comment.