1+ use anyhow:: { Ok , Result } ;
12use k256:: { ecdsa:: SigningKey , elliptic_curve:: sec1:: ToEncodedPoint } ;
23use serde:: { Deserialize , Serialize } ;
34use sha2:: { Digest , Sha256 } ;
4- use utxo_test_data_generator:: test_data_gen:: { TestUtxo , generate_test_utxos} ;
55use std:: fs:: { self , File } ;
66use std:: io:: Write ;
7- use anyhow:: { Ok , Result } ;
87use std:: process:: Command ;
8+ use utxo_test_data_generator:: test_data_gen:: { TestUtxo , generate_test_utxos} ;
99
1010const MAX_COINS_DATABASE_AMOUNT : usize = 5 ;
1111const MAX_NODES_AMOUNT : usize = 8 ;
@@ -38,7 +38,7 @@ struct NodeProof {
3838#[ derive( Serialize , Deserialize ) ]
3939struct NodeToml {
4040 verification_key : Vec < String > ,
41- node_proofs : Vec < NodeProof >
41+ node_proofs : Vec < NodeProof > ,
4242}
4343
4444fn main ( ) {
@@ -109,41 +109,55 @@ fn main() {
109109 . expect ( "failed to execute command" ) ;
110110
111111 assert ! ( status. success( ) , "Command return non-zero status" ) ;
112-
113112}
114113
115114fn leafs_toml ( utxos : Vec < TestUtxo > , message_hash : & [ u8 ; 32 ] , public_key : & [ u8 ] ) -> Result < ( ) > {
116- let mut coins_database: Vec < CoinsDatabaseElement > = utxos. iter ( ) . map ( |e| CoinsDatabaseElement { script_pub_key : hex:: decode ( & e. script_pub_key ) . unwrap ( ) , amount : e. amount } ) . collect ( ) ;
115+ let mut coins_database: Vec < CoinsDatabaseElement > = utxos
116+ . iter ( )
117+ . map ( |e| CoinsDatabaseElement {
118+ script_pub_key : hex:: decode ( & e. script_pub_key ) . unwrap ( ) ,
119+ amount : e. amount ,
120+ } )
121+ . collect ( ) ;
117122
118123 let append_from = coins_database. len ( ) ;
119- let append_to = ( ( coins_database. len ( ) + MAX_COINS_DATABASE_AMOUNT - 1 ) / MAX_COINS_DATABASE_AMOUNT ) * MAX_COINS_DATABASE_AMOUNT ;
124+ let append_to = ( ( coins_database. len ( ) + MAX_COINS_DATABASE_AMOUNT - 1 )
125+ / MAX_COINS_DATABASE_AMOUNT )
126+ * MAX_COINS_DATABASE_AMOUNT ;
120127
121128 for _ in append_from..append_to {
122- coins_database. push ( CoinsDatabaseElement { script_pub_key : Vec :: from ( [ 0 ; 25 ] ) , amount : 0 } ) ;
129+ coins_database. push ( CoinsDatabaseElement {
130+ script_pub_key : Vec :: from ( [ 0 ; 25 ] ) ,
131+ amount : 0 ,
132+ } ) ;
123133 }
124134
125135 let mut own_utxos: Vec < Spending > = utxos
126- . iter ( )
127- . map ( |e| {
128- let mut witness = hex:: decode ( & e. witness ) . unwrap ( ) ;
129- if witness. len ( ) < 72 {
130- witness. resize ( 72 , 0 ) ;
131- }
132-
133- let mut pub_key = Vec :: from ( public_key) ;
134- if pub_key. len ( ) < 65 {
135- pub_key. resize ( 65 , 0 ) ;
136- }
137-
138- Spending { witness, pub_key }
139- } )
136+ . iter ( )
137+ . map ( |e| {
138+ let mut witness = hex:: decode ( & e. witness ) . unwrap ( ) ;
139+ if witness. len ( ) < 72 {
140+ witness. resize ( 72 , 0 ) ;
141+ }
142+
143+ let mut pub_key = Vec :: from ( public_key) ;
144+ if pub_key. len ( ) < 65 {
145+ pub_key. resize ( 65 , 0 ) ;
146+ }
147+
148+ Spending { witness, pub_key }
149+ } )
140150 . collect ( ) ;
141151
142152 let append_from = own_utxos. len ( ) ;
143- let append_to = ( ( own_utxos. len ( ) + MAX_COINS_DATABASE_AMOUNT - 1 ) / MAX_COINS_DATABASE_AMOUNT ) * MAX_COINS_DATABASE_AMOUNT ;
153+ let append_to = ( ( own_utxos. len ( ) + MAX_COINS_DATABASE_AMOUNT - 1 ) / MAX_COINS_DATABASE_AMOUNT )
154+ * MAX_COINS_DATABASE_AMOUNT ;
144155
145156 for _ in append_from..append_to {
146- own_utxos. push ( Spending { witness : Vec :: from ( [ 0 ; 72 ] ) , pub_key : Vec :: from ( [ 0 ; 65 ] ) } ) ;
157+ own_utxos. push ( Spending {
158+ witness : Vec :: from ( [ 0 ; 72 ] ) ,
159+ pub_key : Vec :: from ( [ 0 ; 65 ] ) ,
160+ } ) ;
147161 }
148162
149163 let toml_struct = LeafsToml {
@@ -169,16 +183,14 @@ fn tree_toml() -> Result<()> {
169183
170184 let node_toml = NodeToml {
171185 verification_key : vk_fields,
172- node_proofs : vec ! [
173- NodeProof {
174- proof: proof_fields,
175- public_inputs: pi_fields
176- }
177- ]
186+ node_proofs : vec ! [ NodeProof {
187+ proof: proof_fields,
188+ public_inputs: pi_fields,
189+ } ] ,
178190 } ;
179191
180192 let mut file = File :: create ( "../circuits/app/proof_of_reserve/utxos_tree/Prover.toml" ) ?;
181193 file. write ( toml:: to_string ( & node_toml) ?. as_bytes ( ) ) ?;
182194
183195 Ok ( ( ) )
184- }
196+ }
0 commit comments