diff --git a/.dockerignore b/.dockerignore index f512bb7..569b45c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,32 @@ -target -*docker* \ No newline at end of file +# Ignore Python virtual environment +venv/ +env/ + +# Ignore Rust-related files +debug/ +target/ +Cargo.lock +*.rs.bk +*.pdb +/target +Scarb.lock +.snfoundry_cache/ +stone-prover +bootloader*.json + +# Ignore Python-specific files +*.pyc +__pycache__/ +dist/ +build/ +*.egg-info/ + +# Ignore IPython/Jupyter Notebook checkpoints +.ipynb_checkpoints/ + +# Additional Docker-specific ignores +.dockerignore +.dockerignore.template +.dockerignore.generated +.dockerignore.custom +.dockerignore.local diff --git a/.gitignore b/.gitignore index 14600fe..ea0e9bf 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,23 @@ Scarb.lock stone-prover -bootloader*.json \ No newline at end of file +bootloader*.json + +# Python +*.pyc +__pycache__/ +venv/ +env/ +dist/ +build/ +*.egg-info/ + +# PyInstaller +dist/ +build/ + +# IPython Notebook +.ipynb_checkpoints + +# Jupyter Notebook +.ipynb_checkpoints/ diff --git a/crates/delegator/src/delegator.rs b/crates/delegator/src/delegator.rs index 1c304ff..8a71855 100644 --- a/crates/delegator/src/delegator.rs +++ b/crates/delegator/src/delegator.rs @@ -1,13 +1,12 @@ -use futures::executor::block_on; use libp2p::gossipsub::Event; use std::hash::{DefaultHasher, Hash, Hasher}; use tokio::{ sync::{broadcast, mpsc}, task::JoinHandle, }; -use tokio_util::sync::CancellationToken; use tracing::info; use zetina_common::{ + graceful_shutdown::shutdown_signal, hash, job::Job, job_witness::JobWitness, @@ -16,7 +15,6 @@ use zetina_common::{ }; pub struct Delegator { - cancellation_token: CancellationToken, handle: Option>>, } @@ -25,10 +23,7 @@ impl Delegator { job_witness_tx: broadcast::Sender, mut events_rx: mpsc::Receiver, ) -> Self { - let cancellation_token = CancellationToken::new(); - Self { - cancellation_token: cancellation_token.to_owned(), handle: Some(tokio::spawn(async move { loop { tokio::select! { @@ -48,7 +43,7 @@ impl Delegator { // Received a finished-job message from the network if message.topic == gossipsub_ident_topic(Network::Sepolia, Topic::FinishedJob).into() { let job_witness: JobWitness = serde_json::from_slice(&message.data)?; - info!("Received finished job event: {}", hash!(&job_witness)); + info!("Received finished job event: {}", &job_witness.job_hash); job_witness_tx.send(job_witness)?; } }, @@ -61,7 +56,7 @@ impl Delegator { _ => {} } }, - _ = cancellation_token.cancelled() => { + _ = shutdown_signal() => { break } else => break @@ -75,12 +70,12 @@ impl Delegator { impl Drop for Delegator { fn drop(&mut self) { - self.cancellation_token.cancel(); - block_on(async move { - if let Some(handle) = self.handle.take() { + let handle = self.handle.take(); + tokio::spawn(async move { + if let Some(handle) = handle { handle.await.unwrap().unwrap(); } - }) + }); } } diff --git a/crates/delegator/src/swarm.rs b/crates/delegator/src/swarm.rs index d0ae025..0682280 100644 --- a/crates/delegator/src/swarm.rs +++ b/crates/delegator/src/swarm.rs @@ -1,16 +1,14 @@ -pub mod event_loop; - -use event_loop::swarm_loop; -use futures::executor::block_on; -use futures::FutureExt; +use futures::StreamExt; use libp2p::gossipsub::{self, IdentTopic}; use libp2p::identity::Keypair; -use libp2p::swarm::NetworkBehaviour; +use libp2p::swarm::{NetworkBehaviour, SwarmEvent}; use libp2p::{mdns, noise, tcp, yamux, SwarmBuilder}; use std::error::Error; use std::time::Duration; use tokio::sync::mpsc; use tokio::task::JoinHandle; +use tracing::{debug, error}; +use zetina_common::graceful_shutdown::shutdown_signal; #[derive(NetworkBehaviour)] pub struct PeerBehaviour { @@ -26,7 +24,7 @@ impl SwarmRunner { pub fn new( p2p_local_keypair: &Keypair, subscribe_topics: Vec, - transmit_topics: Vec<(IdentTopic, mpsc::Receiver>)>, + mut transmit_topics: Vec<(IdentTopic, mpsc::Receiver>)>, swarm_events_tx: mpsc::Sender, ) -> Result> { let mdns = mdns::tokio::Behaviour::new( @@ -38,7 +36,11 @@ impl SwarmRunner { let local_keypair = p2p_local_keypair.clone(); let mut swarm = SwarmBuilder::with_existing_identity(local_keypair) .with_tokio() - .with_tcp(tcp::Config::default(), noise::Config::new, yamux::Config::default)? + .with_tcp( + tcp::Config::default().port_reuse(true), + noise::Config::new, + yamux::Config::default, + )? .with_quic() .with_behaviour(|_| behaviour)? .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) @@ -53,7 +55,47 @@ impl SwarmRunner { Ok(SwarmRunner { handle: Some(tokio::spawn(async move { - swarm_loop(swarm, transmit_topics, swarm_events_tx).boxed().await + loop { + tokio::select! { + Some(data) = transmit_topics[0].1.recv() => { + debug!("Publishing to topic: {:?}", transmit_topics[0].0); + if let Err(e) = swarm + .behaviour_mut().gossipsub + .publish(transmit_topics[0].0.clone(), data) { + error!("Publish error: {e:?}"); + } + }, + event = swarm.select_next_some() => match event { + SwarmEvent::Behaviour(PeerBehaviourEvent::Mdns(mdns::Event::Discovered(list))) => { + for (peer_id, _multiaddr) in list { + debug!("mDNS discovered a new peer: {peer_id}"); + swarm.behaviour_mut().gossipsub.add_explicit_peer(&peer_id); + } + }, + SwarmEvent::Behaviour(PeerBehaviourEvent::Mdns(mdns::Event::Expired(list))) => { + for (peer_id, _multiaddr) in list { + debug!("mDNS discover peer has expired: {peer_id}"); + swarm.behaviour_mut().gossipsub.remove_explicit_peer(&peer_id); + } + }, + SwarmEvent::Behaviour(PeerBehaviourEvent::Gossipsub(gossipsub::Event::Message { + propagation_source, + message_id, + message, + })) => { + swarm_events_tx.send(gossipsub::Event::Message { propagation_source, message_id, message }).await.unwrap(); + }, + SwarmEvent::NewListenAddr { address, .. } => { + debug!("Local node is listening on {address}"); + } + _ => {} + }, + _ = shutdown_signal() => { + break + } + else => break + } + } })), }) } @@ -74,10 +116,11 @@ impl SwarmRunner { impl Drop for SwarmRunner { fn drop(&mut self) { - block_on(async move { - if let Some(handle) = self.handle.take() { + let handle = self.handle.take(); + tokio::spawn(async move { + if let Some(handle) = handle { handle.await.unwrap(); } - }) + }); } } diff --git a/crates/delegator/src/swarm/event_loop.rs b/crates/delegator/src/swarm/event_loop.rs deleted file mode 100644 index ec8351c..0000000 --- a/crates/delegator/src/swarm/event_loop.rs +++ /dev/null @@ -1,59 +0,0 @@ -use super::PeerBehaviour; -use crate::swarm::PeerBehaviourEvent; -use futures::StreamExt; -use libp2p::{ - gossipsub::{self, IdentTopic}, - mdns, - swarm::SwarmEvent, - Swarm, -}; -use tokio::sync::mpsc::{self, Receiver}; -use tracing::{debug, error}; -use zetina_common::graceful_shutdown::shutdown_signal; - -pub(crate) async fn swarm_loop( - mut swarm: Swarm, - mut transmit_topics: Vec<(IdentTopic, Receiver>)>, - swarm_events_tx: mpsc::Sender, -) { - loop { - tokio::select! { - Some(data) = transmit_topics[0].1.recv() => { - debug!("Publishing to topic: {:?}", transmit_topics[0].0); - if let Err(e) = swarm - .behaviour_mut().gossipsub - .publish(transmit_topics[0].0.clone(), data) { - error!("Publish error: {e:?}"); - } - }, - event = swarm.select_next_some() => match event { - SwarmEvent::Behaviour(PeerBehaviourEvent::Mdns(mdns::Event::Discovered(list))) => { - for (peer_id, _multiaddr) in list { - debug!("mDNS discovered a new peer: {peer_id}"); - swarm.behaviour_mut().gossipsub.add_explicit_peer(&peer_id); - } - }, - SwarmEvent::Behaviour(PeerBehaviourEvent::Mdns(mdns::Event::Expired(list))) => { - for (peer_id, _multiaddr) in list { - debug!("mDNS discover peer has expired: {peer_id}"); - swarm.behaviour_mut().gossipsub.remove_explicit_peer(&peer_id); - } - }, - SwarmEvent::Behaviour(PeerBehaviourEvent::Gossipsub(gossipsub::Event::Message { - propagation_source, - message_id, - message, - })) => { - swarm_events_tx.send(gossipsub::Event::Message { propagation_source, message_id, message }).await.unwrap(); - }, - SwarmEvent::NewListenAddr { address, .. } => { - debug!("Local node is listening on {address}"); - } - _ => {} - }, - _ = shutdown_signal() => { - break - } - } - } -} diff --git a/crates/delegator/src/tonic.rs b/crates/delegator/src/tonic.rs index 9cef8e8..a37c991 100644 --- a/crates/delegator/src/tonic.rs +++ b/crates/delegator/src/tonic.rs @@ -10,12 +10,9 @@ use starknet::signers::SigningKey; use std::collections::HashSet; use std::hash::{DefaultHasher, Hash, Hasher}; use std::pin::Pin; -use tokio::{ - select, - sync::{broadcast, mpsc}, -}; +use tokio::sync::{broadcast, mpsc}; use tonic::{Request, Response, Status, Streaming}; -use tracing::{debug, info}; +use tracing::{debug, error, info}; use zetina_common::hash; use zetina_common::{ job::{Job, JobData}, @@ -55,14 +52,19 @@ impl DelegatorService for DelegatorGRPCServer { let out_stream = stream! { loop { - select! { - Ok(request) = in_stream.select_next_some() => { - let job_data = JobData::new(0, request.cairo_pie); - let job = Job::try_from_job_data(job_data, &signing_key); - queue_set.insert(hash!(job)); - let serialized_job = serde_json::to_string(&job).unwrap(); - job_channel.send(serialized_job.into()).await.unwrap(); - info!("Sent a new job: {}", hash!(&job)); + tokio::select! { + Some(request) = in_stream.next() => { + match request { + Ok(r) => { + let job_data = JobData::new(0, r.cairo_pie); + let job = Job::try_from_job_data(job_data, &signing_key); + queue_set.insert(hash!(job)); + let serialized_job = serde_json::to_string(&job).unwrap(); + job_channel.send(serialized_job.into()).await.unwrap(); + info!("Sent a new job: {}", hash!(&job)); + } + Err(err) => error!("Error: {}",err) + } } Ok(rx) = witness_channel.recv() => { debug!("Received job witness: {}", &rx.job_hash); @@ -72,6 +74,7 @@ impl DelegatorService for DelegatorGRPCServer { } } else => { + error!("Stream cancelled!"); yield Err(Status::cancelled("")) } } diff --git a/crates/executor/src/executor.rs b/crates/executor/src/executor.rs index 2aa3549..d6df707 100644 --- a/crates/executor/src/executor.rs +++ b/crates/executor/src/executor.rs @@ -1,11 +1,11 @@ +use futures::stream::FuturesUnordered; use futures::StreamExt; -use futures::{executor::block_on, stream::FuturesUnordered}; use libp2p::gossipsub::Event; use std::hash::{DefaultHasher, Hash, Hasher}; use tokio::{sync::mpsc, task::JoinHandle}; -use tokio_util::sync::CancellationToken; use tracing::info; use zetina_common::{ + graceful_shutdown::shutdown_signal, hash, job::Job, job_record::JobRecord, @@ -25,7 +25,6 @@ use zetina_runner::traits::RunnerController; const MAX_PARALLEL_JOBS: usize = 1; pub struct Executor { - cancellation_token: CancellationToken, handle: Option>>, } @@ -37,10 +36,7 @@ impl Executor { runner: CairoRunner, prover: StoneProver, ) -> Self { - let cancellation_token = CancellationToken::new(); - Self { - cancellation_token: cancellation_token.to_owned(), handle: Some(tokio::spawn(async move { let mut job_record = JobRecord::::new(); let mut runner_scheduler = @@ -78,15 +74,15 @@ impl Executor { } }, Some(Ok(job_trace)) = runner_scheduler.next() => { - info!("Scheduled proving of job_trace: {}", hash!(&job_trace)); + info!("Scheduled proving of job_trace: {}", &job_trace.job_hash); prover_scheduler.push(prover.run(job_trace)?); }, Some(Ok(job_witness)) = prover_scheduler.next() => { - info!("Calculated job_witness: {}", hash!(&job_witness)); + info!("Calculated job_witness: {}", &job_witness.job_hash); let serialized_job_witness = serde_json::to_string(&job_witness)?; finished_job_topic_tx.send(serialized_job_witness.into()).await?; }, - _ = cancellation_token.cancelled() => { + _ = shutdown_signal() => { break } else => break @@ -113,12 +109,12 @@ impl Executor { impl Drop for Executor { fn drop(&mut self) { - self.cancellation_token.cancel(); - block_on(async move { - if let Some(handle) = self.handle.take() { + let handle = self.handle.take(); + tokio::spawn(async move { + if let Some(handle) = handle { handle.await.unwrap().unwrap(); } - }) + }); } } diff --git a/crates/executor/src/swarm.rs b/crates/executor/src/swarm.rs index e9ee06e..1600dca 100644 --- a/crates/executor/src/swarm.rs +++ b/crates/executor/src/swarm.rs @@ -1,16 +1,14 @@ -pub mod event_loop; - -use event_loop::swarm_loop; -use futures::executor::block_on; -use futures::FutureExt; +use futures::StreamExt; use libp2p::gossipsub::{self, IdentTopic}; use libp2p::identity::Keypair; -use libp2p::swarm::NetworkBehaviour; +use libp2p::swarm::{NetworkBehaviour, SwarmEvent}; use libp2p::{mdns, noise, tcp, yamux, SwarmBuilder}; use std::error::Error; use std::time::Duration; use tokio::sync::mpsc; use tokio::task::JoinHandle; +use tracing::{debug, error}; +use zetina_common::graceful_shutdown::shutdown_signal; #[derive(NetworkBehaviour)] pub struct PeerBehaviour { @@ -26,7 +24,7 @@ impl SwarmRunner { pub fn new( p2p_local_keypair: &Keypair, subscribe_topics: Vec, - transmit_topics: Vec<(IdentTopic, mpsc::Receiver>)>, + mut transmit_topics: Vec<(IdentTopic, mpsc::Receiver>)>, swarm_events_tx: mpsc::Sender, ) -> Result> { let mdns = mdns::tokio::Behaviour::new( @@ -38,7 +36,11 @@ impl SwarmRunner { let local_keypair = p2p_local_keypair.clone(); let mut swarm = SwarmBuilder::with_existing_identity(local_keypair) .with_tokio() - .with_tcp(tcp::Config::default(), noise::Config::new, yamux::Config::default)? + .with_tcp( + tcp::Config::default().port_reuse(true), + noise::Config::new, + yamux::Config::default, + )? .with_quic() .with_behaviour(|_| behaviour)? .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) @@ -53,7 +55,58 @@ impl SwarmRunner { Ok(SwarmRunner { handle: Some(tokio::spawn(async move { - swarm_loop(swarm, transmit_topics, swarm_events_tx).boxed().await + // TODO make it nicer solution, extensible not manual! + let mut topic_one = transmit_topics.pop().unwrap(); + let mut topic_two = transmit_topics.pop().unwrap(); + loop { + tokio::select! { + Some(data) = topic_one.1.recv() => { + debug!("Publishing to topic: {:?}", topic_one.0); + if let Err(e) = swarm + .behaviour_mut().gossipsub + .publish(topic_one.0.clone(), data) { + error!("Publish error: {e:?}"); + } + }, + Some(data) = topic_two.1.recv() => { + debug!("Publishing to topic: {:?}", topic_two.0); + if let Err(e) = swarm + .behaviour_mut().gossipsub + .publish(topic_two.0.clone(), data) { + error!("Publish error: {e:?}"); + } + }, + event = swarm.select_next_some() => match event { + SwarmEvent::Behaviour(PeerBehaviourEvent::Mdns(mdns::Event::Discovered(list))) => { + for (peer_id, _multiaddr) in list { + debug!("mDNS discovered a new peer: {peer_id}"); + swarm.behaviour_mut().gossipsub.add_explicit_peer(&peer_id); + } + }, + SwarmEvent::Behaviour(PeerBehaviourEvent::Mdns(mdns::Event::Expired(list))) => { + for (peer_id, _multiaddr) in list { + debug!("mDNS discover peer has expired: {peer_id}"); + swarm.behaviour_mut().gossipsub.remove_explicit_peer(&peer_id); + } + }, + SwarmEvent::Behaviour(PeerBehaviourEvent::Gossipsub(gossipsub::Event::Message { + propagation_source, + message_id, + message, + })) => { + swarm_events_tx.send(gossipsub::Event::Message { propagation_source, message_id, message }).await.unwrap(); + }, + SwarmEvent::NewListenAddr { address, .. } => { + debug!("Local node is listening on {address}"); + } + _ => {} + }, + _ = shutdown_signal() => { + break + } + else => break + } + } })), }) } @@ -74,10 +127,11 @@ impl SwarmRunner { impl Drop for SwarmRunner { fn drop(&mut self) { - block_on(async move { - if let Some(handle) = self.handle.take() { + let handle = self.handle.take(); + tokio::spawn(async move { + if let Some(handle) = handle { handle.await.unwrap(); } - }) + }); } } diff --git a/crates/executor/src/swarm/event_loop.rs b/crates/executor/src/swarm/event_loop.rs deleted file mode 100644 index 0a9417f..0000000 --- a/crates/executor/src/swarm/event_loop.rs +++ /dev/null @@ -1,70 +0,0 @@ -use super::PeerBehaviour; -use crate::swarm::PeerBehaviourEvent; -use futures::StreamExt; -use libp2p::{ - gossipsub::{self, IdentTopic}, - mdns, - swarm::SwarmEvent, - Swarm, -}; -use tokio::sync::mpsc::{self, Receiver}; -use tracing::{debug, error}; -use zetina_common::graceful_shutdown::shutdown_signal; - -pub(crate) async fn swarm_loop( - mut swarm: Swarm, - mut transmit_topics: Vec<(IdentTopic, Receiver>)>, - swarm_events_tx: mpsc::Sender, -) { - // TODO make it nicer solution, extensible not manual! - let mut topic_one = transmit_topics.pop().unwrap(); - let mut topic_two = transmit_topics.pop().unwrap(); - loop { - tokio::select! { - Some(data) = topic_one.1.recv() => { - debug!("Publishing to topic: {:?}", topic_one.0); - if let Err(e) = swarm - .behaviour_mut().gossipsub - .publish(topic_one.0.clone(), data) { - error!("Publish error: {e:?}"); - } - }, - Some(data) = topic_two.1.recv() => { - debug!("Publishing to topic: {:?}", topic_two.0); - if let Err(e) = swarm - .behaviour_mut().gossipsub - .publish(topic_two.0.clone(), data) { - error!("Publish error: {e:?}"); - } - }, - event = swarm.select_next_some() => match event { - SwarmEvent::Behaviour(PeerBehaviourEvent::Mdns(mdns::Event::Discovered(list))) => { - for (peer_id, _multiaddr) in list { - debug!("mDNS discovered a new peer: {peer_id}"); - swarm.behaviour_mut().gossipsub.add_explicit_peer(&peer_id); - } - }, - SwarmEvent::Behaviour(PeerBehaviourEvent::Mdns(mdns::Event::Expired(list))) => { - for (peer_id, _multiaddr) in list { - debug!("mDNS discover peer has expired: {peer_id}"); - swarm.behaviour_mut().gossipsub.remove_explicit_peer(&peer_id); - } - }, - SwarmEvent::Behaviour(PeerBehaviourEvent::Gossipsub(gossipsub::Event::Message { - propagation_source, - message_id, - message, - })) => { - swarm_events_tx.send(gossipsub::Event::Message { propagation_source, message_id, message }).await.unwrap(); - }, - SwarmEvent::NewListenAddr { address, .. } => { - debug!("Local node is listening on {address}"); - } - _ => {} - }, - _ = shutdown_signal() => { - break - } - } - } -} diff --git a/runtime.dockerfile b/runtime.dockerfile index d9868ff..aeb1ee1 100644 --- a/runtime.dockerfile +++ b/runtime.dockerfile @@ -76,3 +76,6 @@ RUN pip install -r requirements.txt && \ # Copy the current directory content into the container COPY . . + +# Build +RUN cargo build --release \ No newline at end of file diff --git a/utils/cairo0_fibonacci.cairo b/utils/cairo0_fibonacci.cairo new file mode 100644 index 0000000..e7d2440 --- /dev/null +++ b/utils/cairo0_fibonacci.cairo @@ -0,0 +1,44 @@ +// Copyright 2023 StarkWare Industries Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"). +// You may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.starkware.co/open-source-license/ +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions +// and limitations under the License. + +%builtins output pedersen range_check bitwise +func main( + output_ptr: felt*, pedersen_ptr: felt*, range_check_ptr: felt*, bitwise_ptr: felt*) -> ( + output_ptr: felt*, pedersen_ptr: felt*, range_check_ptr: felt*, bitwise_ptr: felt* + ) { + alloc_locals; + + // Load fibonacci_claim_index and copy it to the output segment. + local fibonacci_claim_index; + %{ ids.fibonacci_claim_index = program_input['fibonacci_claim_index'] %} + + assert output_ptr[0] = fibonacci_claim_index; + let res = fib(1, 1, fibonacci_claim_index); + assert output_ptr[1] = res; + + // Return the updated output_ptr. + return ( + output_ptr=&output_ptr[2], pedersen_ptr=pedersen_ptr, range_check_ptr=range_check_ptr, bitwise_ptr=bitwise_ptr + ); +} + +func fib(first_element: felt, second_element: felt, n: felt) -> felt { + if (n == 0) { + return second_element; + } + + return fib( + first_element=second_element, second_element=first_element + second_element, n=n - 1 + ); +} \ No newline at end of file diff --git a/utils/cairo0_fibonacci_compiled.json b/utils/cairo0_fibonacci_compiled.json new file mode 100644 index 0000000..db5939b --- /dev/null +++ b/utils/cairo0_fibonacci_compiled.json @@ -0,0 +1,1018 @@ +{ + "attributes": [], + "builtins": [ + "output", + "pedersen", + "range_check", + "bitwise" + ], + "compiler_version": "0.13.1", + "data": [ + "0x40780017fff7fff", + "0x1", + "0x400380007ffa8000", + "0x480680017fff8000", + "0x1", + "0x480680017fff8000", + "0x1", + "0x480a80007fff8000", + "0x1104800180018000", + "0x9", + "0x400280017ffa7fff", + "0x482680017ffa8000", + "0x2", + "0x480a7ffb7fff8000", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x208b7fff7fff7ffe", + "0x20780017fff7ffd", + "0x4", + "0x480a7ffc7fff8000", + "0x208b7fff7fff7ffe", + "0x480a7ffc7fff8000", + "0x482a7ffc7ffb8000", + "0x482680017ffd8000", + "0x800000000000011000000000000000000000000000000000000000000000000", + "0x1104800180018000", + "0x800000000000010fffffffffffffffffffffffffffffffffffffffffffffff9", + "0x208b7fff7fff7ffe" + ], + "debug_info": { + "file_contents": {}, + "instruction_locations": { + "0": { + "accessible_scopes": [ + "__main__", + "__main__.main" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 0, + "offset": 0 + }, + "reference_ids": { + "__main__.main.bitwise_ptr": 3, + "__main__.main.output_ptr": 0, + "__main__.main.pedersen_ptr": 1, + "__main__.main.range_check_ptr": 2 + } + }, + "hints": [], + "inst": { + "end_col": 18, + "end_line": 20, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 5, + "start_line": 20 + } + }, + "2": { + "accessible_scopes": [ + "__main__", + "__main__.main" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 0, + "offset": 1 + }, + "reference_ids": { + "__main__.main.bitwise_ptr": 3, + "__main__.main.fibonacci_claim_index": 4, + "__main__.main.output_ptr": 0, + "__main__.main.pedersen_ptr": 1, + "__main__.main.range_check_ptr": 2 + } + }, + "hints": [ + { + "location": { + "end_col": 77, + "end_line": 24, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 5, + "start_line": 24 + }, + "n_prefix_newlines": 0 + } + ], + "inst": { + "end_col": 50, + "end_line": 26, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 5, + "start_line": 26 + } + }, + "3": { + "accessible_scopes": [ + "__main__", + "__main__.main" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 0, + "offset": 1 + }, + "reference_ids": { + "__main__.main.bitwise_ptr": 3, + "__main__.main.fibonacci_claim_index": 4, + "__main__.main.output_ptr": 0, + "__main__.main.pedersen_ptr": 1, + "__main__.main.range_check_ptr": 2 + } + }, + "hints": [], + "inst": { + "end_col": 20, + "end_line": 27, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 19, + "start_line": 27 + } + }, + "5": { + "accessible_scopes": [ + "__main__", + "__main__.main" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 0, + "offset": 2 + }, + "reference_ids": { + "__main__.main.bitwise_ptr": 3, + "__main__.main.fibonacci_claim_index": 4, + "__main__.main.output_ptr": 0, + "__main__.main.pedersen_ptr": 1, + "__main__.main.range_check_ptr": 2 + } + }, + "hints": [], + "inst": { + "end_col": 23, + "end_line": 27, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 22, + "start_line": 27 + } + }, + "7": { + "accessible_scopes": [ + "__main__", + "__main__.main" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 0, + "offset": 3 + }, + "reference_ids": { + "__main__.main.bitwise_ptr": 3, + "__main__.main.fibonacci_claim_index": 4, + "__main__.main.output_ptr": 0, + "__main__.main.pedersen_ptr": 1, + "__main__.main.range_check_ptr": 2 + } + }, + "hints": [], + "inst": { + "end_col": 32, + "end_line": 23, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "parent_location": [ + { + "end_col": 46, + "end_line": 27, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 25, + "start_line": 27 + }, + "While expanding the reference 'fibonacci_claim_index' in:" + ], + "start_col": 11, + "start_line": 23 + } + }, + "8": { + "accessible_scopes": [ + "__main__", + "__main__.main" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 0, + "offset": 4 + }, + "reference_ids": { + "__main__.main.bitwise_ptr": 3, + "__main__.main.fibonacci_claim_index": 4, + "__main__.main.output_ptr": 0, + "__main__.main.pedersen_ptr": 1, + "__main__.main.range_check_ptr": 2 + } + }, + "hints": [], + "inst": { + "end_col": 47, + "end_line": 27, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 15, + "start_line": 27 + } + }, + "10": { + "accessible_scopes": [ + "__main__", + "__main__.main" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 1, + "offset": 0 + }, + "reference_ids": { + "__main__.main.bitwise_ptr": 3, + "__main__.main.fibonacci_claim_index": 4, + "__main__.main.output_ptr": 0, + "__main__.main.pedersen_ptr": 1, + "__main__.main.range_check_ptr": 2, + "__main__.main.res": 5 + } + }, + "hints": [], + "inst": { + "end_col": 32, + "end_line": 28, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 5, + "start_line": 28 + } + }, + "11": { + "accessible_scopes": [ + "__main__", + "__main__.main" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 1, + "offset": 0 + }, + "reference_ids": { + "__main__.main.bitwise_ptr": 3, + "__main__.main.fibonacci_claim_index": 4, + "__main__.main.output_ptr": 0, + "__main__.main.pedersen_ptr": 1, + "__main__.main.range_check_ptr": 2, + "__main__.main.res": 5 + } + }, + "hints": [], + "inst": { + "end_col": 34, + "end_line": 32, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 21, + "start_line": 32 + } + }, + "13": { + "accessible_scopes": [ + "__main__", + "__main__.main" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 1, + "offset": 1 + }, + "reference_ids": { + "__main__.main.bitwise_ptr": 3, + "__main__.main.fibonacci_claim_index": 4, + "__main__.main.output_ptr": 0, + "__main__.main.pedersen_ptr": 1, + "__main__.main.range_check_ptr": 2, + "__main__.main.res": 5 + } + }, + "hints": [], + "inst": { + "end_col": 43, + "end_line": 17, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "parent_location": [ + { + "end_col": 61, + "end_line": 32, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 49, + "start_line": 32 + }, + "While expanding the reference 'pedersen_ptr' in:" + ], + "start_col": 24, + "start_line": 17 + } + }, + "14": { + "accessible_scopes": [ + "__main__", + "__main__.main" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 1, + "offset": 2 + }, + "reference_ids": { + "__main__.main.bitwise_ptr": 3, + "__main__.main.fibonacci_claim_index": 4, + "__main__.main.output_ptr": 0, + "__main__.main.pedersen_ptr": 1, + "__main__.main.range_check_ptr": 2, + "__main__.main.res": 5 + } + }, + "hints": [], + "inst": { + "end_col": 67, + "end_line": 17, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "parent_location": [ + { + "end_col": 94, + "end_line": 32, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 79, + "start_line": 32 + }, + "While expanding the reference 'range_check_ptr' in:" + ], + "start_col": 45, + "start_line": 17 + } + }, + "15": { + "accessible_scopes": [ + "__main__", + "__main__.main" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 1, + "offset": 3 + }, + "reference_ids": { + "__main__.main.bitwise_ptr": 3, + "__main__.main.fibonacci_claim_index": 4, + "__main__.main.output_ptr": 0, + "__main__.main.pedersen_ptr": 1, + "__main__.main.range_check_ptr": 2, + "__main__.main.res": 5 + } + }, + "hints": [], + "inst": { + "end_col": 87, + "end_line": 17, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "parent_location": [ + { + "end_col": 119, + "end_line": 32, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 108, + "start_line": 32 + }, + "While expanding the reference 'bitwise_ptr' in:" + ], + "start_col": 69, + "start_line": 17 + } + }, + "16": { + "accessible_scopes": [ + "__main__", + "__main__.main" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 1, + "offset": 4 + }, + "reference_ids": { + "__main__.main.bitwise_ptr": 3, + "__main__.main.fibonacci_claim_index": 4, + "__main__.main.output_ptr": 0, + "__main__.main.pedersen_ptr": 1, + "__main__.main.range_check_ptr": 2, + "__main__.main.res": 5 + } + }, + "hints": [], + "inst": { + "end_col": 7, + "end_line": 33, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 5, + "start_line": 31 + } + }, + "17": { + "accessible_scopes": [ + "__main__", + "__main__.fib" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 2, + "offset": 0 + }, + "reference_ids": { + "__main__.fib.first_element": 6, + "__main__.fib.n": 8, + "__main__.fib.second_element": 7 + } + }, + "hints": [], + "inst": { + "end_col": 7, + "end_line": 37, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 5, + "start_line": 37 + } + }, + "19": { + "accessible_scopes": [ + "__main__", + "__main__.fib" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 2, + "offset": 0 + }, + "reference_ids": { + "__main__.fib.first_element": 6, + "__main__.fib.n": 8, + "__main__.fib.second_element": 7 + } + }, + "hints": [], + "inst": { + "end_col": 51, + "end_line": 36, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "parent_location": [ + { + "end_col": 30, + "end_line": 38, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 16, + "start_line": 38 + }, + "While expanding the reference 'second_element' in:" + ], + "start_col": 31, + "start_line": 36 + } + }, + "20": { + "accessible_scopes": [ + "__main__", + "__main__.fib" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 2, + "offset": 1 + }, + "reference_ids": { + "__main__.fib.first_element": 6, + "__main__.fib.n": 8, + "__main__.fib.second_element": 7 + } + }, + "hints": [], + "inst": { + "end_col": 31, + "end_line": 38, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 9, + "start_line": 38 + } + }, + "21": { + "accessible_scopes": [ + "__main__", + "__main__.fib" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 2, + "offset": 0 + }, + "reference_ids": { + "__main__.fib.first_element": 6, + "__main__.fib.n": 8, + "__main__.fib.second_element": 7 + } + }, + "hints": [], + "inst": { + "end_col": 51, + "end_line": 36, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "parent_location": [ + { + "end_col": 37, + "end_line": 42, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 23, + "start_line": 42 + }, + "While expanding the reference 'second_element' in:" + ], + "start_col": 31, + "start_line": 36 + } + }, + "22": { + "accessible_scopes": [ + "__main__", + "__main__.fib" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 2, + "offset": 1 + }, + "reference_ids": { + "__main__.fib.first_element": 6, + "__main__.fib.n": 8, + "__main__.fib.second_element": 7 + } + }, + "hints": [], + "inst": { + "end_col": 84, + "end_line": 42, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 54, + "start_line": 42 + } + }, + "23": { + "accessible_scopes": [ + "__main__", + "__main__.fib" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 2, + "offset": 2 + }, + "reference_ids": { + "__main__.fib.first_element": 6, + "__main__.fib.n": 8, + "__main__.fib.second_element": 7 + } + }, + "hints": [], + "inst": { + "end_col": 93, + "end_line": 42, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 88, + "start_line": 42 + } + }, + "25": { + "accessible_scopes": [ + "__main__", + "__main__.fib" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 2, + "offset": 3 + }, + "reference_ids": { + "__main__.fib.first_element": 6, + "__main__.fib.n": 8, + "__main__.fib.second_element": 7 + } + }, + "hints": [], + "inst": { + "end_col": 6, + "end_line": 43, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 12, + "start_line": 41 + } + }, + "27": { + "accessible_scopes": [ + "__main__", + "__main__.fib" + ], + "flow_tracking_data": { + "ap_tracking": { + "group": 3, + "offset": 0 + }, + "reference_ids": { + "__main__.fib.first_element": 6, + "__main__.fib.n": 8, + "__main__.fib.second_element": 7 + } + }, + "hints": [], + "inst": { + "end_col": 7, + "end_line": 43, + "input_file": { + "filename": "cairo0_fibonacci.cairo" + }, + "start_col": 5, + "start_line": 41 + } + } + } + }, + "hints": { + "2": [ + { + "accessible_scopes": [ + "__main__", + "__main__.main" + ], + "code": "ids.fibonacci_claim_index = program_input['fibonacci_claim_index']", + "flow_tracking_data": { + "ap_tracking": { + "group": 0, + "offset": 1 + }, + "reference_ids": { + "__main__.main.bitwise_ptr": 3, + "__main__.main.fibonacci_claim_index": 4, + "__main__.main.output_ptr": 0, + "__main__.main.pedersen_ptr": 1, + "__main__.main.range_check_ptr": 2 + } + } + } + ] + }, + "identifiers": { + "__main__.fib": { + "decorators": [], + "pc": 17, + "type": "function" + }, + "__main__.fib.Args": { + "full_name": "__main__.fib.Args", + "members": { + "first_element": { + "cairo_type": "felt", + "offset": 0 + }, + "n": { + "cairo_type": "felt", + "offset": 2 + }, + "second_element": { + "cairo_type": "felt", + "offset": 1 + } + }, + "size": 3, + "type": "struct" + }, + "__main__.fib.ImplicitArgs": { + "full_name": "__main__.fib.ImplicitArgs", + "members": {}, + "size": 0, + "type": "struct" + }, + "__main__.fib.Return": { + "cairo_type": "felt", + "type": "type_definition" + }, + "__main__.fib.SIZEOF_LOCALS": { + "type": "const", + "value": 0 + }, + "__main__.fib.first_element": { + "cairo_type": "felt", + "full_name": "__main__.fib.first_element", + "references": [ + { + "ap_tracking_data": { + "group": 2, + "offset": 0 + }, + "pc": 17, + "value": "[cast(fp + (-5), felt*)]" + } + ], + "type": "reference" + }, + "__main__.fib.n": { + "cairo_type": "felt", + "full_name": "__main__.fib.n", + "references": [ + { + "ap_tracking_data": { + "group": 2, + "offset": 0 + }, + "pc": 17, + "value": "[cast(fp + (-3), felt*)]" + } + ], + "type": "reference" + }, + "__main__.fib.second_element": { + "cairo_type": "felt", + "full_name": "__main__.fib.second_element", + "references": [ + { + "ap_tracking_data": { + "group": 2, + "offset": 0 + }, + "pc": 17, + "value": "[cast(fp + (-4), felt*)]" + } + ], + "type": "reference" + }, + "__main__.main": { + "decorators": [], + "pc": 0, + "type": "function" + }, + "__main__.main.Args": { + "full_name": "__main__.main.Args", + "members": { + "bitwise_ptr": { + "cairo_type": "felt*", + "offset": 3 + }, + "output_ptr": { + "cairo_type": "felt*", + "offset": 0 + }, + "pedersen_ptr": { + "cairo_type": "felt*", + "offset": 1 + }, + "range_check_ptr": { + "cairo_type": "felt*", + "offset": 2 + } + }, + "size": 4, + "type": "struct" + }, + "__main__.main.ImplicitArgs": { + "full_name": "__main__.main.ImplicitArgs", + "members": {}, + "size": 0, + "type": "struct" + }, + "__main__.main.Return": { + "cairo_type": "(output_ptr: felt*, pedersen_ptr: felt*, range_check_ptr: felt*, bitwise_ptr: felt*)", + "type": "type_definition" + }, + "__main__.main.SIZEOF_LOCALS": { + "type": "const", + "value": 1 + }, + "__main__.main.bitwise_ptr": { + "cairo_type": "felt*", + "full_name": "__main__.main.bitwise_ptr", + "references": [ + { + "ap_tracking_data": { + "group": 0, + "offset": 0 + }, + "pc": 0, + "value": "[cast(fp + (-3), felt**)]" + } + ], + "type": "reference" + }, + "__main__.main.fibonacci_claim_index": { + "cairo_type": "felt", + "full_name": "__main__.main.fibonacci_claim_index", + "references": [ + { + "ap_tracking_data": { + "group": 0, + "offset": 1 + }, + "pc": 2, + "value": "[cast(fp, felt*)]" + } + ], + "type": "reference" + }, + "__main__.main.output_ptr": { + "cairo_type": "felt*", + "full_name": "__main__.main.output_ptr", + "references": [ + { + "ap_tracking_data": { + "group": 0, + "offset": 0 + }, + "pc": 0, + "value": "[cast(fp + (-6), felt**)]" + } + ], + "type": "reference" + }, + "__main__.main.pedersen_ptr": { + "cairo_type": "felt*", + "full_name": "__main__.main.pedersen_ptr", + "references": [ + { + "ap_tracking_data": { + "group": 0, + "offset": 0 + }, + "pc": 0, + "value": "[cast(fp + (-5), felt**)]" + } + ], + "type": "reference" + }, + "__main__.main.range_check_ptr": { + "cairo_type": "felt*", + "full_name": "__main__.main.range_check_ptr", + "references": [ + { + "ap_tracking_data": { + "group": 0, + "offset": 0 + }, + "pc": 0, + "value": "[cast(fp + (-4), felt**)]" + } + ], + "type": "reference" + }, + "__main__.main.res": { + "cairo_type": "felt", + "full_name": "__main__.main.res", + "references": [ + { + "ap_tracking_data": { + "group": 1, + "offset": 0 + }, + "pc": 10, + "value": "[cast(ap + (-1), felt*)]" + } + ], + "type": "reference" + } + }, + "main_scope": "__main__", + "prime": "0x800000000000011000000000000000000000000000000000000000000000001", + "reference_manager": { + "references": [ + { + "ap_tracking_data": { + "group": 0, + "offset": 0 + }, + "pc": 0, + "value": "[cast(fp + (-6), felt**)]" + }, + { + "ap_tracking_data": { + "group": 0, + "offset": 0 + }, + "pc": 0, + "value": "[cast(fp + (-5), felt**)]" + }, + { + "ap_tracking_data": { + "group": 0, + "offset": 0 + }, + "pc": 0, + "value": "[cast(fp + (-4), felt**)]" + }, + { + "ap_tracking_data": { + "group": 0, + "offset": 0 + }, + "pc": 0, + "value": "[cast(fp + (-3), felt**)]" + }, + { + "ap_tracking_data": { + "group": 0, + "offset": 1 + }, + "pc": 2, + "value": "[cast(fp, felt*)]" + }, + { + "ap_tracking_data": { + "group": 1, + "offset": 0 + }, + "pc": 10, + "value": "[cast(ap + (-1), felt*)]" + }, + { + "ap_tracking_data": { + "group": 2, + "offset": 0 + }, + "pc": 17, + "value": "[cast(fp + (-5), felt*)]" + }, + { + "ap_tracking_data": { + "group": 2, + "offset": 0 + }, + "pc": 17, + "value": "[cast(fp + (-4), felt*)]" + }, + { + "ap_tracking_data": { + "group": 2, + "offset": 0 + }, + "pc": 17, + "value": "[cast(fp + (-3), felt*)]" + } + ] + } +} diff --git a/utils/cairo0_fibonacci_input.json b/utils/cairo0_fibonacci_input.json new file mode 100644 index 0000000..d20c51a --- /dev/null +++ b/utils/cairo0_fibonacci_input.json @@ -0,0 +1,3 @@ +{ + "fibonacci_claim_index": 10 +} \ No newline at end of file diff --git a/utils/cairo0_fibonacci_pie.zip b/utils/cairo0_fibonacci_pie.zip new file mode 100644 index 0000000..3c13319 Binary files /dev/null and b/utils/cairo0_fibonacci_pie.zip differ diff --git a/utils/create_pie.py b/utils/create_pie.py new file mode 100644 index 0000000..44b6bdc --- /dev/null +++ b/utils/create_pie.py @@ -0,0 +1,19 @@ +import os +from utils import log_and_run + +if __name__ == "__main__": + current_dir = os.getcwd() + + log_and_run([ + f"cairo-compile --cairo_path=. cairo0_fibonacci.cairo --output {current_dir}/cairo0_fibonacci_compiled.json", + ], "Compile program", cwd=".") + + log_and_run([ + "cairo-run \ + --program=cairo0_fibonacci_compiled.json \ + --layout=recursive_with_poseidon \ + --program_input=cairo0_fibonacci_input.json \ + --cairo_pie_output=cairo0_fibonacci_pie.zip \ + --print_output \ + --print_info" + ], "Create PIE", cwd=".") \ No newline at end of file diff --git a/utils/delegator_pb2.py b/utils/delegator_pb2.py new file mode 100644 index 0000000..3f1d3a6 --- /dev/null +++ b/utils/delegator_pb2.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: delegator.proto +# Protobuf Python Version: 5.26.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0f\x64\x65legator.proto\x12\tdelegator\"$\n\x0f\x44\x65legateRequest\x12\x11\n\tcairo_pie\x18\x01 \x01(\x0c\"3\n\x10\x44\x65legateResponse\x12\r\n\x05proof\x18\x01 \x01(\x0c\x12\x10\n\x08job_hash\x18\x02 \x01(\x04\x32^\n\x10\x44\x65legatorService\x12J\n\tDelegator\x12\x1a.delegator.DelegateRequest\x1a\x1b.delegator.DelegateResponse\"\x00(\x01\x30\x01\x62\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'delegator_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + DESCRIPTOR._loaded_options = None + _globals['_DELEGATEREQUEST']._serialized_start=30 + _globals['_DELEGATEREQUEST']._serialized_end=66 + _globals['_DELEGATERESPONSE']._serialized_start=68 + _globals['_DELEGATERESPONSE']._serialized_end=119 + _globals['_DELEGATORSERVICE']._serialized_start=121 + _globals['_DELEGATORSERVICE']._serialized_end=215 +# @@protoc_insertion_point(module_scope) diff --git a/utils/delegator_pb2.pyi b/utils/delegator_pb2.pyi new file mode 100644 index 0000000..4a8665d --- /dev/null +++ b/utils/delegator_pb2.pyi @@ -0,0 +1,19 @@ +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from typing import ClassVar as _ClassVar, Optional as _Optional + +DESCRIPTOR: _descriptor.FileDescriptor + +class DelegateRequest(_message.Message): + __slots__ = ("cairo_pie",) + CAIRO_PIE_FIELD_NUMBER: _ClassVar[int] + cairo_pie: bytes + def __init__(self, cairo_pie: _Optional[bytes] = ...) -> None: ... + +class DelegateResponse(_message.Message): + __slots__ = ("proof", "job_hash") + PROOF_FIELD_NUMBER: _ClassVar[int] + JOB_HASH_FIELD_NUMBER: _ClassVar[int] + proof: bytes + job_hash: int + def __init__(self, proof: _Optional[bytes] = ..., job_hash: _Optional[int] = ...) -> None: ... diff --git a/utils/delegator_pb2_grpc.py b/utils/delegator_pb2_grpc.py new file mode 100644 index 0000000..b72c6de --- /dev/null +++ b/utils/delegator_pb2_grpc.py @@ -0,0 +1,102 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc +import warnings + +import delegator_pb2 as delegator__pb2 + +GRPC_GENERATED_VERSION = '1.64.1' +GRPC_VERSION = grpc.__version__ +EXPECTED_ERROR_RELEASE = '1.65.0' +SCHEDULED_RELEASE_DATE = 'June 25, 2024' +_version_not_supported = False + +try: + from grpc._utilities import first_version_is_lower + _version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION) +except ImportError: + _version_not_supported = True + +if _version_not_supported: + warnings.warn( + f'The grpc package installed is at version {GRPC_VERSION},' + + f' but the generated code in delegator_pb2_grpc.py depends on' + + f' grpcio>={GRPC_GENERATED_VERSION}.' + + f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}' + + f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.' + + f' This warning will become an error in {EXPECTED_ERROR_RELEASE},' + + f' scheduled for release on {SCHEDULED_RELEASE_DATE}.', + RuntimeWarning + ) + + +class DelegatorServiceStub(object): + """Missing associated documentation comment in .proto file.""" + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.Delegator = channel.stream_stream( + '/delegator.DelegatorService/Delegator', + request_serializer=delegator__pb2.DelegateRequest.SerializeToString, + response_deserializer=delegator__pb2.DelegateResponse.FromString, + _registered_method=True) + + +class DelegatorServiceServicer(object): + """Missing associated documentation comment in .proto file.""" + + def Delegator(self, request_iterator, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_DelegatorServiceServicer_to_server(servicer, server): + rpc_method_handlers = { + 'Delegator': grpc.stream_stream_rpc_method_handler( + servicer.Delegator, + request_deserializer=delegator__pb2.DelegateRequest.FromString, + response_serializer=delegator__pb2.DelegateResponse.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'delegator.DelegatorService', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + server.add_registered_method_handlers('delegator.DelegatorService', rpc_method_handlers) + + + # This class is part of an EXPERIMENTAL API. +class DelegatorService(object): + """Missing associated documentation comment in .proto file.""" + + @staticmethod + def Delegator(request_iterator, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.stream_stream( + request_iterator, + target, + '/delegator.DelegatorService/Delegator', + delegator__pb2.DelegateRequest.SerializeToString, + delegator__pb2.DelegateResponse.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + _registered_method=True) diff --git a/utils/grpc_healt_check.py b/utils/grpc_healt_check.py new file mode 100644 index 0000000..d8f91e3 --- /dev/null +++ b/utils/grpc_healt_check.py @@ -0,0 +1,28 @@ +import logging +from time import sleep + +import grpc +from grpc_health.v1 import health_pb2 +from grpc_health.v1 import health_pb2_grpc + +def health_check_call(stub: health_pb2_grpc.HealthStub): + request = health_pb2.HealthCheckRequest() + resp = stub.Check(request) + if resp.status == health_pb2.HealthCheckResponse.SERVING: + print("server is serving") + elif resp.status == health_pb2.HealthCheckResponse.NOT_SERVING: + print("server stopped serving") + + +def run(): + with grpc.insecure_channel("localhost:50052") as channel: + health_stub = health_pb2_grpc.HealthStub(channel) + + # Check health status every 1 second for 30 seconds + for _ in range(30): + health_check_call(health_stub) + + +if __name__ == "__main__": + logging.basicConfig() + run() \ No newline at end of file diff --git a/utils/send_pie.py b/utils/send_pie.py new file mode 100644 index 0000000..04843b6 --- /dev/null +++ b/utils/send_pie.py @@ -0,0 +1,42 @@ +import grpc +import delegator_pb2_grpc +import delegator_pb2 + +def send_file_to_server(): + # Open the file and read its contents + with open("cairo0_fibonacci_pie.zip", 'rb') as file: + file_content = file.read() + + # Create gRPC channel and stub + with grpc.insecure_channel('localhost:50051') as channel: + stub = delegator_pb2_grpc.DelegatorServiceStub(channel) + + # Define generator function for streaming request + def request_generator(): + for i in range(2): + yield delegator_pb2.DelegateRequest(cairo_pie=file_content) + + try: + # Make the RPC call with streaming request + responses = stub.Delegator(request_generator()) + + # Iterate over responses (if needed) + for response in responses: + print(response) + + except grpc.RpcError as e: + # Handle gRPC errors + print(f"Error occurred during RPC: {e}") + + # Access detailed information about the RPC status + status_code = e.code() + details = e.details() + debug_error_string = e.debug_error_string() + + print(f"RPC Error Details:") + print(f"Status Code: {status_code}") + print(f"Details: {details}") + print(f"Debug Error String: {debug_error_string}") + +if __name__ == '__main__': + send_file_to_server()