Skip to content

Commit

Permalink
Merge pull request #22 from iosis-tech/delegator-dashboard
Browse files Browse the repository at this point in the history
Delegator dashboard
  • Loading branch information
Okm165 authored Jul 14, 2024
2 parents 4dc7ea1 + dd57d78 commit 242ca2f
Show file tree
Hide file tree
Showing 64 changed files with 8,688 additions and 490 deletions.
34 changes: 32 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
target
*docker*
# 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
21 changes: 20 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,23 @@ Scarb.lock

stone-prover

bootloader*.json
bootloader*.json

# Python
*.pyc
__pycache__/
venv/
env/
dist/
build/
*.egg-info/

# PyInstaller
dist/
build/

# IPython Notebook
.ipynb_checkpoints

# Jupyter Notebook
.ipynb_checkpoints/
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ tokio = { version = "1.36", features = ["full"] }
tokio-util = "0.7.10"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tokio-stream = "0.1.15"
axum = "0.7.5"
hyper = { version = "1.0", features = [] }
hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] }
tower = { version = "0.4", features = ["util"] }
tower-http = { version = "0.5", features = ["timeout", "trace", "cors"] }

zetina-common = { path = "crates/common" }
zetina-compiler = { path = "crates/compiler" }
Expand All @@ -72,4 +78,4 @@ zetina-executor = { path = "crates/executor" }
zetina-peer = { path = "crates/peer" }
zetina-prover = { path = "crates/prover" }
zetina-runner = { path = "crates/runner" }
zetina-tests = { path = "crates/tests" }
zetina-tests = { path = "crates/tests" }
1 change: 0 additions & 1 deletion cairo/bootloader/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class JobData(Task):
reward: int
num_of_steps: int
cairo_pie_compressed: FieldElementsData
registry_address: int

def load_task(self) -> "CairoPieTask":
return CairoPieTask(
Expand Down
1 change: 1 addition & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ publish = true

[dependencies]
cairo-vm.workspace = true
rand.workspace = true
futures.workspace = true
hex.workspace = true
libp2p.workspace = true
Expand Down
41 changes: 5 additions & 36 deletions crates/common/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use tempfile::NamedTempFile;
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Serialize, Deserialize)]
pub struct Job {
pub job_data: JobData,
pub public_key: FieldElement, // The public key of the delegator, used in the bootloader stage to confirm authenticity of the Job<->Delegator relationship
pub signature_r: FieldElement, // The signature of the delegator, used in the bootloader stage to confirm authenticity of the Job<->Delegator relationship
pub signature_s: FieldElement, // The signature of the delegator, used in the bootloader stage to confirm authenticity of the Job<->Delegator relationship
pub public_key: FieldElement, // The public key of the delegator, used in the bootloader stage to confirm authenticity of the Job<->Delegator relation
pub signature_r: FieldElement, // The signature of the delegator, used in the bootloader stage to confirm authenticity of the Job<->Delegator relation
pub signature_s: FieldElement, // The signature of the delegator, used in the bootloader stage to confirm authenticity of the Job<->Delegator relation
}

