From 8a2f765932ae8b7c8d1c8bb51a6b0be35df4f957 Mon Sep 17 00:00:00 2001 From: Pia Date: Mon, 15 Apr 2024 11:09:10 +0900 Subject: [PATCH 1/8] feat: serialize mock job --- Cargo.toml | 17 +++++++++++++++-- crates/common/Cargo.toml | 3 ++- crates/common/src/job.rs | 10 ++++++++++ crates/delegator/src/main.rs | 15 +++++++++++++-- crates/executor/src/main.rs | 24 +++++++++++++++++++++++- 5 files changed, 63 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ba62b9c..25fca2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,8 @@ members = [ "crates/delegator", "crates/executor", "crates/peer", - "crates/prover", "crates/runner", + "crates/prover", + "crates/runner", ] exclude = [] @@ -21,6 +22,7 @@ license-file = "LICENSE" [workspace.dependencies] async-process = "2.2.0" async-stream = "0.3.5" +bincode = "1.3" cairo-felt = "0.9.1" cairo-proof-parser = { git = "https://github.com/Okm165/cairo-proof-parser", rev = "97a04bbee07330311b38d6f4cecfed3acb237626" } futures = "0.3.30" @@ -28,7 +30,18 @@ futures-core = "0.3.30" futures-util = "0.3.30" hex = "0.4.3" itertools = "0.12.1" -libp2p = { version = "0.53.2", features = ["secp256k1", "tokio","gossipsub","kad","mdns","noise","macros","tcp","yamux","quic"]} +libp2p = { version = "0.53.2", features = [ + "secp256k1", + "tokio", + "gossipsub", + "kad", + "mdns", + "noise", + "macros", + "tcp", + "yamux", + "quic", +] } libsecp256k1 = "0.7.1" num-bigint = "0.4.4" serde = "1.0.197" diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 6eeebdc..6bb3050 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -8,6 +8,7 @@ license-file.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +bincode.workspace = true cairo-felt.workspace = true hex.workspace = true libp2p.workspace = true @@ -16,4 +17,4 @@ num-bigint.workspace = true serde_json.workspace = true serde.workspace = true tempfile.workspace = true -thiserror.workspace = true \ No newline at end of file +thiserror.workspace = true diff --git a/crates/common/src/job.rs b/crates/common/src/job.rs index 3f6e61b..0e6238d 100644 --- a/crates/common/src/job.rs +++ b/crates/common/src/job.rs @@ -33,3 +33,13 @@ impl Display for Job { write!(f, "{}", hex::encode(hash!(self).to_be_bytes())) } } + +impl Job { + pub fn serialize_job(&self) -> Vec { + bincode::serialize(self).unwrap() + } + + pub fn deserialize_job(serialized_job: &[u8]) -> Self { + bincode::deserialize(serialized_job).unwrap() + } +} diff --git a/crates/delegator/src/main.rs b/crates/delegator/src/main.rs index 08723aa..f527308 100644 --- a/crates/delegator/src/main.rs +++ b/crates/delegator/src/main.rs @@ -1,4 +1,5 @@ use futures_util::StreamExt; +use sharp_p2p_common::job::Job; use sharp_p2p_common::network::Network; use sharp_p2p_common::topic::{gossipsub_ident_topic, Topic}; use sharp_p2p_peer::registry::RegistryHandler; @@ -36,8 +37,18 @@ async fn main() -> Result<(), Box> { loop { tokio::select! { - Ok(Some(line)) = stdin.next_line() => { - send_topic_tx.send(line.as_bytes().to_vec()).await?; + Ok(Some(_)) = stdin.next_line() => { + // TODO: Turn this into a real job generation + let job = Job { + reward: 100, + num_of_steps: 10, + private_input: vec![1, 2, 3], + public_input: vec![4, 5, 6], + cpu_air_prover_config: vec![7, 8, 9], + cpu_air_params: vec![10, 11, 12], + }; + let serialized_job = (job).serialize_job(); + send_topic_tx.send(serialized_job).await?; }, Some(event) = message_stream.next() => { info!("{:?}", event); diff --git a/crates/executor/src/main.rs b/crates/executor/src/main.rs index 422d2c6..ff1974a 100644 --- a/crates/executor/src/main.rs +++ b/crates/executor/src/main.rs @@ -1,4 +1,6 @@ use futures_util::StreamExt; +use libp2p::gossipsub::Event; +use sharp_p2p_common::job::Job; use sharp_p2p_common::network::Network; use sharp_p2p_common::topic::{gossipsub_ident_topic, Topic}; use sharp_p2p_peer::registry::RegistryHandler; @@ -40,7 +42,27 @@ async fn main() -> Result<(), Box> { send_topic_tx.send(line.as_bytes().to_vec()).await?; }, Some(event) = message_stream.next() => { - info!("{:?}", event); + match event { + Event::Message { message, .. } => { + // Received a new-job message from the network + if message.topic == gossipsub_ident_topic(Network::Sepolia, Topic::NewJob).into() { + let deserialized_job = Job::deserialize_job(&message.data); + info!("Received a new job: {:?}", deserialized_job); + } + // Received a picked-job message from the network + if message.topic == gossipsub_ident_topic(Network::Sepolia, Topic::PickedJob).into() { + + info!("Received a picked job: {:?}", message); + } + }, + Event::Subscribed { peer_id, topic } => { + info!("{} subscribed to the topic {}", peer_id.to_string(), topic.to_string()); + }, + Event::Unsubscribed { peer_id, topic }=> { + info!("{} unsubscribed to the topic {}", peer_id.to_string(), topic.to_string()); + }, + _ => {} + } }, Some(Ok(event_vec)) = event_stream.next() => { info!("{:?}", event_vec); From 3b9c67b1e751b7288a6f6ae9dcbcdfd6b3961f41 Mon Sep 17 00:00:00 2001 From: Pia Date: Fri, 19 Apr 2024 12:21:56 +0900 Subject: [PATCH 2/8] job --- crates/common/src/job.rs | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/crates/common/src/job.rs b/crates/common/src/job.rs index 0e6238d..a4ecea4 100644 --- a/crates/common/src/job.rs +++ b/crates/common/src/job.rs @@ -1,4 +1,4 @@ -use libsecp256k1::{PublicKey, Signature}; +use libsecp256k1::{curve::Scalar, sign, PublicKey, SecretKey, Signature}; use std::{ fmt::Display, hash::{DefaultHasher, Hash, Hasher}, @@ -18,6 +18,24 @@ pub struct Job { pub cpu_air_prover_config: Vec, // needed for proving } +impl Default for Job { + fn default() -> Self { + let secret_key = &SecretKey::default(); + let public_key = PublicKey::from_secret_key(secret_key); + let (signature, _recovery_id) = + sign(&libsecp256k1::Message(Scalar([0, 0, 0, 0, 0, 0, 0, 0])), secret_key); + Self { + reward: 0, + num_of_steps: 0, + cairo_pie: vec![1, 2, 3], + public_key, + signature, + cpu_air_params: vec![1, 2, 3], + cpu_air_prover_config: vec![1, 2, 3], + } + } +} + impl Hash for Job { fn hash(&self, state: &mut H) { self.reward.hash(state); @@ -34,12 +52,12 @@ impl Display for Job { } } -impl Job { - pub fn serialize_job(&self) -> Vec { - bincode::serialize(self).unwrap() - } +// impl Job { +// pub fn serialize_job(&self) -> Vec { +// bincode::serialize(self).unwrap() +// } - pub fn deserialize_job(serialized_job: &[u8]) -> Self { - bincode::deserialize(serialized_job).unwrap() - } -} +// pub fn deserialize_job(serialized_job: &[u8]) -> Self { +// bincode::deserialize(serialized_job).unwrap() +// } +// } From 82c3df92555d833473804852fa0c23dfd5b06a6a Mon Sep 17 00:00:00 2001 From: Pia Date: Fri, 19 Apr 2024 12:24:53 +0900 Subject: [PATCH 3/8] job --- crates/delegator/src/main.rs | 12 ++---------- crates/executor/src/main.rs | 4 ++-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/crates/delegator/src/main.rs b/crates/delegator/src/main.rs index f527308..5ed7d4a 100644 --- a/crates/delegator/src/main.rs +++ b/crates/delegator/src/main.rs @@ -39,16 +39,8 @@ async fn main() -> Result<(), Box> { tokio::select! { Ok(Some(_)) = stdin.next_line() => { // TODO: Turn this into a real job generation - let job = Job { - reward: 100, - num_of_steps: 10, - private_input: vec![1, 2, 3], - public_input: vec![4, 5, 6], - cpu_air_prover_config: vec![7, 8, 9], - cpu_air_params: vec![10, 11, 12], - }; - let serialized_job = (job).serialize_job(); - send_topic_tx.send(serialized_job).await?; + + send_topic_tx.send([1,2, 3].to_vec()).await?; }, Some(event) = message_stream.next() => { info!("{:?}", event); diff --git a/crates/executor/src/main.rs b/crates/executor/src/main.rs index ff1974a..067adf2 100644 --- a/crates/executor/src/main.rs +++ b/crates/executor/src/main.rs @@ -46,8 +46,8 @@ async fn main() -> Result<(), Box> { Event::Message { message, .. } => { // Received a new-job message from the network if message.topic == gossipsub_ident_topic(Network::Sepolia, Topic::NewJob).into() { - let deserialized_job = Job::deserialize_job(&message.data); - info!("Received a new job: {:?}", deserialized_job); + + info!("Received a new job: {:?}", message); } // Received a picked-job message from the network if message.topic == gossipsub_ident_topic(Network::Sepolia, Topic::PickedJob).into() { From c7f229d588b425c5e9682a3e67f1cd6c78999abf Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Fri, 19 Apr 2024 08:26:10 +0200 Subject: [PATCH 4/8] renames & comments --- crates/common/src/job.rs | 15 +++++++++------ crates/common/src/job_witness.rs | 2 +- crates/delegator/src/main.rs | 1 - crates/executor/src/main.rs | 1 - crates/prover/src/stone_prover/mod.rs | 14 +++++++------- crates/prover/src/traits.rs | 4 ++-- crates/runner/src/cairo_runner/mod.rs | 6 +++--- crates/runner/src/traits.rs | 4 ++-- crates/runner/src/types/input.rs | 2 +- crates/runner/src/types/layout.rs | 2 +- 10 files changed, 26 insertions(+), 25 deletions(-) diff --git a/crates/common/src/job.rs b/crates/common/src/job.rs index a4ecea4..a528df0 100644 --- a/crates/common/src/job.rs +++ b/crates/common/src/job.rs @@ -9,13 +9,16 @@ use crate::hash; #[derive(Debug, PartialEq, Eq, Clone)] pub struct Job { pub reward: u32, - pub num_of_steps: u32, - pub cairo_pie: Vec, - pub public_key: PublicKey, - pub signature: Signature, + pub num_of_steps: u32, // executor needs to make sure that this num of steps are >= real ones if not executor can charge a fee on delegator in Registry (added in future) + pub cairo_pie: Vec, // zip format compressed bytes, no point in inflating it in RAM + pub public_key: PublicKey, // used it bootloader stage to confirm Job<->Delegator auth + pub signature: Signature, // used it bootloader stage to confirm Job<->Delegator auth // below fields not bounded by signature - pub cpu_air_params: Vec, // needed for proving - pub cpu_air_prover_config: Vec, // needed for proving + // needed for proving, + // prover can falsify it but it is executor responsibility so that the proof passes the verifier checks, + // Delegator is interested only in succesfull proof verification and output of the job + pub cpu_air_params: Vec, // JSON file serialized + pub cpu_air_prover_config: Vec, // JSON file serialized } impl Default for Job { diff --git a/crates/common/src/job_witness.rs b/crates/common/src/job_witness.rs index a038193..0d608e8 100644 --- a/crates/common/src/job_witness.rs +++ b/crates/common/src/job_witness.rs @@ -7,7 +7,7 @@ use std::{ #[derive(Debug, PartialEq, Eq, Hash, Clone)] pub struct JobWitness { - pub data: Vec, + pub proof: Vec, } impl Display for JobWitness { diff --git a/crates/delegator/src/main.rs b/crates/delegator/src/main.rs index 5ed7d4a..6e56912 100644 --- a/crates/delegator/src/main.rs +++ b/crates/delegator/src/main.rs @@ -1,5 +1,4 @@ use futures_util::StreamExt; -use sharp_p2p_common::job::Job; use sharp_p2p_common::network::Network; use sharp_p2p_common::topic::{gossipsub_ident_topic, Topic}; use sharp_p2p_peer::registry::RegistryHandler; diff --git a/crates/executor/src/main.rs b/crates/executor/src/main.rs index 067adf2..5efd067 100644 --- a/crates/executor/src/main.rs +++ b/crates/executor/src/main.rs @@ -1,6 +1,5 @@ use futures_util::StreamExt; use libp2p::gossipsub::Event; -use sharp_p2p_common::job::Job; use sharp_p2p_common::network::Network; use sharp_p2p_common::topic::{gossipsub_ident_topic, Topic}; use sharp_p2p_peer::registry::RegistryHandler; diff --git a/crates/prover/src/stone_prover/mod.rs b/crates/prover/src/stone_prover/mod.rs index efad759..d767473 100644 --- a/crates/prover/src/stone_prover/mod.rs +++ b/crates/prover/src/stone_prover/mod.rs @@ -71,10 +71,10 @@ impl ProverController for StoneProver { .await?; trace!("task {} output {:?}", job_trace_hash, task_output); - let mut input = String::new(); - out_file.read_to_string(&mut input)?; + let mut raw_proof = String::new(); + out_file.read_to_string(&mut raw_proof)?; - let parsed_proof = cairo_proof_parser::parse(input) + let parsed_proof = cairo_proof_parser::parse(raw_proof) .map_err(|e| ProverControllerError::ProofParseError(e.to_string()))?; let config: VecFelt252 = serde_json::from_str(&parsed_proof.config.to_string())?; @@ -84,7 +84,7 @@ impl ProverController for StoneProver { serde_json::from_str(&parsed_proof.unsent_commitment.to_string())?; let witness: VecFelt252 = serde_json::from_str(&parsed_proof.witness.to_string())?; - let data = chain!( + let proof = chain!( config.into_iter(), public_input.into_iter(), unsent_commitment.into_iter(), @@ -92,10 +92,10 @@ impl ProverController for StoneProver { ) .collect_vec(); - Ok(JobWitness { data }) + Ok(JobWitness { proof }) } - async fn terminate(&mut self, job_trace_hash: u64) -> Result<(), ProverControllerError> { + fn terminate(&mut self, job_trace_hash: u64) -> Result<(), ProverControllerError> { self.tasks .get_mut(&job_trace_hash) .ok_or(ProverControllerError::TaskNotFound)? @@ -104,7 +104,7 @@ impl ProverController for StoneProver { Ok(()) } - async fn drop(mut self) -> Result<(), ProverControllerError> { + fn drop(mut self) -> Result<(), ProverControllerError> { let keys: Vec = self.tasks.keys().cloned().collect(); for job_trace_hash in keys.iter() { self.tasks diff --git a/crates/prover/src/traits.rs b/crates/prover/src/traits.rs index 2d78f22..d4ad171 100644 --- a/crates/prover/src/traits.rs +++ b/crates/prover/src/traits.rs @@ -7,6 +7,6 @@ pub trait Prover { pub trait ProverController { async fn prove(&mut self, job_trace: JobTrace) -> Result; - async fn terminate(&mut self, job_trace_hash: u64) -> Result<(), ProverControllerError>; - async fn drop(self) -> Result<(), ProverControllerError>; + fn terminate(&mut self, job_trace_hash: u64) -> Result<(), ProverControllerError>; + fn drop(self) -> Result<(), ProverControllerError>; } diff --git a/crates/runner/src/cairo_runner/mod.rs b/crates/runner/src/cairo_runner/mod.rs index 0702b1d..73aaabb 100644 --- a/crates/runner/src/cairo_runner/mod.rs +++ b/crates/runner/src/cairo_runner/mod.rs @@ -29,7 +29,7 @@ impl Runner for CairoRunner { impl RunnerController for CairoRunner { async fn run(&mut self, job: Job) -> Result { let program = NamedTempFile::new()?; - let layout: &str = Layout::Recursive.into(); + let layout: &str = Layout::RecursiveWithPoseidon.into(); let mut cairo_pie = NamedTempFile::new()?; cairo_pie.write_all(&job.cairo_pie)?; @@ -101,13 +101,13 @@ impl RunnerController for CairoRunner { }) } - async fn terminate(&mut self, job_hash: u64) -> Result<(), RunnerControllerError> { + fn terminate(&mut self, job_hash: u64) -> Result<(), RunnerControllerError> { self.tasks.get_mut(&job_hash).ok_or(RunnerControllerError::TaskNotFound)?.start_kill()?; trace!("task scheduled for termination {}", job_hash); Ok(()) } - async fn drop(mut self) -> Result<(), RunnerControllerError> { + fn drop(mut self) -> Result<(), RunnerControllerError> { let keys: Vec = self.tasks.keys().cloned().collect(); for job_hash in keys.iter() { self.tasks diff --git a/crates/runner/src/traits.rs b/crates/runner/src/traits.rs index fe748e4..fc0e183 100644 --- a/crates/runner/src/traits.rs +++ b/crates/runner/src/traits.rs @@ -8,6 +8,6 @@ pub trait Runner { pub trait RunnerController { async fn run(&mut self, job: Job) -> Result; - async fn terminate(&mut self, job_hash: u64) -> Result<(), RunnerControllerError>; - async fn drop(self) -> Result<(), RunnerControllerError>; + fn terminate(&mut self, job_hash: u64) -> Result<(), RunnerControllerError>; + fn drop(self) -> Result<(), RunnerControllerError>; } diff --git a/crates/runner/src/types/input.rs b/crates/runner/src/types/input.rs index af01ee3..0578b86 100644 --- a/crates/runner/src/types/input.rs +++ b/crates/runner/src/types/input.rs @@ -17,7 +17,7 @@ pub struct BootloaderInput { impl Default for Task { fn default() -> Self { - Self { type_: "CairoPiePath".to_string(), path: PathBuf::default(), use_poseidon: false } + Self { type_: "CairoPiePath".to_string(), path: PathBuf::default(), use_poseidon: true } } } diff --git a/crates/runner/src/types/layout.rs b/crates/runner/src/types/layout.rs index d7edd3f..02153f0 100644 --- a/crates/runner/src/types/layout.rs +++ b/crates/runner/src/types/layout.rs @@ -3,5 +3,5 @@ use strum::IntoStaticStr; #[derive(Debug, PartialEq, IntoStaticStr)] #[strum(serialize_all = "snake_case")] pub enum Layout { - Recursive, + RecursiveWithPoseidon, } From f1c1cafccbcddb93968b56a6e0b06c397bf8fca2 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Fri, 19 Apr 2024 09:01:57 +0200 Subject: [PATCH 5/8] install script & build.rs checks --- .gitignore | 2 ++ crates/prover/build.rs | 9 +++++++++ crates/runner/build.rs | 15 +++++++++++++++ install.py | 42 ++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 3 +++ 5 files changed, 71 insertions(+) create mode 100644 crates/prover/build.rs create mode 100644 crates/runner/build.rs create mode 100644 install.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 4a5cef6..9c81814 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ Cargo.lock Scarb.lock .snfoundry_cache/ + +stone-prover \ No newline at end of file diff --git a/crates/prover/build.rs b/crates/prover/build.rs new file mode 100644 index 0000000..c31b021 --- /dev/null +++ b/crates/prover/build.rs @@ -0,0 +1,9 @@ +use std::process::Command; + +fn main() { + // Check if stone-prover command is present + Command::new("cpu_air_prover") + .arg("--help") + .output() + .expect("Failed to execute cpu_air_prover command"); +} diff --git a/crates/runner/build.rs b/crates/runner/build.rs new file mode 100644 index 0000000..7d14d34 --- /dev/null +++ b/crates/runner/build.rs @@ -0,0 +1,15 @@ +use std::process::Command; + +fn main() { + // Check if cairo-run command is present + Command::new("cairo-run") + .arg("--version") + .output() + .expect("Failed to execute cairo-run command"); + + // Check if cairo-compile command is present + Command::new("cairo-compile") + .arg("--version") + .output() + .expect("Failed to execute cairo-compile command"); +} diff --git a/install.py b/install.py new file mode 100644 index 0000000..485f661 --- /dev/null +++ b/install.py @@ -0,0 +1,42 @@ +import subprocess + + +def log_and_run(commands, description, cwd=None): + full_command = " && ".join(commands) + try: + print(f"{Fore.YELLOW}Starting: {description}...{Style.RESET_ALL}") + print(f"{Fore.CYAN}Command: {full_command}{Style.RESET_ALL}") + result = subprocess.run( + full_command, shell=True, check=True, cwd=cwd, text=True + ) + print(f"{Fore.GREEN}Success: {description} completed!\n{Style.RESET_ALL}") + except subprocess.CalledProcessError as e: + print( + f"{Fore.RED}Error running command '{full_command}': {e}\n{Style.RESET_ALL}" + ) + + +if __name__ == "__main__": + subprocess.run(["pip", "install", "-r", "requirements.txt"], check=True) + from colorama import Fore, Style + + log_and_run(["pip install cairo/"], "Install bootloader package", cwd=".") + + log_and_run( + [ + "git clone https://github.com/starkware-libs/stone-prover.git", + ], + "Clone stone-prover", + cwd=".", + ) + + log_and_run( + [ + "docker build --tag prover .", + "container_id=$(docker create prover)", + "docker cp -L ${container_id}:/bin/cpu_air_prover $HOME/.local/bin", + "docker cp -L ${container_id}:/bin/cpu_air_verifier $HOME/.local/bin", + ], + "Build & Install stone-prover", + cwd="stone-prover", + ) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ef6a516 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +aiofiles==23.2.1 +cairo-lang==0.13.1 +colorama==0.4.6 \ No newline at end of file From 8d476f9f0f588e3c3733e0ce6fd8daba30a2882c Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Fri, 19 Apr 2024 11:15:14 +0200 Subject: [PATCH 6/8] comments --- crates/common/src/job.rs | 33 ++++++++++++++------------- crates/common/src/job_trace.rs | 18 ++++++++------- crates/common/src/job_witness.rs | 9 +++++++- crates/prover/src/stone_prover/mod.rs | 7 ++++-- crates/runner/src/cairo_runner/mod.rs | 14 +----------- 5 files changed, 41 insertions(+), 40 deletions(-) diff --git a/crates/common/src/job.rs b/crates/common/src/job.rs index a528df0..392fd13 100644 --- a/crates/common/src/job.rs +++ b/crates/common/src/job.rs @@ -1,24 +1,27 @@ +use crate::hash; use libsecp256k1::{curve::Scalar, sign, PublicKey, SecretKey, Signature}; use std::{ fmt::Display, hash::{DefaultHasher, Hash, Hasher}, }; -use crate::hash; +/* + Job Object + This object represents a task requested by a delegator. + It contains metadata that allows the executor to decide if the task is attractive enough to run. + It includes a pie object that holds the task bytecode itself. + Additionally, the object holds the signature and public key of the delegator, enabling the executor to prove to the Registry that the task was intended by the delegator. + The Job object also includes the target registry where the delegator expects this proof to be verified. +*/ #[derive(Debug, PartialEq, Eq, Clone)] pub struct Job { - pub reward: u32, - pub num_of_steps: u32, // executor needs to make sure that this num of steps are >= real ones if not executor can charge a fee on delegator in Registry (added in future) - pub cairo_pie: Vec, // zip format compressed bytes, no point in inflating it in RAM - pub public_key: PublicKey, // used it bootloader stage to confirm Job<->Delegator auth - pub signature: Signature, // used it bootloader stage to confirm Job<->Delegator auth - // below fields not bounded by signature - // needed for proving, - // prover can falsify it but it is executor responsibility so that the proof passes the verifier checks, - // Delegator is interested only in succesfull proof verification and output of the job - pub cpu_air_params: Vec, // JSON file serialized - pub cpu_air_prover_config: Vec, // JSON file serialized + pub reward: u32, // The reward offered for completing the task + pub num_of_steps: u32, // The number of steps expected to complete the task (executor ensures that this number is greater than or equal to the actual steps; in the future, the executor may charge a fee to the delegator if not met) + pub cairo_pie: Vec, // The task bytecode in compressed zip format, to conserve memory + pub registry_address: String, // The address of the registry contract where the delegator expects the proof to be verified + pub public_key: PublicKey, // The public key of the delegator, used in the bootloader stage to confirm authenticity of the Job<->Delegator relationship + pub signature: Signature, // The signature of the delegator, used in the bootloader stage to confirm authenticity of the Job<->Delegator relationship } impl Default for Job { @@ -33,8 +36,7 @@ impl Default for Job { cairo_pie: vec![1, 2, 3], public_key, signature, - cpu_air_params: vec![1, 2, 3], - cpu_air_prover_config: vec![1, 2, 3], + registry_address: "0x0".to_string(), } } } @@ -44,8 +46,7 @@ impl Hash for Job { 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); + self.registry_address.hash(state); } } diff --git a/crates/common/src/job_trace.rs b/crates/common/src/job_trace.rs index bd7c627..f5870ea 100644 --- a/crates/common/src/job_trace.rs +++ b/crates/common/src/job_trace.rs @@ -5,14 +5,18 @@ use std::{ }; use tempfile::NamedTempFile; +/* + Job Trace Object + This object represents the output from the Cairo run process in proof mode. + It includes objects such as public input, private input, trace, and memory. +*/ + #[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, + pub air_public_input: NamedTempFile, // Temporary file containing the public input + pub air_private_input: NamedTempFile, // Temporary file containing the private input; memory and trace files must exist for this to be valid + pub memory: NamedTempFile, // Temporary file containing memory data (required for air_private_input validity) + pub trace: NamedTempFile, // Temporary file containing trace data (required for air_private_input validity) } impl Hash for JobTrace { @@ -21,8 +25,6 @@ impl Hash for JobTrace { 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); } } diff --git a/crates/common/src/job_witness.rs b/crates/common/src/job_witness.rs index 0d608e8..59d04b0 100644 --- a/crates/common/src/job_witness.rs +++ b/crates/common/src/job_witness.rs @@ -5,9 +5,16 @@ use std::{ hash::{DefaultHasher, Hash, Hasher}, }; +/* + Job Witness Object + This object represents the output from the proving process. + It holds a serialized proof as an array of Felt252 objects. + This serialized proof can be deserialized into a StarkProof object by the verifier to proceed with the verification of the statement. +*/ + #[derive(Debug, PartialEq, Eq, Hash, Clone)] pub struct JobWitness { - pub proof: Vec, + pub proof: Vec, // Serialized proof } impl Display for JobWitness { diff --git a/crates/prover/src/stone_prover/mod.rs b/crates/prover/src/stone_prover/mod.rs index d767473..457d89d 100644 --- a/crates/prover/src/stone_prover/mod.rs +++ b/crates/prover/src/stone_prover/mod.rs @@ -27,6 +27,9 @@ impl ProverController for StoneProver { async fn prove(&mut self, job_trace: JobTrace) -> Result { let mut out_file = NamedTempFile::new()?; + let cpu_air_prover_config = NamedTempFile::new()?; // TODO implement default config and getting info from integrity verifier + let cpu_air_params = NamedTempFile::new()?; // TODO implement default config and getting info from integrity verifier + let task = Command::new("cpu_air_prover") .args(["--out_file", out_file.path().to_string_lossy().as_ref()]) .args([ @@ -39,9 +42,9 @@ impl ProverController for StoneProver { ]) .args([ "--cpu_air_prover_config", - job_trace.cpu_air_prover_config.path().to_string_lossy().as_ref(), + cpu_air_prover_config.path().to_string_lossy().as_ref(), ]) - .args(["--cpu_air_params", job_trace.cpu_air_params.path().to_string_lossy().as_ref()]) + .args(["--cpu_air_params", cpu_air_params.path().to_string_lossy().as_ref()]) .arg("--generate_annotations") .spawn()?; diff --git a/crates/runner/src/cairo_runner/mod.rs b/crates/runner/src/cairo_runner/mod.rs index 73aaabb..1ca896f 100644 --- a/crates/runner/src/cairo_runner/mod.rs +++ b/crates/runner/src/cairo_runner/mod.rs @@ -86,19 +86,7 @@ impl RunnerController for CairoRunner { .await?; trace!("task {} output {:?}", job_hash, task_output); - let mut cpu_air_params = NamedTempFile::new()?; - let mut cpu_air_prover_config = NamedTempFile::new()?; - cpu_air_params.write_all(&job.cpu_air_params)?; - cpu_air_prover_config.write_all(&job.cpu_air_prover_config)?; - - Ok(JobTrace { - air_public_input, - air_private_input, - memory, - trace, - cpu_air_prover_config, - cpu_air_params, - }) + Ok(JobTrace { air_public_input, air_private_input, memory, trace }) } fn terminate(&mut self, job_hash: u64) -> Result<(), RunnerControllerError> { From 381046bb1dc2683ec99f410c0a9876ff0fea465a Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Fri, 19 Apr 2024 11:24:24 +0200 Subject: [PATCH 7/8] suppress stone-prover --- crates/prover/build.rs | 10 +++++----- install.py | 34 +++++++++++++++++----------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/crates/prover/build.rs b/crates/prover/build.rs index c31b021..5942213 100644 --- a/crates/prover/build.rs +++ b/crates/prover/build.rs @@ -1,9 +1,9 @@ -use std::process::Command; +// use std::process::Command; fn main() { // Check if stone-prover command is present - Command::new("cpu_air_prover") - .arg("--help") - .output() - .expect("Failed to execute cpu_air_prover command"); + // Command::new("cpu_air_prover") + // .arg("--help") + // .output() + // .expect("Failed to execute cpu_air_prover command"); } diff --git a/install.py b/install.py index 485f661..cda2650 100644 --- a/install.py +++ b/install.py @@ -22,21 +22,21 @@ def log_and_run(commands, description, cwd=None): log_and_run(["pip install cairo/"], "Install bootloader package", cwd=".") - log_and_run( - [ - "git clone https://github.com/starkware-libs/stone-prover.git", - ], - "Clone stone-prover", - cwd=".", - ) + # log_and_run( + # [ + # "git clone https://github.com/starkware-libs/stone-prover.git", + # ], + # "Clone stone-prover", + # cwd=".", + # ) - log_and_run( - [ - "docker build --tag prover .", - "container_id=$(docker create prover)", - "docker cp -L ${container_id}:/bin/cpu_air_prover $HOME/.local/bin", - "docker cp -L ${container_id}:/bin/cpu_air_verifier $HOME/.local/bin", - ], - "Build & Install stone-prover", - cwd="stone-prover", - ) + # log_and_run( + # [ + # "docker build --tag prover .", + # "container_id=$(docker create prover)", + # "docker cp -L ${container_id}:/bin/cpu_air_prover $HOME/.local/bin", + # "docker cp -L ${container_id}:/bin/cpu_air_verifier $HOME/.local/bin", + # ], + # "Build & Install stone-prover", + # cwd="stone-prover", + # ) From 44952925424e0d7b26140b4409933d5c089d0226 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Fri, 19 Apr 2024 11:32:02 +0200 Subject: [PATCH 8/8] ci install python script --- .github/workflows/test.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c17ed75..2ebc201 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -19,6 +19,14 @@ jobs: - name: Setup Starknet Foundry uses: foundry-rs/setup-snfoundry@v3 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.9' + + - name: Provision Environment + run: python install.py - name: Format code run: cargo fmt --check