@@ -8,7 +8,9 @@ use actix_web::{
88 web:: { self , Data } ,
99 App , HttpRequest , HttpResponse , HttpServer , Responder ,
1010} ;
11+ use agg_mode_sdk:: types:: Network ;
1112use aligned_sdk:: aggregation_layer:: AggregationModeProvingSystem ;
13+ use alloy:: signers:: Signature ;
1214use sp1_sdk:: { SP1ProofWithPublicValues , SP1VerifyingKey } ;
1315use sqlx:: types:: BigDecimal ;
1416
@@ -28,11 +30,17 @@ use crate::{
2830pub struct BatcherServer {
2931 db : Db ,
3032 config : Config ,
33+ network : Network ,
3134}
3235
3336impl BatcherServer {
3437 pub fn new ( db : Db , config : Config ) -> Self {
35- Self { db, config }
38+ let network = Network :: from_str ( & config. network ) . expect ( "A valid network in config file" ) ;
39+ Self {
40+ db,
41+ config,
42+ network,
43+ }
3644 }
3745
3846 pub async fn start ( & self ) {
@@ -93,13 +101,40 @@ impl BatcherServer {
93101 req : HttpRequest ,
94102 MultipartForm ( data) : MultipartForm < SubmitProofRequestSP1 > ,
95103 ) -> impl Responder {
96- let recovered_address = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" . to_lowercase ( ) ;
97-
98104 let Some ( state) = req. app_data :: < Data < BatcherServer > > ( ) else {
99105 return HttpResponse :: InternalServerError ( )
100106 . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
101107 } ;
108+
102109 let state = state. get_ref ( ) ;
110+ let Ok ( signature) = Signature :: from_str ( & data. signature_hex . 0 ) else {
111+ return HttpResponse :: InternalServerError ( )
112+ . json ( AppResponse :: new_unsucessfull ( "Invalid signature" , 500 ) ) ;
113+ } ;
114+
115+ let Ok ( proof_content) = tokio:: fs:: read ( data. proof . file . path ( ) ) . await else {
116+ return HttpResponse :: InternalServerError ( )
117+ . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
118+ } ;
119+
120+ let Ok ( vk_content) = tokio:: fs:: read ( data. program_vk . file . path ( ) ) . await else {
121+ return HttpResponse :: InternalServerError ( )
122+ . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
123+ } ;
124+
125+ // reconstruct message and recover address
126+ let msg = agg_mode_sdk:: gateway:: types:: SubmitSP1ProofMessage :: new (
127+ data. nonce . 0 ,
128+ proof_content. clone ( ) ,
129+ vk_content. clone ( ) ,
130+ ) ;
131+ let Ok ( recovered_address) =
132+ signature. recover_address_from_prehash ( & msg. eip712_hash ( & state. network ) . into ( ) )
133+ else {
134+ return HttpResponse :: InternalServerError ( )
135+ . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
136+ } ;
137+ let recovered_address = recovered_address. to_string ( ) . to_lowercase ( ) ;
103138
104139 // Checking if this address has submited more proofs than the ones allowed per day
105140 let Ok ( daily_tasks_by_address) = state
@@ -160,22 +195,11 @@ impl BatcherServer {
160195 400 ,
161196 ) ) ;
162197 }
163-
164- let Ok ( proof_content) = tokio:: fs:: read ( data. proof . file . path ( ) ) . await else {
165- return HttpResponse :: InternalServerError ( )
166- . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
167- } ;
168-
169198 let Ok ( proof) = bincode:: deserialize :: < SP1ProofWithPublicValues > ( & proof_content) else {
170199 return HttpResponse :: BadRequest ( )
171200 . json ( AppResponse :: new_unsucessfull ( "Invalid SP1 proof" , 400 ) ) ;
172201 } ;
173202
174- let Ok ( vk_content) = tokio:: fs:: read ( data. program_vk . file . path ( ) ) . await else {
175- return HttpResponse :: InternalServerError ( )
176- . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
177- } ;
178-
179203 let Ok ( vk) = bincode:: deserialize :: < SP1VerifyingKey > ( & vk_content) else {
180204 return HttpResponse :: BadRequest ( )
181205 . json ( AppResponse :: new_unsucessfull ( "Invalid vk" , 400 ) ) ;
0 commit comments