12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- use std:: sync:: Arc ;
15
+ use std:: { str :: FromStr , sync:: Arc } ;
16
16
17
17
use alloy_primitives:: U256 ;
18
18
use alloy_sol_types:: { sol, SolValue } ;
19
19
use anyhow:: anyhow;
20
20
use bonsai_sdk:: alpha:: responses:: { Groth16Seal , SnarkReceipt } ;
21
21
use ethers_contract:: abigen;
22
- use ethers_core:: types:: H160 ;
22
+ use ethers_core:: { abi :: AbiDecode , types:: H160 } ;
23
23
use ethers_providers:: { Http , Provider , RetryClient } ;
24
+ use once_cell:: unsync:: Lazy ;
24
25
use risc0_zkvm:: sha:: { Digest , Digestible } ;
25
-
26
- static RISC_ZERO_VERIFIER : ethers_core:: types:: Address = H160 :: zero ( ) ;
26
+ use tracing:: { error as tracing_err, info as tracing_info} ;
27
27
28
28
sol ! (
29
29
/// A Groth16 seal over the claimed receipt claim.
@@ -85,7 +85,11 @@ pub async fn verify_groth16_snark(
85
85
image_id : Digest ,
86
86
snark_receipt : SnarkReceipt ,
87
87
) -> anyhow:: Result < ( ) > {
88
- let verifier_rpc_url = "TODO: http://fuckBonsai:8545" ;
88
+ let verifier_rpc_url = env ! ( "GROTH16_VERIFIER_RPC_URL" ) ;
89
+ let groth16_verifier_addr = {
90
+ let addr = env ! ( "GROTH16_VERIFIER_ADDRESS" ) ;
91
+ H160 :: from_str ( addr) . unwrap ( )
92
+ } ;
89
93
90
94
let http_client = Arc :: new ( Provider :: < RetryClient < Http > > :: new_client (
91
95
& verifier_rpc_url,
@@ -95,15 +99,15 @@ pub async fn verify_groth16_snark(
95
99
96
100
let seal = <Groth16Seal as Into < Seal > >:: into ( snark_receipt. snark ) . abi_encode ( ) ;
97
101
let journal_digest = snark_receipt. journal . digest ( ) ;
98
- log :: info !( "Verifying SNARK:" ) ;
99
- log :: info !( "Seal: {}" , hex:: encode( & seal) ) ;
100
- log :: info !( "Image ID: {}" , hex:: encode( image_id. as_bytes( ) ) ) ;
101
- log :: info !(
102
+ tracing_info ! ( "Verifying SNARK:" ) ;
103
+ tracing_info ! ( "Seal: {}" , hex:: encode( & seal) ) ;
104
+ tracing_info ! ( "Image ID: {}" , hex:: encode( image_id. as_bytes( ) ) ) ;
105
+ tracing_info ! (
102
106
"Post State Digest: {}" ,
103
107
hex:: encode( & snark_receipt. post_state_digest)
104
108
) ;
105
- log :: info !( "Journal Digest: {}" , hex:: encode( journal_digest. as_bytes( ) ) ) ;
106
- let verification = IRiscZeroVerifier :: new ( RISC_ZERO_VERIFIER , http_client)
109
+ tracing_info ! ( "Journal Digest: {}" , hex:: encode( journal_digest. as_bytes( ) ) ) ;
110
+ let verification: bool = IRiscZeroVerifier :: new ( groth16_verifier_addr , http_client)
107
111
. verify (
108
112
seal. into ( ) ,
109
113
image_id. as_bytes ( ) . try_into ( ) . unwrap ( ) ,
@@ -117,9 +121,12 @@ pub async fn verify_groth16_snark(
117
121
. await ?;
118
122
119
123
if verification {
120
- log:: info!( "SNARK verified successfully using {}!" , RISC_ZERO_VERIFIER ) ;
124
+ tracing_info ! (
125
+ "SNARK verified successfully using {:?}!" ,
126
+ groth16_verifier_addr
127
+ ) ;
121
128
} else {
122
- log :: error !( "SNARK verification failed!" ) ;
129
+ tracing_err ! ( "SNARK verification failed!" ) ;
123
130
}
124
131
125
132
Ok ( ( ) )
0 commit comments