-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
351 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#[macro_export] | ||
macro_rules! hash { | ||
($value:expr) => {{ | ||
let mut hasher = DefaultHasher::new(); | ||
$value.hash(&mut hasher); | ||
hasher.finish() | ||
}}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,35 @@ | ||
use libsecp256k1::{PublicKey, Signature}; | ||
use std::{ | ||
fmt::Display, | ||
hash::{DefaultHasher, Hash, Hasher}, | ||
}; | ||
|
||
#[derive(Debug, PartialEq, Eq, Hash, Clone)] | ||
use crate::hash; | ||
|
||
#[derive(Debug, PartialEq, Eq, Clone)] | ||
pub struct Job { | ||
pub reward: u32, | ||
pub num_of_steps: u32, | ||
pub private_input: Vec<u8>, | ||
pub public_input: Vec<u8>, | ||
pub cpu_air_prover_config: Vec<u8>, | ||
pub cpu_air_params: Vec<u8>, | ||
pub cairo_pie: Vec<u8>, | ||
pub public_key: PublicKey, | ||
pub signature: Signature, | ||
// below fields not bounded by signature | ||
pub cpu_air_params: Vec<u8>, // needed for proving | ||
pub cpu_air_prover_config: Vec<u8>, // needed for proving | ||
} | ||
|
||
impl Hash for Job { | ||
fn hash<H: Hasher>(&self, state: &mut H) { | ||
self.reward.hash(state); | ||
self.num_of_steps.hash(state); | ||
self.cairo_pie.hash(state); | ||
self.cpu_air_prover_config.hash(state); | ||
self.cpu_air_params.hash(state); | ||
} | ||
} | ||
|
||
impl Display for Job { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let mut hasher = DefaultHasher::new(); | ||
self.hash(&mut hasher); | ||
write!(f, "{}", hex::encode(hasher.finish().to_be_bytes())) | ||
write!(f, "{}", hex::encode(hash!(self).to_be_bytes())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::hash; | ||
use std::{ | ||
fmt::Display, | ||
hash::{DefaultHasher, Hash, Hasher}, | ||
}; | ||
use tempfile::NamedTempFile; | ||
|
||
#[derive(Debug)] | ||
pub struct JobTrace { | ||
pub air_public_input: NamedTempFile, | ||
pub air_private_input: NamedTempFile, | ||
pub memory: NamedTempFile, // this is not used directly but needs to live for air_private_input to be valid | ||
pub trace: NamedTempFile, // this is not used directly but needs to live for air_private_input to be valid | ||
pub cpu_air_prover_config: NamedTempFile, | ||
pub cpu_air_params: NamedTempFile, | ||
} | ||
|
||
impl Hash for JobTrace { | ||
fn hash<H: Hasher>(&self, state: &mut H) { | ||
self.air_public_input.path().hash(state); | ||
self.air_private_input.path().hash(state); | ||
self.memory.path().hash(state); | ||
self.trace.path().hash(state); | ||
self.cpu_air_prover_config.path().hash(state); | ||
self.cpu_air_params.path().hash(state); | ||
} | ||
} | ||
|
||
impl Display for JobTrace { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", hex::encode(hash!(self).to_be_bytes())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
use crate::hash; | ||
use cairo_felt::Felt252; | ||
use std::{ | ||
fmt::Display, | ||
hash::{DefaultHasher, Hash, Hasher}, | ||
}; | ||
|
||
use cairo_felt::Felt252; | ||
|
||
#[derive(Debug, PartialEq, Eq, Hash, Clone)] | ||
pub struct JobWitness { | ||
pub data: Vec<Felt252>, | ||
} | ||
|
||
impl Display for JobWitness { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let mut hasher = DefaultHasher::new(); | ||
self.hash(&mut hasher); | ||
write!(f, "{}", hex::encode(hasher.finish().to_be_bytes())) | ||
write!(f, "{}", hex::encode(hash!(self).to_be_bytes())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
pub mod hash_macro; | ||
pub mod job; | ||
pub mod job_trace; | ||
pub mod job_witness; | ||
pub mod network; | ||
pub mod topic; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
pub mod errors; | ||
pub mod stone_prover; | ||
#[allow(async_fn_in_trait)] | ||
pub mod traits; | ||
|
||
pub mod stone_prover; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
use sharp_p2p_common::{job::Job, job_witness::JobWitness}; | ||
|
||
use crate::errors::ProverControllerError; | ||
use sharp_p2p_common::{job_trace::JobTrace, job_witness::JobWitness}; | ||
|
||
pub trait Prover { | ||
fn init() -> impl ProverController; | ||
} | ||
|
||
pub trait ProverController { | ||
async fn prove(&mut self, job: Job) -> Result<JobWitness, ProverControllerError>; | ||
async fn terminate(&mut self, job: &Job) -> Result<(), ProverControllerError>; | ||
async fn prove(&mut self, job_trace: JobTrace) -> Result<JobWitness, ProverControllerError>; | ||
async fn terminate(&mut self, job_trace_hash: u64) -> Result<(), ProverControllerError>; | ||
async fn drop(self) -> Result<(), ProverControllerError>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "sharp-p2p-runner" | ||
version.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
license-file.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
async-process.workspace = true | ||
cairo-proof-parser.workspace = true | ||
futures.workspace= true | ||
itertools.workspace = true | ||
serde_json.workspace = true | ||
serde.workspace = true | ||
sharp-p2p-common.workspace = true | ||
strum.workspace = true | ||
tempfile.workspace = true | ||
thiserror.workspace = true | ||
tokio.workspace = true | ||
tracing.workspace = true | ||
zip-extensions.workspace = true |
Oops, something went wrong.