@@ -2,6 +2,7 @@ use crate::gnark::verify_gnark;
22use crate :: risc_zero:: verify_risc_zero_proof;
33use crate :: sp1:: verify_sp1_proof;
44use aligned_sdk:: core:: types:: { ProvingSystemId , VerificationData } ;
5+ use ethers:: types:: U256 ;
56use log:: { debug, warn} ;
67
78pub ( crate ) async fn verify ( verification_data : & VerificationData ) -> bool {
@@ -61,3 +62,110 @@ fn verify_internal(verification_data: &VerificationData) -> bool {
6162 }
6263 }
6364}
65+
66+ pub ( crate ) fn is_verifier_disabled (
67+ disabled_verifiers : U256 ,
68+ verification_data : & VerificationData ,
69+ ) -> bool {
70+ disabled_verifiers & ( U256 :: one ( ) << verification_data. proving_system as u64 ) != U256 :: zero ( )
71+ }
72+
73+ #[ cfg( test) ]
74+ mod test {
75+ use super :: is_verifier_disabled;
76+ use aligned_sdk:: core:: types:: { ProvingSystemId , VerificationData } ;
77+ use ethers:: types:: Address ;
78+
79+ fn get_all_verifiers ( ) -> Vec < ProvingSystemId > {
80+ let verifiers = vec ! [
81+ ProvingSystemId :: GnarkPlonkBls12_381 ,
82+ ProvingSystemId :: GnarkPlonkBn254 ,
83+ ProvingSystemId :: Groth16Bn254 ,
84+ ProvingSystemId :: SP1 ,
85+ ProvingSystemId :: Risc0 ,
86+ ] ;
87+ // Just to make sure we are not missing any verifier. The compilation will fail if we do and it forces us to add it to the vec above.
88+ for verifier in verifiers. iter ( ) {
89+ match verifier {
90+ ProvingSystemId :: SP1 => ( ) ,
91+ ProvingSystemId :: Risc0 => ( ) ,
92+ ProvingSystemId :: GnarkPlonkBls12_381 => ( ) ,
93+ ProvingSystemId :: GnarkPlonkBn254 => ( ) ,
94+ ProvingSystemId :: Groth16Bn254 => ( ) ,
95+ }
96+ }
97+ verifiers
98+ }
99+
100+ #[ test]
101+ fn test_all_verifiers_enabled ( ) {
102+ let disabled_verifiers = ethers:: types:: U256 :: zero ( ) ;
103+ for verifier in get_all_verifiers ( ) . iter ( ) {
104+ let verification_data = VerificationData {
105+ proving_system : * verifier,
106+ vm_program_code : None ,
107+ pub_input : None ,
108+ proof : vec ! [ ] ,
109+ verification_key : None ,
110+ proof_generator_addr : Address :: zero ( ) ,
111+ } ;
112+ assert ! (
113+ !is_verifier_disabled( disabled_verifiers, & verification_data) ,
114+ "Verifier {:?} should not be disabled" ,
115+ verifier
116+ ) ;
117+ }
118+ }
119+
120+ #[ test]
121+ fn test_all_verifiers_disabled ( ) {
122+ let verifiers = get_all_verifiers ( ) ;
123+ // This creates a number with all bits set to 1 depending on the number of verifiers to disable all of them.
124+ let disabled_verifiers = ethers:: types:: U256 :: from ( 2u64 . pow ( verifiers. len ( ) as u32 ) - 1 ) ;
125+ for verifier in get_all_verifiers ( ) . iter ( ) {
126+ let verification_data = VerificationData {
127+ proving_system : * verifier,
128+ vm_program_code : None ,
129+ pub_input : None ,
130+ proof : vec ! [ ] ,
131+ verification_key : None ,
132+ proof_generator_addr : Address :: zero ( ) ,
133+ } ;
134+ assert ! (
135+ is_verifier_disabled( disabled_verifiers, & verification_data) ,
136+ "Verifier {:?} should be disabled" ,
137+ verifier
138+ ) ;
139+ }
140+ }
141+
142+ #[ test]
143+ fn test_some_verifiers_disabled ( ) {
144+ let verifiers = get_all_verifiers ( ) ;
145+ // Disabling only the first verifier
146+ let disabled_verifiers = ethers:: types:: U256 :: from ( 0b10001 ) ;
147+ for verifier in get_all_verifiers ( ) . iter ( ) {
148+ let verification_data = VerificationData {
149+ proving_system : * verifier,
150+ vm_program_code : None ,
151+ pub_input : None ,
152+ proof : vec ! [ ] ,
153+ verification_key : None ,
154+ proof_generator_addr : Address :: zero ( ) ,
155+ } ;
156+ if verifier == & verifiers[ 0 ] || verifier == & verifiers[ verifiers. len ( ) - 1 ] {
157+ assert ! (
158+ is_verifier_disabled( disabled_verifiers, & verification_data) ,
159+ "Verifier {:?} should be disabled" ,
160+ verifier
161+ ) ;
162+ } else {
163+ assert ! (
164+ !is_verifier_disabled( disabled_verifiers, & verification_data) ,
165+ "Verifier {:?} should not be disabled" ,
166+ verifier
167+ ) ;
168+ }
169+ }
170+ }
171+ }
0 commit comments