Line data Source code
1 : #include "../fd_zksdk_private.h" 2 : 3 : /* https://github.com/solana-program/zk-elgamal-proof/blob/zk-sdk%40v5.0.1/zk-sdk/src/sigma_proofs/batched_grouped_ciphertext_validity/handles_3.rs#L180 */ 4 : static inline void 5 : batched_grouped_ciphertext_validity_hash_context( 6 : fd_zksdk_transcript_t * transcript, 7 : uchar const pubkey1 [ 32 ], 8 : uchar const pubkey2 [ 32 ], 9 : uchar const pubkey3 [ 32 ], 10 : grp_ciph_3h_t const * grouped_ciphertext_lo, 11 6 : grp_ciph_3h_t const * grouped_ciphertext_hi ) { 12 6 : fd_zksdk_transcript_append_pubkey ( transcript, FD_TRANSCRIPT_LITERAL("first-pubkey"), pubkey1 ); 13 6 : fd_zksdk_transcript_append_pubkey ( transcript, FD_TRANSCRIPT_LITERAL("second-pubkey"), pubkey2 ); 14 6 : fd_zksdk_transcript_append_pubkey ( transcript, FD_TRANSCRIPT_LITERAL("third-pubkey"), pubkey3 ); 15 6 : fd_zksdk_transcript_append_message( transcript, FD_TRANSCRIPT_LITERAL("grouped-ciphertext-lo"), (uchar *)grouped_ciphertext_lo, sizeof(grp_ciph_3h_t) ); 16 6 : fd_zksdk_transcript_append_message( transcript, FD_TRANSCRIPT_LITERAL("grouped-ciphertext-hi"), (uchar *)grouped_ciphertext_hi, sizeof(grp_ciph_3h_t) ); 17 6 : } 18 : 19 : /* https://github.com/solana-program/zk-elgamal-proof/blob/zk-sdk%40v5.0.1/zk-sdk/src/sigma_proofs/batched_grouped_ciphertext_validity/handles_3.rs#L111 */ 20 : static inline int 21 : fd_zksdk_verify_proof_batched_grouped_ciphertext_3_handles_validity( 22 : fd_zksdk_grp_ciph_3h_val_proof_t const * proof, 23 : uchar const pubkey1 [ 32 ], 24 : uchar const pubkey2 [ 32 ], 25 : uchar const pubkey3 [ 32 ], 26 : grp_ciph_3h_t const * grouped_ciphertext_lo, 27 : grp_ciph_3h_t const * grouped_ciphertext_hi, 28 6 : fd_zksdk_transcript_t * transcript ) { 29 : 30 : /* https://github.com/solana-program/zk-elgamal-proof/blob/zk-sdk%40v5.0.1/zk-sdk/src/sigma_proofs/batched_grouped_ciphertext_validity/handles_3.rs#L123-L129 */ 31 6 : if( FD_UNLIKELY( fd_memeq( pubkey1, fd_ristretto255_compressed_zero, 32 ) 32 6 : || fd_memeq( pubkey2, fd_ristretto255_compressed_zero, 32 ) 33 6 : || fd_memeq( grouped_ciphertext_lo->commitment, fd_ristretto255_compressed_zero, 32 ) 34 6 : || fd_memeq( grouped_ciphertext_hi->commitment, fd_ristretto255_compressed_zero, 32 ) ) ) { 35 0 : return FD_ZKSDK_VERIFY_PROOF_ERROR; 36 0 : } 37 : 38 : /* https://github.com/solana-program/zk-elgamal-proof/blob/zk-sdk%40v5.0.1/zk-sdk/src/sigma_proofs/batched_grouped_ciphertext_validity/handles_3.rs#L131-L139 */ 39 6 : batched_grouped_ciphertext_validity_hash_context( transcript, pubkey1, pubkey2, pubkey3, grouped_ciphertext_lo, grouped_ciphertext_hi ); 40 6 : fd_zksdk_transcript_domsep_batched_grp_ciph_val_proof( transcript, 3 ); 41 : 42 : /* https://github.com/solana-program/zk-elgamal-proof/blob/zk-sdk%40v5.0.1/zk-sdk/src/sigma_proofs/batched_grouped_ciphertext_validity/handles_3.rs#L141 */ 43 6 : uchar t[ 32 ]; 44 6 : fd_zksdk_transcript_challenge_scalar( t, transcript, FD_TRANSCRIPT_LITERAL("t") ); 45 : 46 : /* https://github.com/solana-program/zk-elgamal-proof/blob/zk-sdk%40v5.0.1/zk-sdk/src/sigma_proofs/batched_grouped_ciphertext_validity/handles_3.rs#L143-L177 47 : Note: in our impl, t is embedded in the final MSM. */ 48 6 : return fd_zksdk_verify_proof_direct_grouped_ciphertext_3_handles_validity( 49 6 : proof, 50 6 : pubkey1, 51 6 : pubkey2, 52 6 : pubkey3, 53 6 : grouped_ciphertext_lo->commitment, 54 6 : grouped_ciphertext_lo->handles[0].handle, 55 6 : grouped_ciphertext_lo->handles[1].handle, 56 6 : grouped_ciphertext_lo->handles[2].handle, 57 6 : grouped_ciphertext_hi->commitment, 58 6 : grouped_ciphertext_hi->handles[0].handle, 59 6 : grouped_ciphertext_hi->handles[1].handle, 60 6 : grouped_ciphertext_hi->handles[2].handle, 61 6 : t, 62 6 : 1, 63 6 : transcript 64 6 : ); 65 6 : } 66 : 67 : /* https://github.com/solana-program/zk-elgamal-proof/blob/zk-sdk%40v5.0.1/zk-sdk/src/zk_elgamal_proof_program/proof_data/batched_grouped_ciphertext_validity/handles_3.rs#L138 */ 68 : int 69 6 : fd_zksdk_instr_verify_proof_batched_grouped_ciphertext_3_handles_validity( void const * _context, void const * _proof ) { 70 6 : fd_zksdk_transcript_t transcript[1]; 71 6 : fd_zksdk_transcript_init( transcript, FD_TRANSCRIPT_LITERAL("batched-grouped-ciphertext-validity-3-handles-instruction") ); 72 : 73 6 : fd_zksdk_batched_grp_ciph_3h_val_context_t const * context = _context; 74 6 : fd_zksdk_batched_grp_ciph_3h_val_proof_t const * proof = _proof; 75 6 : return fd_zksdk_verify_proof_batched_grouped_ciphertext_3_handles_validity( 76 6 : proof, 77 6 : context->pubkey1, 78 6 : context->pubkey2, 79 6 : context->pubkey3, 80 6 : context->grouped_ciphertext_lo, 81 6 : context->grouped_ciphertext_hi, 82 6 : transcript 83 6 : ); 84 6 : }