11use anyhow:: Context ;
22use anyhow:: Result ;
33use plonky2:: field:: types:: Field ;
4- use plonky2:: hash:: poseidon :: PoseidonHash ;
4+ use plonky2:: hash:: poseidon2 :: Poseidon2Hash ;
55use plonky2:: plonk:: circuit_data:: CircuitConfig ;
66use plonky2:: plonk:: config:: { Hasher , PoseidonGoldilocksConfig } ;
77use plonky2:: util:: serialization:: { DefaultGateSerializer , DefaultGeneratorSerializer } ;
@@ -10,17 +10,22 @@ use serde::de::DeserializeOwned;
1010use std:: path:: { Path , PathBuf } ;
1111use std:: process:: Command ;
1212use std:: { env, fs} ;
13+ use test_helpers:: storage_proof:: TestInputs ;
14+ use test_helpers:: DEFAULT_FUNDING_ACCOUNT ;
15+ use test_helpers:: DEFAULT_SECRETS ;
1316use wormhole_circuit:: circuit:: circuit_logic:: WormholeCircuit ;
1417use wormhole_circuit:: circuit:: { circuit_data_from_bytes, circuit_data_to_bytes} ;
1518use wormhole_circuit:: inputs:: { CircuitInputs , PrivateCircuitInputs , PublicCircuitInputs } ;
1619use wormhole_circuit:: nullifier:: Nullifier ;
20+ use wormhole_circuit:: storage_proof:: leaf:: LeafInputs ;
1721use wormhole_circuit:: storage_proof:: ProcessedStorageProof ;
1822use wormhole_circuit:: substrate_account:: SubstrateAccount ;
1923use wormhole_circuit:: unspendable_account:: UnspendableAccount ;
2024use wormhole_prover:: WormholeProver ;
2125use wormhole_verifier:: WormholeVerifier ;
2226use zk_circuits_common:: circuit:: { TransferProofJson , D , F } ;
23- use zk_circuits_common:: utils:: u64_to_felts;
27+ use zk_circuits_common:: utils:: felts_to_u128;
28+ use zk_circuits_common:: utils:: felts_to_u64;
2429use zk_circuits_common:: utils:: BytesDigest ;
2530use zk_circuits_common:: utils:: { digest_felts_to_bytes, u128_to_felts} ;
2631
@@ -140,33 +145,42 @@ fn test_prover_and_verifier_from_file_e2e() -> Result<()> {
140145 let verifier = WormholeVerifier :: new_from_files ( & verifier_path, & common_path) ?;
141146
142147 // Create inputs
143- let funding_account = SubstrateAccount :: new ( & [ 2u8 ; 32 ] ) ?;
144- let secret = BytesDigest :: try_from ( [ 1u8 ; 32 ] ) . unwrap ( ) ;
145- let unspendable_account = UnspendableAccount :: from_secret ( secret) . account_id ;
146- let funding_amount = 1000u128 ;
147- let transfer_count = 0u64 ;
148+ let leaf_inputs = LeafInputs :: test_inputs_0 ( ) ;
149+ let secret =
150+ BytesDigest :: try_from ( hex:: decode ( DEFAULT_SECRETS [ 0 ] ) . unwrap ( ) . as_slice ( ) ) . unwrap ( ) ;
151+ let funding_account = leaf_inputs. funding_account ;
152+ // let secret = BytesDigest::try_from([1u8; 32]).unwrap();
153+ let unspendable_account = leaf_inputs. to_account ;
154+ let funding_amount = leaf_inputs. funding_amount ;
155+ let transfer_count = leaf_inputs. transfer_count ;
148156
149157 let mut leaf_inputs_felts = Vec :: new ( ) ;
150- leaf_inputs_felts. extend ( & u64_to_felts ( transfer_count) ) ;
151- leaf_inputs_felts. extend_from_slice ( & funding_account. 0 ) ;
152- leaf_inputs_felts. extend_from_slice ( & unspendable_account) ;
153- leaf_inputs_felts. extend_from_slice ( & u128_to_felts ( funding_amount) ) ;
158+ leaf_inputs_felts. extend ( transfer_count) ;
159+ leaf_inputs_felts. extend_from_slice ( funding_account. as_slice ( ) ) ;
160+ leaf_inputs_felts. extend_from_slice ( unspendable_account. as_slice ( ) ) ;
161+ leaf_inputs_felts. extend ( funding_amount) ;
154162
155- let leaf_inputs_hash = PoseidonHash :: hash_no_pad ( & leaf_inputs_felts) ;
163+ let transfer_count = felts_to_u64 ( transfer_count) . unwrap ( ) ;
164+ let funding_amount = felts_to_u128 ( funding_amount) . unwrap ( ) ;
165+
166+ let leaf_inputs_hash = Poseidon2Hash :: hash_no_pad ( & leaf_inputs_felts) ;
156167 let root_hash: [ u8 ; 32 ] = * digest_felts_to_bytes ( leaf_inputs_hash. elements ) ;
157168
169+ // print the hex of the root hash
170+ println ! ( "root_hash: {}" , hex:: encode( root_hash) ) ;
171+
158172 let exit_account = SubstrateAccount :: new ( & [ 2u8 ; 32 ] ) ?;
159173 let inputs = CircuitInputs {
160174 private : PrivateCircuitInputs {
161175 secret,
162176 funding_account : ( * funding_account) . into ( ) ,
163177 storage_proof : ProcessedStorageProof :: new ( vec ! [ ] , vec ! [ ] ) . unwrap ( ) ,
164- unspendable_account : ( unspendable_account) . into ( ) ,
178+ unspendable_account : ( * unspendable_account) . into ( ) ,
165179 transfer_count,
166180 } ,
167181 public : PublicCircuitInputs {
168182 funding_amount,
169- nullifier : Nullifier :: from_preimage ( secret, 0 ) . hash . into ( ) ,
183+ nullifier : Nullifier :: from_preimage ( secret, transfer_count ) . hash . into ( ) ,
170184 root_hash : root_hash. try_into ( ) . unwrap ( ) ,
171185 exit_account : ( * exit_account) . into ( ) ,
172186 } ,
@@ -269,10 +283,7 @@ fn test_prover_and_verifier_fuzzing() -> Result<()> {
269283 ProcessedStorageProof :: new ( storage_proof_bytes, proof_json. indices . clone ( ) )
270284 . context ( "failed to build ProcessedStorageProof" ) ?;
271285
272- let funding_account = SubstrateAccount :: new ( & [
273- 223 , 23 , 232 , 59 , 97 , 108 , 223 , 113 , 2 , 89 , 54 , 39 , 126 , 65 , 248 , 106 , 156 , 219 , 7 ,
274- 123 , 213 , 197 , 228 , 118 , 177 , 81 , 61 , 77 , 23 , 89 , 200 , 80 ,
275- ] ) ?; // Alice test account from dev node.
286+ let funding_account = SubstrateAccount :: new ( & DEFAULT_FUNDING_ACCOUNT ) ?;
276287 let secret = BytesDigest :: try_from ( secret. as_slice ( ) ) . unwrap ( ) ;
277288 let unspendable_account = UnspendableAccount :: from_secret ( secret) . account_id ;
278289
0 commit comments