Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ members = [
"crates/apollo_proc_macros",
"crates/apollo_proc_macros_tests",
"crates/apollo_proof_manager",
"crates/apollo_proof_manager_config",
"crates/apollo_propeller",
"crates/apollo_protobuf",
"crates/apollo_reverts",
Expand Down Expand Up @@ -185,6 +186,7 @@ apollo_p2p_sync_config.path = "crates/apollo_p2p_sync_config"
apollo_proc_macros = { path = "crates/apollo_proc_macros", version = "0.0.0" }
apollo_proc_macros_tests.path = "crates/apollo_proc_macros_tests"
apollo_proof_manager.path = "crates/apollo_proof_manager"
apollo_proof_manager_config.path = "crates/apollo_proof_manager_config"
apollo_propeller.path = "crates/apollo_propeller"
apollo_protobuf.path = "crates/apollo_protobuf"
apollo_reverts.path = "crates/apollo_reverts"
Expand Down
1 change: 1 addition & 0 deletions crates/apollo_proof_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ testing = []
workspace = true

[dependencies]
apollo_proof_manager_config.workspace = true
hex.workspace = true
starknet-types-core = { workspace = true, features = ["hash"] }
starknet_api.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions crates/apollo_proof_manager/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod proof_manager;
pub mod proof_storage;

pub use proof_storage::ProofStorage;
33 changes: 33 additions & 0 deletions crates/apollo_proof_manager/src/proof_manager.rs
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
use apollo_proof_manager_config::config::ProofManagerConfig;
use starknet_api::transaction::fields::Proof;
use starknet_types_core::felt::Felt;

use crate::proof_storage::{FsProofStorage, FsProofStorageError, ProofStorage};
/// Proof manager that wraps filesystem-based proof storage.
pub struct ProofManager {
pub proof_storage: FsProofStorage,
// TODO(Einat): Add cache.
}

impl ProofManager {
pub fn new(config: ProofManagerConfig) -> Self {
let proof_storage =
FsProofStorage::new(config.persistent_root).expect("Failed to create proof storage.");
Self { proof_storage }
}
}

impl ProofStorage for ProofManager {
type Error = FsProofStorageError;

fn set_proof(&self, facts_hash: Felt, proof: Proof) -> Result<(), Self::Error> {
self.proof_storage.set_proof(facts_hash, proof)
}

fn get_proof(&self, facts_hash: Felt) -> Result<Option<Proof>, Self::Error> {
self.proof_storage.get_proof(facts_hash)
}

fn contains_proof(&self, facts_hash: Felt) -> Result<bool, Self::Error> {
self.proof_storage.contains_proof(facts_hash)
}
}
4 changes: 0 additions & 4 deletions crates/apollo_proof_manager/src/proof_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,17 @@ impl FsProofStorage {
/// a1/
/// └── b2/
/// └── a1b2c3d4.../
#[allow(dead_code)]
fn get_proof_dir(&self, facts_hash: Felt) -> PathBuf {
let facts_hash = hex::encode(facts_hash.to_bytes_be());
let (first_msb_byte, second_msb_byte, _rest_of_bytes) =
(&facts_hash[..2], &facts_hash[2..4], &facts_hash[4..]);
PathBuf::from(first_msb_byte).join(second_msb_byte).join(facts_hash)
}

#[allow(dead_code)]
fn get_persistent_dir(&self, facts_hash: Felt) -> PathBuf {
self.persistent_root.join(self.get_proof_dir(facts_hash))
}

#[allow(dead_code)]
fn get_persistent_dir_with_create(&self, facts_hash: Felt) -> FsProofStorageResult<PathBuf> {
let path = self.get_persistent_dir(facts_hash);
if let Some(parent) = path.parent() {
Expand All @@ -69,7 +66,6 @@ impl FsProofStorage {
Ok(path)
}

#[allow(dead_code)]
fn create_tmp_dir(
&self,
facts_hash: Felt,
Expand Down
21 changes: 21 additions & 0 deletions crates/apollo_proof_manager_config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "apollo_proof_manager_config"
edition.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true
description = "Configuration for Apollo proof manager"

[features]
testing = []

[lints]
workspace = true

[dependencies]
apollo_config.workspace = true
serde = { workspace = true, features = ["derive"] }
validator.workspace = true


[dev-dependencies]
30 changes: 30 additions & 0 deletions crates/apollo_proof_manager_config/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::collections::BTreeMap;
use std::path::PathBuf;

use apollo_config::dumping::{ser_param, SerializeConfig};
use apollo_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use serde::{Deserialize, Serialize};
use validator::Validate;

/// Configuration for the proof manager.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Validate)]
pub struct ProofManagerConfig {
pub persistent_root: PathBuf,
}

impl Default for ProofManagerConfig {
fn default() -> Self {
Self { persistent_root: "/data/proofs".into() }
}
}

impl SerializeConfig for ProofManagerConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
BTreeMap::from([ser_param(
"persistent_root",
&self.persistent_root,
"Persistent root for proof storage.",
ParamPrivacyInput::Public,
)])
}
}
1 change: 1 addition & 0 deletions crates/apollo_proof_manager_config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod config;
Loading