Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_program_zksdk_fd_zksdk_private_h 2 : #define HEADER_fd_src_flamenco_runtime_program_zksdk_fd_zksdk_private_h 3 : 4 : #include "fd_zksdk.h" 5 : #include "transcript/fd_zksdk_transcript.h" 6 : #include "rangeproofs/fd_rangeproofs.h" 7 : #include "../fd_zk_elgamal_proof_program.h" 8 : #include "../../fd_executor.h" 9 : 10 : /* Instruction context struct, proof struct, and in some cases 11 : ZKP verify function. */ 12 : #include "instructions/fd_zksdk_zero_ciphertext.h" 13 : #include "instructions/fd_zksdk_ciphertext_ciphertext_equality.h" 14 : #include "instructions/fd_zksdk_ciphertext_commitment_equality.h" 15 : #include "instructions/fd_zksdk_pubkey_validity.h" 16 : #include "instructions/fd_zksdk_percentage_with_cap.h" 17 : #include "instructions/fd_zksdk_batched_range_proofs.h" 18 : #include "instructions/fd_zksdk_batched_grouped_ciphertext_validity.h" 19 : 20 : /* Internal error for ZKP verify_proof instructions, to distinguish 21 : from the external error which is FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA. */ 22 162 : #define FD_ZKSDK_VERIFY_PROOF_ERROR FD_EXECUTOR_INSTR_ERR_GENERIC_ERR 23 : 24 : /* Basepoints for Pedersen commitments. 25 : They're the same as rangeproofs, but some ZKP don't use rangeproofs. */ 26 279 : #define fd_zksdk_basepoint_G fd_rangeproofs_basepoint_G 27 417 : #define fd_zksdk_basepoint_H fd_rangeproofs_basepoint_H 28 : 29 : /* Size of the context struct for each verify_proof instruction. */ 30 : static const ulong fd_zksdk_context_sz[] = { 31 : 0, // (placeholder/unused) FD_ZKSDK_INSTR_CLOSE_CONTEXT_STATE 32 : sizeof(fd_zksdk_zero_ciphertext_context_t), // FD_ZKSDK_INSTR_VERIFY_ZERO_CIPHERTEXT 33 : sizeof(fd_zksdk_ciph_ciph_eq_context_t), // FD_ZKSDK_INSTR_VERIFY_CIPHERTEXT_CIPHERTEXT_EQUALITY 34 : sizeof(fd_zksdk_ciph_comm_eq_context_t), // FD_ZKSDK_INSTR_VERIFY_CIPHERTEXT_COMMITMENT_EQUALITY 35 : sizeof(fd_zksdk_pubkey_validity_context_t), // FD_ZKSDK_INSTR_VERIFY_PUBKEY_VALIDITY 36 : sizeof(fd_zksdk_percentage_with_cap_context_t), // FD_ZKSDK_INSTR_VERIFY_PERCENTAGE_WITH_CAP 37 : sizeof(fd_zksdk_batched_range_proof_context_t), // FD_ZKSDK_INSTR_VERIFY_BATCHED_RANGE_PROOF_U64 38 : sizeof(fd_zksdk_batched_range_proof_context_t), // FD_ZKSDK_INSTR_VERIFY_BATCHED_RANGE_PROOF_U128 39 : sizeof(fd_zksdk_batched_range_proof_context_t), // FD_ZKSDK_INSTR_VERIFY_BATCHED_RANGE_PROOF_U256 40 : sizeof(fd_zksdk_grp_ciph_2h_val_context_t), // FD_ZKSDK_INSTR_VERFIY_GROUPED_CIPHERTEXT_2_HANDLES_VALIDITY 41 : sizeof(fd_zksdk_batched_grp_ciph_2h_val_context_t), // FD_ZKSDK_INSTR_VERIFY_BATCHED_GROUPED_CIPHERTEXT_2_HANDLES_VALIDITY 42 : sizeof(fd_zksdk_grp_ciph_3h_val_context_t), // FD_ZKSDK_INSTR_VERFIY_GROUPED_CIPHERTEXT_3_HANDLES_VALIDITY 43 : sizeof(fd_zksdk_batched_grp_ciph_3h_val_context_t), // FD_ZKSDK_INSTR_VERIFY_BATCHED_GROUPED_CIPHERTEXT_3_HANDLES_VALIDITY 44 : }; 45 : 46 : /* Size of the proof struct for each verify_proof instruction. */ 47 : static const ulong fd_zksdk_proof_sz[] = { 48 : 0, // (placeholder/unused) FD_ZKSDK_INSTR_CLOSE_CONTEXT_STATE 49 : sizeof(fd_zksdk_zero_ciphertext_proof_t), // FD_ZKSDK_INSTR_VERIFY_ZERO_CIPHERTEXT 50 : sizeof(fd_zksdk_ciph_ciph_eq_proof_t), // FD_ZKSDK_INSTR_VERIFY_CIPHERTEXT_CIPHERTEXT_EQUALITY 51 : sizeof(fd_zksdk_ciph_comm_eq_proof_t), // FD_ZKSDK_INSTR_VERIFY_CIPHERTEXT_COMMITMENT_EQUALITY 52 : sizeof(fd_zksdk_pubkey_validity_proof_t), // FD_ZKSDK_INSTR_VERIFY_PUBKEY_VALIDITY 53 : sizeof(fd_zksdk_percentage_with_cap_proof_t), // FD_ZKSDK_INSTR_VERIFY_PERCENTAGE_WITH_CAP 54 : sizeof(fd_zksdk_range_proof_u64_proof_t), // FD_ZKSDK_INSTR_VERIFY_BATCHED_RANGE_PROOF_U64 55 : sizeof(fd_zksdk_range_proof_u128_proof_t), // FD_ZKSDK_INSTR_VERIFY_BATCHED_RANGE_PROOF_U128 56 : sizeof(fd_zksdk_range_proof_u256_proof_t), // FD_ZKSDK_INSTR_VERIFY_BATCHED_RANGE_PROOF_U256 57 : sizeof(fd_zksdk_grp_ciph_2h_val_proof_t), // FD_ZKSDK_INSTR_VERFIY_GROUPED_CIPHERTEXT_2_HANDLES_VALIDITY 58 : sizeof(fd_zksdk_batched_grp_ciph_2h_val_proof_t), // FD_ZKSDK_INSTR_VERIFY_BATCHED_GROUPED_CIPHERTEXT_2_HANDLES_VALIDITY 59 : sizeof(fd_zksdk_grp_ciph_3h_val_proof_t), // FD_ZKSDK_INSTR_VERFIY_GROUPED_CIPHERTEXT_3_HANDLES_VALIDITY 60 : sizeof(fd_zksdk_batched_grp_ciph_3h_val_proof_t), // FD_ZKSDK_INSTR_VERIFY_BATCHED_GROUPED_CIPHERTEXT_3_HANDLES_VALIDITY 61 : }; 62 : 63 : /* ProofContextStateMeta 64 : https://github.com/anza-xyz/agave/blob/v2.0.1/zk-sdk/src/zk_elgamal_proof_program/state.rs#L58 */ 65 : struct __attribute__((packed)) fd_zksdk_proof_ctx_state_meta { 66 : fd_pubkey_t ctx_state_authority; 67 : uchar proof_type; 68 : }; 69 : typedef struct fd_zksdk_proof_ctx_state_meta fd_zksdk_proof_ctx_state_meta_t; 70 : 71 : /* Define all the fd_zksdk_instr_verify_proof_* functions with a macro 72 : so it's easy to keep the interface. */ 73 : #define DEFINE_VERIFY_PROOF(name) \ 74 : int \ 75 : fd_zksdk_instr_verify_proof_ ## name( void const * context, \ 76 : void const * proof ); 77 : 78 : FD_PROTOTYPES_BEGIN 79 : 80 : DEFINE_VERIFY_PROOF(zero_ciphertext) 81 : DEFINE_VERIFY_PROOF(ciphertext_ciphertext_equality) 82 : DEFINE_VERIFY_PROOF(ciphertext_commitment_equality) 83 : DEFINE_VERIFY_PROOF(pubkey_validity) 84 : DEFINE_VERIFY_PROOF(percentage_with_cap) 85 : DEFINE_VERIFY_PROOF(batched_range_proof_u64) 86 : DEFINE_VERIFY_PROOF(batched_range_proof_u128) 87 : DEFINE_VERIFY_PROOF(batched_range_proof_u256) 88 : DEFINE_VERIFY_PROOF(grouped_ciphertext_2_handles_validity) 89 : DEFINE_VERIFY_PROOF(batched_grouped_ciphertext_2_handles_validity) 90 : DEFINE_VERIFY_PROOF(grouped_ciphertext_3_handles_validity) 91 : DEFINE_VERIFY_PROOF(batched_grouped_ciphertext_3_handles_validity) 92 : 93 : FD_PROTOTYPES_END 94 : #endif /* HEADER_fd_src_flamenco_runtime_program_zksdk_fd_zksdk_private_h */