Skip to content

Commit fb33c4f

Browse files
committed
feat: submit proof message in gateway provider
1 parent 65ff097 commit fb33c4f

File tree

4 files changed

+98
-9
lines changed

4 files changed

+98
-9
lines changed

crates/sdk/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ hex = "0.4.3"
2626
ciborium = "=0.2.2"
2727
serde_repr = "0.1.19"
2828
dialoguer = "0.11.0"
29-
reqwest = { version = "0.12", features = ["json"] }
29+
reqwest = { version = "0.12", features = ["json", "multipart"] }
30+
alloy = { version = "1.1.1", features = ["default", "signer-keystore"] }

crates/sdk/src/aggregation_layer/gateway/provider.rs

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
use reqwest::Client;
1+
use alloy::network::EthereumWallet;
2+
use reqwest::{multipart, Client};
23
use serde::de::DeserializeOwned;
34

45
use crate::{
56
aggregation_layer::gateway::types::{
67
GatewayResponse, NonceResponse, Receipt, ReceiptsQuery, ReceiptsResponse,
8+
SubmitProofResponse, SubmitSP1ProofMessage,
79
},
810
common::types::Network,
911
};
1012

1113
pub struct AggregationModeGatewayProvider {
1214
gateway_url: String,
15+
signer: Option<EthereumWallet>,
1316
http_client: Client,
1417
}
1518

@@ -18,6 +21,7 @@ pub enum AggregationModeError {
1821
UnsupportedNetwork,
1922
Request(String),
2023
Api { status: u16, message: String },
24+
SignerNotConfigured,
2125
}
2226

2327
impl AggregationModeGatewayProvider {
@@ -31,12 +35,29 @@ impl AggregationModeGatewayProvider {
3135
Ok(Self {
3236
gateway_url,
3337
http_client: Client::new(),
38+
signer: None,
3439
})
3540
}
3641

37-
pub fn new_with_signer() {}
42+
pub fn new_with_signer(
43+
network: Network,
44+
signer: EthereumWallet,
45+
) -> Result<Self, AggregationModeError> {
46+
let gateway_url = match network {
47+
Network::Devnet => "http://127.0.0.1:8089".into(),
48+
_ => return Err(AggregationModeError::UnsupportedNetwork),
49+
};
50+
51+
Ok(Self {
52+
gateway_url,
53+
http_client: Client::new(),
54+
signer: Some(signer),
55+
})
56+
}
3857

39-
pub fn signer() {}
58+
pub fn signer(&self) -> Option<&EthereumWallet> {
59+
self.signer.as_ref()
60+
}
4061
}
4162

4263
impl AggregationModeGatewayProvider {
@@ -71,7 +92,37 @@ impl AggregationModeGatewayProvider {
7192
Ok(response.receipts)
7293
}
7394

74-
pub async fn submit_sp1_proof(&self, serialized_proof: Vec<u8>, serialized_vk: Vec<u8>) {}
95+
pub async fn submit_sp1_proof(
96+
&self,
97+
serialized_proof: Vec<u8>,
98+
serialized_vk: Vec<u8>,
99+
) -> Result<SubmitProofResponse, AggregationModeError> {
100+
let Some(signer) = &self.signer else {
101+
return Err(AggregationModeError::SignerNotConfigured);
102+
};
103+
let signer_address = signer.default_signer().address().to_string();
104+
105+
let nonce = self.get_nonce_for(signer_address).await?;
106+
let message = SubmitSP1ProofMessage::new(nonce, serialized_proof, serialized_vk).sign();
107+
let form = multipart::Form::new()
108+
.text("nonce", message.nonce.to_string())
109+
.part(
110+
"proof",
111+
multipart::Part::bytes(message.proof).file_name("proof.bin"),
112+
)
113+
.part(
114+
"program_vk",
115+
multipart::Part::bytes(message.program_vk).file_name("program_vk.bin"),
116+
)
117+
.text("signature_hex", hex::encode(message.signature));
118+
119+
let request = self
120+
.http_client
121+
.post(format!("{}/proof/sp1", self.gateway_url))
122+
.multipart(form);
123+
124+
self.send_request(request).await
125+
}
75126

76127
// TODO: verify proof from receipt merkle path
77128

crates/sdk/src/aggregation_layer/gateway/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ pub(super) struct ReceiptsResponse {
3434

3535
#[derive(Debug, Clone, Deserialize)]
3636
pub struct SubmitSP1ProofMessage {
37-
nonce: u64,
38-
proof: Vec<u8>,
39-
program_vk: Vec<u8>,
40-
signature: Vec<u8>,
37+
pub nonce: u64,
38+
pub proof: Vec<u8>,
39+
pub program_vk: Vec<u8>,
40+
pub signature: Vec<u8>,
4141
}
4242

4343
#[derive(Debug, Clone, Deserialize)]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use crate::common::types::Network;
2+
use reqwest::Client;
3+
use serde::{de::DeserializeOwned, Deserialize, Serialize};
4+
5+
#[derive(Debug, Clone, Deserialize)]
6+
pub struct GatewayReceipt {
7+
pub status: String,
8+
pub merkle_path: Vec<String>,
9+
pub nonce: i64,
10+
pub address: String,
11+
}
12+
13+
pub struct SubmitSP1ProofMessage {
14+
nonce: u64,
15+
proof: Vec<u8>,
16+
program_vk: Vec<u8>,
17+
signature: Vec<u8>,
18+
}
19+
20+
pub struct SubmitProofResponse {
21+
pub task_id: String,
22+
}
23+
24+
impl SubmitSP1ProofMessage {
25+
pub fn new(nonce: u64, serialized_proof: Vec<u8>, serialized_vk: Vec<u8>) -> Self {
26+
Self {
27+
nonce,
28+
proof: serialized_proof,
29+
program_vk: serialized_vk,
30+
signature: vec![],
31+
}
32+
}
33+
34+
pub fn sign(self) -> Self {
35+
self
36+
}
37+
}

0 commit comments

Comments
 (0)