LCOV - code coverage report
Current view: top level - flamenco/runtime/program - fd_zk_elgamal_proof_program.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 60 64 93.8 %
Date: 2024-11-13 11:58:15 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "fd_zk_elgamal_proof_program.h"
       2             : #include "zksdk/fd_zksdk.h"
       3             : #include "../fd_executor.h"
       4             : #include "../fd_runtime.h"
       5             : 
       6             : /*
       7             :  * ZK ElGamal Proof Program
       8             :  */
       9             : 
      10             : int
      11         687 : fd_executor_zk_elgamal_proof_program_execute( fd_exec_instr_ctx_t * ctx ) {
      12         687 :   uchar const * instr_data    = ctx->instr->data;
      13         687 :   ulong         instr_data_sz = ctx->instr->data_sz;
      14             : 
      15             :   /* https://github.com/anza-xyz/agave/blob/v2.0.1/programs/zk-elgamal-proof/src/lib.rs#L172-L176 */
      16         687 :   if( FD_UNLIKELY( instr_data_sz==0UL ) ) {
      17           0 :     return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
      18           0 :   }
      19             : 
      20         687 :   switch( instr_data[0] ) {
      21          39 :   case FD_ZKSDK_INSTR_CLOSE_CONTEXT_STATE:
      22             :     /* https://github.com/anza-xyz/agave/blob/v2.0.1/programs/zk-elgamal-proof/src/lib.rs#L179-L185 */
      23          39 :     FD_EXEC_CU_UPDATE( ctx, FD_ZKSDK_INSTR_CLOSE_CONTEXT_STATE_COMPUTE_UNITS );
      24          36 :     fd_log_collector_msg_literal( ctx, "CloseContextState" );
      25          36 :     return fd_zksdk_process_close_context_state( ctx );
      26             : 
      27         132 :   case FD_ZKSDK_INSTR_VERIFY_ZERO_CIPHERTEXT:
      28         132 :     FD_EXEC_CU_UPDATE( ctx, FD_ZKSDK_INSTR_VERIFY_ZERO_CIPHERTEXT_COMPUTE_UNITS );
      29         126 :     fd_log_collector_msg_literal( ctx, "VerifyZeroCiphertext" );
      30         126 :     break;
      31             : 
      32          72 :   case FD_ZKSDK_INSTR_VERIFY_CIPHERTEXT_CIPHERTEXT_EQUALITY:
      33          72 :     FD_EXEC_CU_UPDATE( ctx, FD_ZKSDK_INSTR_VERIFY_CIPHERTEXT_CIPHERTEXT_EQUALITY_COMPUTE_UNITS );
      34          63 :     fd_log_collector_msg_literal( ctx, "VerifyCiphertextCiphertextEquality" );
      35          63 :     break;
      36             : 
      37          42 :   case FD_ZKSDK_INSTR_VERIFY_CIPHERTEXT_COMMITMENT_EQUALITY:
      38          42 :     FD_EXEC_CU_UPDATE( ctx, FD_ZKSDK_INSTR_VERIFY_CIPHERTEXT_COMMITMENT_EQUALITY_COMPUTE_UNITS );
      39          39 :     fd_log_collector_msg_literal( ctx, "VerifyCiphertextCommitmentEquality" );
      40          39 :     break;
      41             : 
      42          36 :   case FD_ZKSDK_INSTR_VERIFY_PUBKEY_VALIDITY:
      43          36 :     FD_EXEC_CU_UPDATE( ctx, FD_ZKSDK_INSTR_VERIFY_PUBKEY_VALIDITY_COMPUTE_UNITS );
      44          33 :     fd_log_collector_msg_literal( ctx, "VerifyPubkeyValidity" );
      45          33 :     break;
      46             : 
      47          51 :   case FD_ZKSDK_INSTR_VERIFY_PERCENTAGE_WITH_CAP:
      48          51 :     FD_EXEC_CU_UPDATE( ctx, FD_ZKSDK_INSTR_VERIFY_PERCENTAGE_WITH_CAP_COMPUTE_UNITS );
      49          45 :     fd_log_collector_msg_literal( ctx, "VerifyPercentageWithCap" );
      50          45 :     break;
      51             : 
      52          54 :   case FD_ZKSDK_INSTR_VERIFY_BATCHED_RANGE_PROOF_U64:
      53          54 :     FD_EXEC_CU_UPDATE( ctx, FD_ZKSDK_INSTR_VERIFY_BATCHED_RANGE_PROOF_U64_COMPUTE_UNITS );
      54          48 :     fd_log_collector_msg_literal( ctx, "VerifyBatchedRangeProofU64" );
      55          48 :     break;
      56             : 
      57          57 :   case FD_ZKSDK_INSTR_VERIFY_BATCHED_RANGE_PROOF_U128:
      58          57 :     FD_EXEC_CU_UPDATE( ctx, FD_ZKSDK_INSTR_VERIFY_BATCHED_RANGE_PROOF_U128_COMPUTE_UNITS );
      59          51 :     fd_log_collector_msg_literal( ctx, "VerifyBatchedRangeProofU128" );
      60          51 :     break;
      61             : 
      62          51 :   case FD_ZKSDK_INSTR_VERIFY_BATCHED_RANGE_PROOF_U256:
      63          51 :     FD_EXEC_CU_UPDATE( ctx, FD_ZKSDK_INSTR_VERIFY_BATCHED_RANGE_PROOF_U256_COMPUTE_UNITS );
      64          42 :     fd_log_collector_msg_literal( ctx, "VerifyBatchedRangeProofU256" );
      65          42 :     break;
      66             : 
      67          39 :   case FD_ZKSDK_INSTR_VERIFY_GROUPED_CIPHERTEXT_2_HANDLES_VALIDITY:
      68          39 :     FD_EXEC_CU_UPDATE( ctx, FD_ZKSDK_INSTR_VERIFY_GROUPED_CIPHERTEXT_2_HANDLES_VALIDITY_COMPUTE_UNITS );
      69          36 :     fd_log_collector_msg_literal( ctx, "VerifyGroupedCiphertext2HandlesValidity" );
      70          36 :     break;
      71             : 
      72          42 :   case FD_ZKSDK_INSTR_VERIFY_BATCHED_GROUPED_CIPHERTEXT_2_HANDLES_VALIDITY:
      73          42 :     FD_EXEC_CU_UPDATE( ctx, FD_ZKSDK_INSTR_VERIFY_BATCHED_GROUPED_CIPHERTEXT_2_HANDLES_VALIDITY_COMPUTE_UNITS );
      74          39 :     fd_log_collector_msg_literal( ctx, "VerifyBatchedGroupedCiphertext2HandlesValidity" );
      75          39 :     break;
      76             : 
      77          33 :   case FD_ZKSDK_INSTR_VERIFY_GROUPED_CIPHERTEXT_3_HANDLES_VALIDITY:
      78          33 :     FD_EXEC_CU_UPDATE( ctx, FD_ZKSDK_INSTR_VERIFY_GROUPED_CIPHERTEXT_3_HANDLES_VALIDITY_COMPUTE_UNITS );
      79          30 :     fd_log_collector_msg_literal( ctx, "VerifyGroupedCiphertext3HandlesValidity" );
      80          30 :     break;
      81             : 
      82          39 :   case FD_ZKSDK_INSTR_VERIFY_BATCHED_GROUPED_CIPHERTEXT_3_HANDLES_VALIDITY:
      83          39 :     FD_EXEC_CU_UPDATE( ctx, FD_ZKSDK_INSTR_VERIFY_BATCHED_GROUPED_CIPHERTEXT_3_HANDLES_VALIDITY_COMPUTE_UNITS );
      84          33 :     fd_log_collector_msg_literal( ctx, "VerifyBatchedGroupedCiphertext3HandlesValidity" );
      85          33 :     break;
      86             : 
      87           0 :   default:
      88           0 :     return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
      89         687 :   }
      90             : 
      91         585 :   return fd_zksdk_process_verify_proof( ctx );
      92         687 : }

Generated by: LCOV version 1.14