Skip to content

Commit

Permalink
feat: update state when verify done.
Browse files Browse the repository at this point in the history
  • Loading branch information
Draply committed Dec 6, 2024
1 parent f5cf1e2 commit 5cc9b72
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export APTOS_VERIFIER_ADDRESS="852578629621677c02f4b9679622f25cac00b4fe17d1fd8b1
export CHAIN_ID="testnet"

export APTOS_TESTCONTAINER__ACCOUNTS="0xb6c8ce69f296d08fc217b953c7fba5eb25fe14ce0c764b1360ddea4e7e21470a,0x054031364b8a623c093277d30ce9fefe0df363226c23b1cb130d6382f4a1162a"
export APTOS_TESTCONTAINER__NODE_URL="http://10.20.21.121:8888"
export APTOS_TESTCONTAINER__NODE_URL="https://api.testnet.aptoslabs.com/v1"
export APTOS_TESTCONTAINER__ENABLE_NODE=false
export APTOS_TESTCONTAINER__DEPLOY_CONTRACT=true
export APTOS_TESTCONTAINER__CHAIN_ID=4
export APTOS_TESTCONTAINER__CHAIN_ID=2
10 changes: 5 additions & 5 deletions crates/adapter/src/worker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use irelia_common::workers::{
REGISTER_CONTINUOUS_IDENTIFIER, VERIFY_FRI_IDENTIFIER, VERIFY_PROOF_AND_REGISTER_IDENTIFIER,
};
use irelia_core::common::core_error::CoreError;
use irelia_core::entities::sharp_proof::SharpProof;
use irelia_core::entities::payload_verify_job::PayloadVerifyJob;
use irelia_core::entities::worker_job::WorkerJobEntity;
use irelia_core::ports::worker::WorkerPort;
use sqlx::postgres::PgConnectOptions;
Expand Down Expand Up @@ -55,7 +55,7 @@ impl WorkerPort for WorkerAdapter {
Ok(job)
}

