Skip to content

Commit d3adcf8

Browse files
committed
feat: [wip] post proofs
1 parent b9abb7d commit d3adcf8

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed

aggregation_mode/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aggregation_mode/batcher/src/server/http.rs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use actix_web::{
2-
web::{self, Data, Query},
2+
web::{self, Data},
33
App, HttpRequest, HttpResponse, HttpServer, Responder,
44
};
5-
use serde::Deserialize;
5+
use aligned_sdk::aggregation_layer::AggregationModeProvingSystem;
66

77
use super::{
88
helpers::format_merkle_path,
99
types::{AppResponse, ProofMerkleQuery},
1010
};
1111

12-
use crate::{config::Config, db::Db};
12+
use crate::{config::Config, db::Db, server::types::SubmitProofRequest};
1313

1414
#[derive(Clone, Debug)]
1515
pub struct BatcherServer {
@@ -32,7 +32,8 @@ impl BatcherServer {
3232
.app_data(Data::new(state.clone()))
3333
.route("/nonce/{address}", web::get().to(Self::get_nonce))
3434
.route("/proof/merkle", web::get().to(Self::get_proof_merkle_path))
35-
.route("/proof", web::post().to(Self::post_proof))
35+
.route("/proof/sp1", web::post().to(Self::post_proof_sp1))
36+
.route("/proof/risc0", web::post().to(Self::post_proof_risc0))
3637
})
3738
.bind(("127.0.0.1", port))?
3839
.run()
@@ -61,14 +62,41 @@ impl BatcherServer {
6162
))),
6263
Err(err) => {
6364
tracing::error!(error = ?err, "failed to count proofs");
64-
HttpResponse::InternalServerError().finish()
65+
HttpResponse::InternalServerError()
66+
.json(AppResponse::new_unsucessfull("Internal server error", 500))
6567
}
6668
}
6769
}
6870

6971
// TODO: receive the proof and 1. decode it, 2. verify it, 3. add to the db
70-
async fn post_proof(req: HttpRequest) -> impl Responder {
71-
HttpResponse::Ok()
72+
async fn post_proof_sp1(
73+
req: HttpRequest,
74+
body: web::Json<SubmitProofRequest>,
75+
) -> impl Responder {
76+
let data = body.into_inner();
77+
78+
// TODO: validate signature
79+
let recovered_address = "";
80+
81+
let Some(state) = req.app_data::<Data<BatcherServer>>() else {
82+
return HttpResponse::InternalServerError()
83+
.json(AppResponse::new_unsucessfull("Internal server error", 500));
84+
};
85+
let state = state.get_ref();
86+
87+
let Ok(count) = state.db.count_proofs_by_address(recovered_address).await else {
88+
return HttpResponse::InternalServerError().finish();
89+
};
90+
91+
HttpResponse::Ok().json(AppResponse::new_sucessfull(serde_json::json!({})))
92+
}
93+
94+
/// TODO: complete for risc0 (see `post_proof_sp1`)
95+
async fn post_proof_risc0(
96+
_req: HttpRequest,
97+
_body: web::Json<SubmitProofRequest>,
98+
) -> impl Responder {
99+
HttpResponse::Ok().json(AppResponse::new_sucessfull(serde_json::json!({})))
72100
}
73101

74102
async fn get_proof_merkle_path(
@@ -111,7 +139,7 @@ impl BatcherServer {
111139
404,
112140
))
113141
}
114-
Err(s) => {
142+
Err(_) => {
115143
return HttpResponse::InternalServerError()
116144
.json(AppResponse::new_unsucessfull("Internal server error", 500));
117145
}

aggregation_mode/batcher/src/server/types.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use aligned_sdk::aggregation_layer::AggregationModeProvingSystem;
12
use serde::{Deserialize, Serialize};
23
use serde_json::Value;
34

@@ -26,7 +27,24 @@ impl AppResponse {
2627
}
2728
}
2829

30+
// TODO: move this to the sdk once ready
31+
2932
#[derive(Deserialize, Clone)]
3033
pub(super) struct ProofMerkleQuery {
3134
pub id: Option<String>,
3235
}
36+
37+
#[derive(Serialize, Deserialize, Clone, Debug)]
38+
pub(super) struct SubmitProofRequest {
39+
pub message: SubmitProofRequestMessage,
40+
pub signature: String,
41+
}
42+
43+
#[derive(Serialize, Deserialize, Clone, Debug)]
44+
pub(super) struct SubmitProofRequestMessage {
45+
pub nonce: u64,
46+
pub proving_system_id: AggregationModeProvingSystem,
47+
pub proof: Vec<u8>,
48+
pub public_inputs: Option<Vec<u8>>,
49+
pub program_id: Vec<u8>,
50+
}

aggregation_mode/db/migrations/001_init.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CREATE TYPE task_status AS ENUM ('pending', 'verified');
22

33
CREATE TABLE tasks (
44
task_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
5-
status task_status
5+
status task_status DEFAULT 'pending'
66
);
77

88
CREATE TABLE proofs (

crates/sdk/src/aggregation_layer/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use lambdaworks_crypto::merkle_tree::traits::IsMerkleTreeBackend;
2+
use serde::{Deserialize, Serialize};
23
use sha3::{Digest, Keccak256};
34

45
use crate::beacon::BeaconClientError;
56

67
#[repr(u16)]
7-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8+
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
89
pub enum AggregationModeProvingSystem {
910
SP1 = 1,
1011
RISC0 = 2,

0 commit comments

Comments
 (0)