@@ -57,25 +57,28 @@ impl ZkData {
5757 }
5858}
5959
60+ #[ allow( clippy:: too_many_arguments) ]
6061async fn insert_proof (
6162 pool : & sqlx:: PgPool ,
6263 request_id : i64 ,
63- zk_pok : & [ u8 ] ,
64- aux : & ZkData ,
64+ zk_pok : Vec < u8 > ,
65+ aux : ZkData ,
6566 db_notify_channel : & str ,
6667 transaction_id : Handle ,
68+ retry_count : i32 ,
6769 _block_number : u64 ,
6870) -> Result < ( ) , sqlx:: Error > {
6971 // Insert ZkPok into database
7072 sqlx:: query (
71- "INSERT INTO verify_proofs (zk_proof_id, input, chain_id, contract_address, user_address, verified, transaction_id)
72- VALUES ($1, $2, $3, $4, $5, NULL, $6)"
73+ "INSERT INTO verify_proofs (zk_proof_id, input, chain_id, contract_address, user_address, verified, transaction_id, retry_count )
74+ VALUES ($1, $2, $3, $4, $5, NULL, $6, $7 )"
7375 ) . bind ( request_id)
7476 . bind ( zk_pok)
7577 . bind ( aux. chain_id )
7678 . bind ( aux. contract_address . clone ( ) )
7779 . bind ( aux. user_address . clone ( ) )
7880 . bind ( transaction_id. to_vec ( ) )
81+ . bind ( retry_count)
7982 . execute ( pool) . await ?;
8083 sqlx:: query ( "SELECT pg_notify($1, '')" )
8184 . bind ( db_notify_channel)
@@ -190,11 +193,12 @@ pub async fn generate_random_handle_vec(
190193 insert_proof (
191194 & pool,
192195 zk_id,
193- & zk_pok,
194- & zk_data,
196+ zk_pok,
197+ zk_data,
195198 & ctx. args . zkproof_notify_channel ,
196199 transaction_id,
197200 0 ,
201+ 0 ,
198202 )
199203 . await ?;
200204
@@ -205,6 +209,67 @@ pub async fn generate_random_handle_vec(
205209 Ok ( handles)
206210}
207211
212+ pub async fn generate_and_insert_inputs_batch (
213+ ctx : & Context ,
214+ batch_size : usize ,
215+ inputs_count : u8 ,
216+ contract_address : & String ,
217+ user_address : & String ,
218+ ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
219+ assert ! ( inputs_count <= 254 ) ;
220+ let ecfg = EnvConfig :: new ( ) ;
221+ let pool = sqlx:: postgres:: PgPoolOptions :: new ( )
222+ . max_connections ( 20 )
223+ . connect ( & ecfg. evgen_db_url )
224+ . await
225+ . unwrap ( ) ;
226+
227+ let ( pks, public_params) = query_and_save_pks ( ecfg. tenant_id , & pool) . await ?;
228+ let mut db_inserts = vec ! [ ] ;
229+
230+ // Generate a batch of zkpoks
231+ for idx in 0 ..batch_size {
232+ let transaction_id = next_random_handle ( DEF_TYPE ) ;
233+
234+ let zk_data = ZkData {
235+ contract_address : contract_address. to_owned ( ) ,
236+ user_address : user_address. to_owned ( ) ,
237+ acl_contract_address : ecfg. acl_contract_address . clone ( ) ,
238+ chain_id : ecfg. chain_id ,
239+ } ;
240+ let aux_data = zk_data. to_owned ( ) . assemble ( ) ?;
241+
242+ let mut builder = tfhe:: ProvenCompactCiphertextList :: builder ( & pks) ;
243+ for _ in 0 ..inputs_count {
244+ builder. push ( rand:: rng ( ) . random :: < u64 > ( ) ) ;
245+ }
246+ let zk_id = ZK_PROOF_ID . fetch_add ( 1 , std:: sync:: atomic:: Ordering :: SeqCst ) ;
247+ info ! ( target: "tool" , "zkpok id: {}, count = {:?}, seq_num = {} of {} , txn: {:?}, " , zk_id, inputs_count, idx, batch_size, transaction_id ) ;
248+ let the_list = builder
249+ . build_with_proof_packed ( & public_params, & aux_data, tfhe:: zk:: ZkComputeLoad :: Proof )
250+ . unwrap ( ) ;
251+
252+ let zk_pok = fhevm_engine_common:: utils:: safe_serialize ( & the_list) ;
253+
254+ // retry_count = 100 to ensure the txn-sender will delete it after first try
255+ // If not deleted, txn-sender will report too many VerifyProofNotRequested errors
256+ db_inserts. push ( insert_proof (
257+ & pool,
258+ zk_id,
259+ zk_pok. clone ( ) ,
260+ zk_data,
261+ & ctx. args . zkproof_notify_channel ,
262+ transaction_id,
263+ 100 ,
264+ 0 ,
265+ ) ) ;
266+ }
267+
268+ futures:: future:: try_join_all ( db_inserts) . await ?;
269+
270+ Ok ( ( ) )
271+ }
272+
208273pub async fn get_inputs_vector (
209274 ctx : & Context ,
210275 in_type : Inputs ,
0 commit comments