impl Job {
Expand All @@ -48,18 +48,12 @@ pub struct JobData {
pub num_of_steps: u64,
#[serde(with = "chunk_felt_array")]
pub cairo_pie_compressed: Vec<u8>,
pub registry_address: FieldElement,
}

impl JobData {
pub fn new(reward: u64, cairo_pie_compressed: Vec<u8>, registry_address: FieldElement) -> Self {
pub fn new(reward: u64, cairo_pie_compressed: Vec<u8>) -> Self {
let pie = Self::decompress_cairo_pie(&cairo_pie_compressed);
Self {
reward,
num_of_steps: pie.execution_resources.n_steps as u64,
cairo_pie_compressed,
registry_address,
}
Self { reward, num_of_steps: pie.execution_resources.n_steps as u64, cairo_pie_compressed }
}

fn decompress_cairo_pie(cairo_pie_compressed: &[u8]) -> CairoPie {
Expand Down Expand Up @@ -96,7 +90,6 @@ impl Hash for JobData {
self.reward.hash(state);
self.num_of_steps.hash(state);
self.cairo_pie_compressed.hash(state);
self.registry_address.hash(state);
}
}

Expand All @@ -112,30 +105,6 @@ impl Display for Job {
}
}

// #[cfg(test)]
// mod tests {
// use super::*;
// use proptest::prelude::*;

// proptest! {
// #![proptest_config(ProptestConfig::with_cases(100))]
// #[test]
// fn job_verify_signature(job in any::<Job>()) {
// assert!(job.verify_signature());
// }
// }

// proptest! {
// #![proptest_config(ProptestConfig::with_cases(100))]
// #[test]
// fn job_serialization(job in any::<Job>()) {
// let serialized_job = serde_json::to_string(&job).unwrap();
// let deserialized_job: Job = serde_json::from_str(&serialized_job).unwrap();
// assert_eq!(job, deserialized_job)
// }
// }
// }

mod chunk_felt_array {
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use starknet_crypto::FieldElement;
Expand Down
8 changes: 8 additions & 0 deletions crates/common/src/job_record.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{collections::BTreeSet, hash::Hash};

use rand::Rng;

pub struct JobRecord<J> {
ordered_set: BTreeSet<J>,
}
Expand All @@ -21,6 +23,12 @@ where
}

pub async fn take_job(&mut self) -> Option<J> {
// add random wait to simulate network overhead
let random = {
let mut rng = rand::thread_rng();
rng.gen_range(0..1000)
};
tokio::time::sleep(std::time::Duration::from_millis(random)).await;
self.ordered_set.pop_last()
}

Expand Down
1 change: 1 addition & 0 deletions crates/common/src/job_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use tempfile::NamedTempFile;

#[derive(Debug)]
pub struct JobTrace {
pub job_hash: u64,
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)
Expand Down
15 changes: 11 additions & 4 deletions crates/common/src/job_witness.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::hash;
use starknet_crypto::FieldElement;
use serde::{Deserialize, Serialize};
use std::{
fmt::Display,
hash::{DefaultHasher, Hash, Hasher},
Expand All @@ -8,13 +8,20 @@ use std::{
/*
Job Witness Object
This object represents the output from the proving process.
It holds a serialized proof as an array of FieldElement objects.
It holds a serialized proof as an array of bytes.
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)]
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct JobWitness {
pub proof: Vec<FieldElement>, // Serialized proof
pub job_hash: u64,
pub proof: Vec<u8>,
}

impl Hash for JobWitness {
fn hash<H: Hasher>(&self, state: &mut H) {
self.proof.hash(state);
}
}

impl Display for JobWitness {
Expand Down
2 changes: 0 additions & 2 deletions crates/common/src/node_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ where
/// The account for the StarkNet network.
/// This account is used to interact with the Registry contract.
account: SingleOwnerAccount<P, LocalWallet>,
///
///
signing_key: SigningKey,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::pin::Pin;
use tokio::sync::mpsc;

pub struct Process<'future, PR> {
future: Pin<Box<dyn Future<Output = PR> + 'future>>,
future: Pin<Box<dyn Future<Output = PR> + Send + 'future>>,
abort: mpsc::Sender<()>,
}

impl<'future, PR> Process<'future, PR> {
pub fn new(
future: Pin<Box<dyn Future<Output = PR> + 'future>>,
future: Pin<Box<dyn Future<Output = PR> + Send + 'future>>,
abort: mpsc::Sender<()>,
) -> Self {
Self { future, abort }
Expand Down
2 changes: 2 additions & 0 deletions crates/common/src/topic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ use crate::network::Network;
pub enum Topic {
NewJob,
PickedJob,
FinishedJob,
}

impl Topic {
pub fn as_str(&self) -> &'static str {
match self {
Topic::NewJob => "new-job",
Topic::PickedJob => "picked-job",
Topic::FinishedJob => "finished-job",
}
}
}
Expand Down
Loading

0 comments on commit 242ca2f

Please sign in to comment.