Skip to content

Commit 5152746

Browse files
committed
feat: recover address on gateway
1 parent 140164e commit 5152746

File tree

4 files changed

+58
-18
lines changed

4 files changed

+58
-18
lines changed

aggregation_mode/Cargo.lock

Lines changed: 18 additions & 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: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use actix_web::{
88
web::{self, Data},
99
App, HttpRequest, HttpResponse, HttpServer, Responder,
1010
};
11-
use aligned_sdk::aggregation_layer::AggregationModeProvingSystem;
11+
use aligned_sdk::aggregation_layer::{self, AggregationModeProvingSystem};
12+
use alloy::signers::Signature;
1213
use sp1_sdk::{SP1ProofWithPublicValues, SP1VerifyingKey};
1314
use sqlx::types::BigDecimal;
1415

@@ -95,7 +96,34 @@ impl BatcherServer {
9596
req: HttpRequest,
9697
MultipartForm(data): MultipartForm<SubmitProofRequestSP1>,
9798
) -> impl Responder {
98-
let recovered_address = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8".to_lowercase();
99+
let Ok(signature) = Signature::from_str(&data.signature_hex.0) else {
100+
return HttpResponse::InternalServerError()
101+
.json(AppResponse::new_unsucessfull("Invalid signature", 500));
102+
};
103+
104+
let Ok(proof_content) = tokio::fs::read(data.proof.file.path()).await else {
105+
return HttpResponse::InternalServerError()
106+
.json(AppResponse::new_unsucessfull("Internal server error", 500));
107+
};
108+
109+
let Ok(vk_content) = tokio::fs::read(data.program_vk.file.path()).await else {
110+
return HttpResponse::InternalServerError()
111+
.json(AppResponse::new_unsucessfull("Internal server error", 500));
112+
};
113+
114+
let msg = aggregation_layer::gateway::types::SubmitSP1ProofMessage::new(
115+
data.nonce.0,
116+
proof_content.clone(),
117+
vk_content.clone(),
118+
);
119+
let Ok(recovered_address) = signature.recover_address_from_prehash(
120+
&msg.eip712_hash(&aligned_sdk::common::types::Network::Devnet)
121+
.into(),
122+
) else {
123+
return HttpResponse::InternalServerError()
124+
.json(AppResponse::new_unsucessfull("Internal server error", 500));
125+
};
126+
let recovered_address = recovered_address.to_string().to_lowercase();
99127

100128
let Some(state) = req.app_data::<Data<BatcherServer>>() else {
101129
return HttpResponse::InternalServerError()
@@ -145,22 +173,11 @@ impl BatcherServer {
145173
400,
146174
));
147175
}
148-
149-
let Ok(proof_content) = tokio::fs::read(data.proof.file.path()).await else {
150-
return HttpResponse::InternalServerError()
151-
.json(AppResponse::new_unsucessfull("Internal server error", 500));
152-
};
153-
154176
let Ok(proof) = bincode::deserialize::<SP1ProofWithPublicValues>(&proof_content) else {
155177
return HttpResponse::BadRequest()
156178
.json(AppResponse::new_unsucessfull("Invalid SP1 proof", 400));
157179
};
158180

159-
let Ok(vk_content) = tokio::fs::read(data.program_vk.file.path()).await else {
160-
return HttpResponse::InternalServerError()
161-
.json(AppResponse::new_unsucessfull("Internal server error", 500));
162-
};
163-
164181
let Ok(vk) = bincode::deserialize::<SP1VerifyingKey>(&vk_content) else {
165182
return HttpResponse::BadRequest()
166183
.json(AppResponse::new_unsucessfull("Invalid vk", 400));

aggregation_mode/batcher/src/server/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub(super) struct SubmitProofRequestSP1 {
4444
pub nonce: Text<u64>,
4545
pub proof: TempFile,
4646
pub program_vk: TempFile,
47-
pub _signature_hex: Text<String>,
47+
pub signature_hex: Text<String>,
4848
}
4949

5050
#[derive(Debug, MultipartForm)]

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl SubmitSP1ProofMessage {
7575
output
7676
}
7777

78-
pub async fn sign<S: Signer>(mut self, signer: &S, network: &Network) -> Self {
78+
pub fn eip712_hash(&self, network: &Network) -> [u8; 32] {
7979
let domain_value = DynSolValue::Tuple(vec![
8080
DynSolValue::String("Aligned".to_string()),
8181
DynSolValue::String("1".to_string()),
@@ -92,10 +92,15 @@ impl SubmitSP1ProofMessage {
9292

9393
let domain_separator = keccak256(&encoded_domain);
9494
let message_hash = keccak256(&encoded_message);
95-
let eip712_hash =
96-
keccak256([&[0x19, 0x01], &domain_separator[..], &message_hash[..]].concat());
9795

98-
let signature = signer.sign_hash(&eip712_hash).await.unwrap();
96+
keccak256([&[0x19, 0x01], &domain_separator[..], &message_hash[..]].concat()).0
97+
}
98+
99+
pub async fn sign<S: Signer>(mut self, signer: &S, network: &Network) -> Self {
100+
let signature = signer
101+
.sign_hash(&self.eip712_hash(network).into())
102+
.await
103+
.unwrap();
99104

100105
self.signature = signature.as_bytes().to_vec();
101106

0 commit comments

Comments
 (0)