@@ -2,16 +2,20 @@ use crate::cfg::CelestiaConfig;
2
2
use anyhow:: { Context , Result } ;
3
3
use async_trait:: async_trait;
4
4
use prism_errors:: { DataAvailabilityError , GeneralError } ;
5
+ use sp1_sdk:: { ProverClient , SP1VerifyingKey } ;
5
6
use std:: { self , sync:: Arc , time:: Duration } ;
6
7
use tokio:: { task:: spawn, time:: interval} ;
7
8
8
9
use crate :: { da:: DataAvailabilityLayer , node_types:: NodeType , utils:: verify_signature} ;
9
10
11
+ pub const PRISM_ELF : & [ u8 ] = include_bytes ! ( "../../../../elf/riscv32im-succinct-zkvm-elf" ) ;
12
+
10
13
pub struct LightClient {
11
14
pub da : Arc < dyn DataAvailabilityLayer > ,
12
- // verifying_key is the [`VerifyingKey`] used to verify epochs from the prover/sequencer
13
- pub verifying_key : Option < String > ,
14
- start_height : u64 ,
15
+ pub sequencer_pubkey : Option < String > ,
16
+ pub client : ProverClient ,
17
+ pub verifying_key : SP1VerifyingKey ,
18
+ pub start_height : u64 ,
15
19
}
16
20
17
21
#[ async_trait]
@@ -35,11 +39,15 @@ impl LightClient {
35
39
pub fn new (
36
40
da : Arc < dyn DataAvailabilityLayer > ,
37
41
cfg : CelestiaConfig ,
38
- sequencer_pub_key : Option < String > ,
42
+ sequencer_pubkey : Option < String > ,
39
43
) -> LightClient {
44
+ let client = ProverClient :: new ( ) ;
45
+ let ( _, verifying_key) = client. setup ( PRISM_ELF ) ;
40
46
LightClient {
41
47
da,
42
- verifying_key : sequencer_pub_key,
48
+ verifying_key,
49
+ client,
50
+ sequencer_pubkey,
43
51
start_height : cfg. start_height ,
44
52
}
45
53
}
@@ -71,33 +79,15 @@ impl LightClient {
71
79
72
80
// todo: verify adjacency to last heights, <- for this we need some sort of storage of epochs
73
81
for epoch_json in epoch_json_vec {
74
- // let prev_commitment = &epoch_json.prev_commitment;
75
- // let current_commitment = &epoch_json.current_commitment;
76
-
77
- // let proof = match epoch_json.proof.clone().try_into() {
78
- // Ok(proof) => proof,
79
- // Err(e) => {
80
- // error!("failed to deserialize proof, skipping a blob at height {}: {:?}", i, e);
81
- // continue;
82
- // }
83
- // };
84
-
85
- // TODO(@distractedm1nd): i don't know rust yet but this seems like non-idiomatic rust -
86
- // is there not a Trait that can satisfy these properties for us?
87
- // let verifying_key = match epoch_json.verifying_key.clone().try_into() {
88
- // Ok(vk) => vk,
89
- // Err(e) => {
90
- // error!("failed to deserialize verifying key, skipping a blob at height {}: {:?}", i, e);
91
- // continue;
92
- // }
93
- // };
82
+ let prev_commitment = & epoch_json. prev_commitment ;
83
+ let current_commitment = & epoch_json. current_commitment ;
94
84
95
85
// if the user does not add a verifying key, we will not verify the signature,
96
86
// but only log a warning on startup
97
- if self . verifying_key . is_some ( ) {
87
+ if self . sequencer_pubkey . is_some ( ) {
98
88
match verify_signature (
99
89
& epoch_json. clone ( ) ,
100
- self . verifying_key . clone ( ) ,
90
+ self . sequencer_pubkey . clone ( ) ,
101
91
) {
102
92
Ok ( _) => trace ! (
103
93
"valid signature for epoch {}" ,
@@ -109,20 +99,20 @@ impl LightClient {
109
99
}
110
100
}
111
101
112
- // match validate_epoch(
113
- // prev_commitment,
114
- // current_commitment,
115
- // proof,
116
- // verifying_key,
117
- // ) {
118
- // Ok(_) => {
119
- // info!(
120
- // "zkSNARK for epoch {} was validated successfully",
121
- // epoch_json.height
122
- // )
123
- // }
124
- // Err(err) => panic!("failed to validate epoch: {:?}", err ),
125
- // }
102
+ // TODO: compare commitment to epoch_json.proof.public_values
103
+
104
+ match self . client . verify ( & epoch_json . proof , & self . verifying_key ) {
105
+ Ok ( _ ) => {
106
+ info ! (
107
+ "zkSNARK for epoch {} was validated successfully" ,
108
+ epoch_json . height
109
+ )
110
+ }
111
+ Err ( err ) => panic ! (
112
+ "failed to validate epoch at height {}: {:?}" ,
113
+ epoch_json . height , err
114
+ ) ,
115
+ }
126
116
}
127
117
}
128
118
Err ( e) => {
0 commit comments