async fn verify_merkle(&self, job: SharpProof) -> Result<(), CoreError> {
async fn verify_merkle(&self, job: PayloadVerifyJob) -> Result<(), CoreError> {
// retrieve the current span
let span = tracing::Span::current();
// retrieve the current context
Expand All @@ -80,7 +80,7 @@ impl WorkerPort for WorkerAdapter {
Ok(())
}

async fn verify_fri(&self, job: SharpProof) -> Result<(), CoreError> {
async fn verify_fri(&self, job: PayloadVerifyJob) -> Result<(), CoreError> {
// retrieve the current span
let span = tracing::Span::current();
// retrieve the current context
Expand All @@ -101,7 +101,7 @@ impl WorkerPort for WorkerAdapter {
Ok(())
}

async fn register_memory_page(&self, job: SharpProof) -> Result<(), CoreError> {
async fn register_memory_page(&self, job: PayloadVerifyJob) -> Result<(), CoreError> {
// retrieve the current span
let span = tracing::Span::current();
// retrieve the current context
Expand All @@ -122,7 +122,7 @@ impl WorkerPort for WorkerAdapter {
Ok(())
}

async fn verify_proof_and_register(&self, job: SharpProof) -> Result<(), CoreError> {
async fn verify_proof_and_register(&self, job: PayloadVerifyJob) -> Result<(), CoreError> {
// retrieve the current span
let span = tracing::Span::current();
// retrieve the current context
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ pub mod gps_statement;
pub mod job;
pub mod memory_statement;
pub mod merkle_statement;
pub mod payload_verify_job;
pub mod sharp_proof;
pub mod worker_job;
10 changes: 10 additions & 0 deletions crates/core/src/entities/payload_verify_job.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use serde::{Deserialize, Serialize};

use crate::entities::job::JobEntity;
use crate::entities::sharp_proof::SharpProof;

#[derive(Debug, Serialize, Deserialize)]
pub struct PayloadVerifyJob {
pub job: JobEntity,
pub sharp_proof: SharpProof,
}
10 changes: 5 additions & 5 deletions crates/core/src/ports/worker.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use async_trait::async_trait;

use crate::common::core_error::CoreError;
use crate::entities::sharp_proof::SharpProof;
use crate::entities::payload_verify_job::PayloadVerifyJob;
use crate::entities::worker_job::WorkerJobEntity;

#[async_trait]
pub trait WorkerPort {
async fn add(&self, job: WorkerJobEntity) -> Result<WorkerJobEntity, CoreError>;
async fn verify_merkle(&self, job: SharpProof) -> Result<(), CoreError>;
async fn verify_fri(&self, job: SharpProof) -> Result<(), CoreError>;
async fn register_memory_page(&self, job: SharpProof) -> Result<(), CoreError>;
async fn verify_proof_and_register(&self, job: SharpProof) -> Result<(), CoreError>;
async fn verify_merkle(&self, job: PayloadVerifyJob) -> Result<(), CoreError>;
async fn verify_fri(&self, job: PayloadVerifyJob) -> Result<(), CoreError>;
async fn register_memory_page(&self, job: PayloadVerifyJob) -> Result<(), CoreError>;
async fn verify_proof_and_register(&self, job: PayloadVerifyJob) -> Result<(), CoreError>;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed crates/public/cairo_pies/test.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion crates/public/src/tests/test_add_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async fn test_successfully(client: Client, base_url: String, cairo_pie: String)
let url =
format!(
"{}/v1/gateway/add_job?customer_id={}&cairo_job_key={}&offchain_proof={}&proof_layout={}",
base_url, Uuid::new_v4(), Uuid::new_v4(), true, "small"
base_url, Uuid::new_v4(), Uuid::new_v4(), true, "starknet"
);

let correct_body = format!("{}", cairo_pie);
Expand Down
16 changes: 0 additions & 16 deletions crates/temp/verifier/Cargo.toml

This file was deleted.

Binary file removed crates/temp/verifier/tests/fibonacci_with_output.zip
Binary file not shown.
14 changes: 13 additions & 1 deletion crates/worker/src/jobs/job_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::PathBuf;
use graphile_worker::{IntoTaskHandlerResult, TaskHandler, WorkerContext};
use irelia_adapter::prover::stone_prover::StoneProver;
use irelia_common::workers::{Worker, ADD_JOB_WORKER_IDENTIFIER};
use irelia_core::entities::payload_verify_job::PayloadVerifyJob;
use irelia_core::entities::worker_job::WorkerJobEntity;
use irelia_core::ports::prover::ProverPort;
use serde::{Deserialize, Serialize};
Expand All @@ -27,12 +28,23 @@ impl TaskHandler for JobWorker {
span.set_parent(parent_cx);

let state = _ctx.extensions().get::<State>().unwrap();

let job = state
.job_port
.get_job(self.0.data.customer_id, self.0.data.cairo_job_key)
.await
.unwrap();

let stone_prover = StoneProver {
layout: self.0.data.proof_layout,
cairo_pie: vec![PathBuf::from(self.0.data.cairo_pie)],
};
let proof = stone_prover.generate_proof().await.unwrap();
let payload = PayloadVerifyJob {
job,
sharp_proof: proof,
};

state.worker_port.verify_merkle(proof).await.unwrap();
state.worker_port.verify_merkle(payload).await.unwrap();
}
}
7 changes: 3 additions & 4 deletions crates/worker/src/jobs/merkle_statement_job.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use graphile_worker::{IntoTaskHandlerResult, TaskHandler, WorkerContext};
use irelia_adapter::aptos_writer::config::{AppConfig, EnvConfig};
use irelia_adapter::aptos_writer::contracts_caller::verify_merkle::extract_verify_merkle_input::extract_verify_merkle_input;
use irelia_adapter::aptos_writer::contracts_caller::verify_merkle::verify_merkle::verify_merkle;
use irelia_common::workers::{Worker, MERKLE_STATEMENT_VERIFIER_IDENTIFIER};
use irelia_core::entities::sharp_proof::SharpProof;
use irelia_core::entities::payload_verify_job::PayloadVerifyJob;
use serde::{Deserialize, Serialize};
use tracing::{info, instrument, Span};
use tracing_opentelemetry::OpenTelemetrySpanExt;

use crate::state::State;

#[derive(Deserialize, Serialize, Debug)]
pub struct MerkleStatementJob(Worker<SharpProof>);
pub struct MerkleStatementJob(Worker<PayloadVerifyJob>);

impl TaskHandler for MerkleStatementJob {
const IDENTIFIER: &'static str = MERKLE_STATEMENT_VERIFIER_IDENTIFIER;
Expand All @@ -26,7 +25,7 @@ impl TaskHandler for MerkleStatementJob {

let state = _ctx.extensions().get::<State>().unwrap();
let verify_merkle_inputs =
extract_verify_merkle_input(&self.0.data.merkle_proofs.clone()).unwrap();
extract_verify_merkle_input(&self.0.data.sharp_proof.merkle_proofs.clone()).unwrap();
info!("VERIFY MERKLE STATEMENT IN PROGRESS");
for merkle_verify_input in verify_merkle_inputs {
info!(
Expand Down
7 changes: 3 additions & 4 deletions crates/worker/src/jobs/register_continuous_page_job.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use crate::state::State;
use graphile_worker::{IntoTaskHandlerResult, TaskHandler, WorkerContext};
use irelia_adapter::aptos_writer::config::{AppConfig, EnvConfig};
use irelia_adapter::aptos_writer::contracts_caller::memory_page_fact_registry::extract_register_memory::extract_register_continuous_page;
use irelia_adapter::aptos_writer::contracts_caller::memory_page_fact_registry::register_continuous_memory_page::register_continuous_memory_page;
use irelia_common::workers::{Worker, REGISTER_CONTINUOUS_IDENTIFIER};
use irelia_core::entities::sharp_proof::SharpProof;
use irelia_core::entities::payload_verify_job::PayloadVerifyJob;
use serde::{Deserialize, Serialize};
use tracing::log::info;
use tracing::{instrument, Span};
use tracing_opentelemetry::OpenTelemetrySpanExt;

#[derive(Deserialize, Serialize, Debug)]
pub struct RegisterContinuousJob(Worker<SharpProof>);
pub struct RegisterContinuousJob(Worker<PayloadVerifyJob>);

impl TaskHandler for RegisterContinuousJob {
const IDENTIFIER: &'static str = REGISTER_CONTINUOUS_IDENTIFIER;
Expand All @@ -24,7 +23,7 @@ impl TaskHandler for RegisterContinuousJob {

span.set_parent(parent_cx);
let register_continuous_page_inputs =
extract_register_continuous_page(&self.0.data.memory_pages).unwrap();
extract_register_continuous_page(&self.0.data.sharp_proof.memory_pages).unwrap();

info!("REGISTER CONTINUOUS IN PROGRESS");
let state = _ctx.extensions().get::<State>().unwrap();
Expand Down
8 changes: 4 additions & 4 deletions crates/worker/src/jobs/verify_fri_job.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use graphile_worker::{IntoTaskHandlerResult, TaskHandler, WorkerContext};
use irelia_adapter::aptos_writer::config::{AppConfig, EnvConfig};
use irelia_adapter::aptos_writer::contracts_caller::verify_fri::extract_verify_fri_input::extract_verify_fri_input;
use irelia_adapter::aptos_writer::contracts_caller::verify_fri::verify_fri::verify_fri;
use irelia_common::workers::{Worker, VERIFY_FRI_IDENTIFIER};
use irelia_core::entities::sharp_proof::SharpProof;
use irelia_core::entities::payload_verify_job::PayloadVerifyJob;
use serde::{Deserialize, Serialize};
use tracing::log::info;
use tracing::{instrument, Span};
Expand All @@ -12,7 +11,7 @@ use tracing_opentelemetry::OpenTelemetrySpanExt;
use crate::state::State;

#[derive(Deserialize, Serialize, Debug)]
pub struct VerifyFriJob(Worker<SharpProof>);
pub struct VerifyFriJob(Worker<PayloadVerifyJob>);

impl TaskHandler for VerifyFriJob {
const IDENTIFIER: &'static str = VERIFY_FRI_IDENTIFIER;
Expand All @@ -24,7 +23,8 @@ impl TaskHandler for VerifyFriJob {
});

span.set_parent(parent_cx);
let fri_verify_inputs = extract_verify_fri_input(&self.0.data.fri_proofs.clone()).unwrap();
let fri_verify_inputs =
extract_verify_fri_input(&self.0.data.sharp_proof.fri_proofs.clone()).unwrap();

info!("VERIFY FRI IN PROGRESS");
let state = _ctx.extensions().get::<State>().unwrap();
Expand Down
14 changes: 11 additions & 3 deletions crates/worker/src/jobs/verify_proof_and_register_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use graphile_worker::{IntoTaskHandlerResult, TaskHandler, WorkerContext};
use irelia_adapter::aptos_writer::contracts_caller::gps::extract_gps_input::extract_gps_input;
use irelia_adapter::aptos_writer::contracts_caller::gps::verify_proof_and_register::verify_proof_and_register;
use irelia_common::workers::{Worker, VERIFY_PROOF_AND_REGISTER_IDENTIFIER};
use irelia_core::entities::sharp_proof::SharpProof;
use irelia_core::entities::job::CairoJobStatus;
use irelia_core::entities::payload_verify_job::PayloadVerifyJob;
use serde::{Deserialize, Serialize};
use tracing::log::info;
use tracing::{instrument, Span};
Expand All @@ -11,7 +12,7 @@ use tracing_opentelemetry::OpenTelemetrySpanExt;
use crate::state::State;

#[derive(Deserialize, Serialize, Debug)]
pub struct VerifyAndRegisterJob(Worker<SharpProof>);
pub struct VerifyAndRegisterJob(Worker<PayloadVerifyJob>);

impl TaskHandler for VerifyAndRegisterJob {
const IDENTIFIER: &'static str = VERIFY_PROOF_AND_REGISTER_IDENTIFIER;
Expand All @@ -23,13 +24,20 @@ impl TaskHandler for VerifyAndRegisterJob {
});

span.set_parent(parent_cx);
let gps_verify_input = extract_gps_input(&self.0.data.main_proof).unwrap();
let gps_verify_input = extract_gps_input(&self.0.data.sharp_proof.main_proof).unwrap();

info!("VERIFY FRI IN PROGRESS");
let state = _ctx.extensions().get::<State>().unwrap();
verify_proof_and_register(&state.app_config, &gps_verify_input)
.await
.unwrap();

let mut job_status = self.0.data.job;
job_status.status = CairoJobStatus::ONCHAIN;
job_status.validation_done = true;

state.job_port.update(job_status).await.unwrap();

info!("=== VERIFY ONCHAIN SUCCESS ===");
}
}

0 comments on commit 5cc9b72

Please sign in to comment.