Skip to content

Commit a292dee

Browse files
committed
move prover input info to a new seperate file
1 parent 33d75ca commit a292dee

File tree

4 files changed

+48
-40
lines changed

4 files changed

+48
-40
lines changed

cairo-vm-cli/src/main.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use bincode::enc::write::Writer;
44
use cairo_vm::air_public_input::PublicInputError;
55
use cairo_vm::cairo_run::{self, EncodeTraceError};
66
use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor;
7+
use cairo_vm::prover_input_info::ProverInputInfoError;
78
#[cfg(feature = "with_tracer")]
89
use cairo_vm::serde::deserialize_program::DebugInfo;
910
use cairo_vm::types::layout::CairoLayoutParams;
@@ -14,7 +15,7 @@ use cairo_vm::vm::errors::vm_errors::VirtualMachineError;
1415
use cairo_vm::vm::runners::cairo_pie::CairoPie;
1516
#[cfg(feature = "with_tracer")]
1617
use cairo_vm::vm::runners::cairo_runner::CairoRunner;
17-
use cairo_vm::vm::runners::cairo_runner::{ProverInputInfoError, RunResources};
18+
use cairo_vm::vm::runners::cairo_runner::RunResources;
1819
#[cfg(feature = "with_tracer")]
1920
use cairo_vm_tracer::error::trace_data_errors::TraceDataError;
2021
#[cfg(feature = "with_tracer")]

vm/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub mod cairo_run;
6060
pub mod hint_processor;
6161
pub mod math_utils;
6262
pub mod program_hash;
63+
pub mod prover_input_info;
6364
pub mod serde;
6465
pub mod typed_operations;
6566
pub mod types;

vm/src/prover_input_info.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use crate::stdlib::{collections::BTreeMap, prelude::*};
2+
use crate::types::builtin_name::BuiltinName;
3+
use crate::types::relocatable::MaybeRelocatable;
4+
use crate::vm::trace::trace_entry::TraceEntry;
5+
use serde::Deserialize;
6+
use serde::Serialize;
7+
use thiserror::Error;
8+
9+
//* ----------------------
10+
//* ProverInputInfo
11+
//* ----------------------
12+
/// This struct contains all relevant data for the prover.
13+
/// All addresses are relocatable.
14+
#[derive(Deserialize, Serialize, PartialEq)]
15+
pub struct ProverInputInfo {
16+
/// A vector of trace entries, i.e. pc, ap, fp, where pc is relocatable.
17+
pub relocatable_trace: Vec<TraceEntry>,
18+
/// A vector of segments, where each segment is a vector of maybe relocatable values or holes (`None`).
19+
pub relocatable_memory: Vec<Vec<Option<MaybeRelocatable>>>,
20+
/// A map from segment index to a vector of offsets within the segment, representing the public memory addresses.
21+
pub public_memory_offsets: BTreeMap<usize, Vec<usize>>,
22+
/// A map from the builtin segment index into its name.
23+
pub builtins_segments: BTreeMap<usize, BuiltinName>,
24+
}
25+
26+
impl ProverInputInfo {
27+
pub fn serialize_json(&self) -> Result<String, ProverInputInfoError> {
28+
serde_json::to_string_pretty(&self).map_err(ProverInputInfoError::from)
29+
}
30+
pub fn serialize(&self) -> Result<Vec<u8>, ProverInputInfoError> {
31+
bincode::serde::encode_to_vec(self, bincode::config::standard())
32+
.map_err(ProverInputInfoError::from)
33+
}
34+
}
35+
36+
// TODO(Stav): add TraceNotEnabled error.
37+
#[derive(Debug, Error)]
38+
pub enum ProverInputInfoError {
39+
#[error("Failed to (de)serialize data using bincode")]
40+
SerdeBincode(#[from] bincode::error::EncodeError),
41+
#[error("Failed to (de)serialize data using json")]
42+
SerdeJson(#[from] serde_json::Error),
43+
}

vm/src/vm/runners/cairo_runner.rs

+2-39
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ use crate::{
1111
types::{builtin_name::BuiltinName, layout::CairoLayoutParams, layout_name::LayoutName},
1212
vm::{
1313
runners::builtin_runner::SegmentArenaBuiltinRunner,
14-
trace::trace_entry::{relocate_trace_register, RelocatedTraceEntry, TraceEntry},
14+
trace::trace_entry::{relocate_trace_register, RelocatedTraceEntry},
1515
},
1616
Felt252,
1717
};
1818

1919
use crate::{
2020
hint_processor::hint_processor_definition::{HintProcessor, HintReference},
21+
prover_input_info::ProverInputInfo,
2122
types::{
2223
errors::{math_errors::MathError, program_errors::ProgramError},
2324
exec_scope::ExecutionScopes,
@@ -48,7 +49,6 @@ use crate::{
4849
use num_integer::div_rem;
4950
use num_traits::{ToPrimitive, Zero};
5051
use serde::{Deserialize, Serialize};
51-
use thiserror::Error;
5252

5353
use super::{builtin_runner::ModBuiltinRunner, cairo_pie::CairoPieAdditionalData};
5454
use super::{
@@ -1545,43 +1545,6 @@ impl CairoRunner {
15451545
}
15461546
}
15471547

1548-
// TODO(Stav): move to specified file.
1549-
//* ----------------------
1550-
//* ProverInputInfo
1551-
//* ----------------------
1552-
/// This struct contains all relevant data for the prover.
1553-
/// All addresses are relocatable.
1554-
#[derive(Deserialize, Serialize, PartialEq)]
1555-
pub struct ProverInputInfo {
1556-
/// A vector of trace entries, i.e. pc, ap, fp, where pc is relocatable.
1557-
pub relocatable_trace: Vec<TraceEntry>,
1558-
/// A vector of segments, where each segment is a vector of maybe relocatable values or holes (`None`).
1559-
pub relocatable_memory: Vec<Vec<Option<MaybeRelocatable>>>,
1560-
/// A map from segment index to a vector of offsets within the segment, representing the public memory addresses.
1561-
pub public_memory_offsets: BTreeMap<usize, Vec<usize>>,
1562-
/// A map from the builtin segment index into its name.
1563-
pub builtins_segments: BTreeMap<usize, BuiltinName>,
1564-
}
1565-
1566-
impl ProverInputInfo {
1567-
pub fn serialize_json(&self) -> Result<String, ProverInputInfoError> {
1568-
serde_json::to_string_pretty(&self).map_err(ProverInputInfoError::from)
1569-
}
1570-
pub fn serialize(&self) -> Result<Vec<u8>, ProverInputInfoError> {
1571-
bincode::serde::encode_to_vec(self, bincode::config::standard())
1572-
.map_err(ProverInputInfoError::from)
1573-
}
1574-
}
1575-
1576-
// TODO(Stav): add TraceNotEnabled error.
1577-
#[derive(Debug, Error)]
1578-
pub enum ProverInputInfoError {
1579-
#[error("Failed to (de)serialize data using bincode")]
1580-
SerdeBincode(#[from] bincode::error::EncodeError),
1581-
#[error("Failed to (de)serialize data using json")]
1582-
SerdeJson(#[from] serde_json::Error),
1583-
}
1584-
15851548
#[derive(Clone, Debug, Eq, PartialEq)]
15861549
pub struct SegmentInfo {
15871550
pub index: isize,

0 commit comments

Comments
 (0)