Skip to content

Commit

Permalink
prover input serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Jan 9, 2025
1 parent d84dd9f commit b4e113d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use cairo_vm::air_public_input::MemorySegmentAddresses;
use cairo_vm::stdlib::collections::HashMap;
use cairo_vm::types::builtin_name::BuiltinName;
use serde::{Deserialize, Serialize};

/// This struct holds the builtins used in a Cairo program.
#[derive(Debug, Default)]
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct BuiltinSegments {
pub add_mod: Option<MemorySegmentAddresses>,
pub bitwise: Option<MemorySegmentAddresses>,
Expand Down
7 changes: 4 additions & 3 deletions stwo_cairo_prover/crates/prover/src/input/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::ops::{Deref, DerefMut};

use itertools::Itertools;
use serde::{Deserialize, Serialize};

use super::vm_import::MemoryEntry;
use crate::components::memory::memory_id_to_big::component::N_M31_IN_SMALL_FELT252;
Expand Down Expand Up @@ -29,7 +30,7 @@ pub const P_MIN_2: [u32; 8] = [
0x0800_0000,
];

#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
pub struct MemoryConfig {
pub small_max: u128,
}
Expand All @@ -49,7 +50,7 @@ impl Default for MemoryConfig {

// TODO(spapini): Add U26 for addresses and U128 for range checks.
// TODO(spapini): Use some struct for Felt252 (that is still memory efficient).
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
pub struct Memory {
pub config: MemoryConfig,
pub address_to_id: Vec<EncodedMemoryValueId>,
Expand Down Expand Up @@ -184,7 +185,7 @@ impl DerefMut for MemoryBuilder {
}

pub const LARGE_MEMORY_VALUE_ID_TAG: u32 = 0x4000_0000;
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
pub struct EncodedMemoryValueId(pub u32);
impl EncodedMemoryValueId {
pub fn encode(value: MemoryValueId) -> EncodedMemoryValueId {
Expand Down
3 changes: 2 additions & 1 deletion stwo_cairo_prover/crates/prover/src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::HashMap;
use builtin_segments::BuiltinSegments;
use memory::Memory;
use prover_types::cpu::M31;
use serde::{Deserialize, Serialize};
use state_transitions::StateTransitions;

pub mod builtin_segments;
Expand All @@ -16,7 +17,7 @@ pub mod vm_import;
pub const N_REGISTERS: usize = 3;

/// Externally provided inputs for the Stwo prover.
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
pub struct ProverInput {
pub state_transitions: StateTransitions,
pub instruction_by_pc: HashMap<M31, u64>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::fmt::Display;

use prover_types::cpu::CasmState;
use serde::{Deserialize, Serialize};
use stwo_prover::core::fields::m31::M31;

use super::decode::Instruction;
Expand All @@ -19,7 +20,7 @@ const SMALL_MUL_MIN_VALUE: u64 = 0;
// TODO (Stav): Ensure it stays synced with that opcdode AIR's list.
/// This struct holds the components used to prove the opcodes in a Cairo program,
/// and should match the opcode's air used by `stwo-cairo-air`.
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct CasmStatesByOpcode {
pub generic_opcode: Vec<CasmState>,
pub add_ap_opcode_is_imm_f_op_1_base_fp_f: Vec<CasmState>,
Expand Down Expand Up @@ -183,7 +184,7 @@ impl From<TraceEntry> for CasmState {

/// Holds the state transitions of a Cairo program, split according to the components responsible
/// for proving each transition.
#[derive(Debug, Default)]
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct StateTransitions {
pub initial_state: CasmState,
pub final_state: CasmState,
Expand Down

0 comments on commit b4e113d

Please sign in to comment.