LCOV - code coverage report
Current view: top level - ballet/zksdk/rangeproofs - fd_rangeproofs_transcript.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 14 29 48.3 %
Date: 2026-02-13 06:06:24 Functions: 3 96 3.1 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_program_rangeproofs_fd_transcript_h
       2             : #define HEADER_fd_src_flamenco_runtime_program_rangeproofs_fd_transcript_h
       3             : 
       4             : /* https://github.com/solana-program/zk-elgamal-proof/blob/zk-sdk%40v5.0.0/zk-sdk/src/transcript.rs */
       5             : 
       6             : #include "../../merlin/fd_merlin.h"
       7             : #include "../../ed25519/fd_ristretto255.h"
       8             : 
       9          12 : #define FD_TRANSCRIPT_SUCCESS 0
      10           0 : #define FD_TRANSCRIPT_ERROR  -1
      11             : 
      12           0 : #define FD_TRANSCRIPT_LITERAL FD_MERLIN_LITERAL
      13             : 
      14             : FD_PROTOTYPES_BEGIN
      15             : 
      16             : /* Domain separators:
      17             :    - range proof
      18             :    - inner product proof
      19             :  */
      20             : 
      21             : static inline void
      22             : fd_rangeproofs_transcript_domsep_range_proof( fd_merlin_transcript_t * transcript,
      23           0 :                                               ulong const             n ) {
      24           0 :   fd_merlin_transcript_append_message( transcript, FD_MERLIN_LITERAL("dom-sep"), (uchar *)FD_MERLIN_LITERAL("range-proof") );
      25           0 :   fd_merlin_transcript_append_u64( transcript, FD_MERLIN_LITERAL("n"), n );
      26           0 : }
      27             : 
      28             : static inline void
      29             : fd_rangeproofs_transcript_domsep_inner_product( fd_merlin_transcript_t * transcript,
      30           0 :                                                 ulong const             n ) {
      31           0 :   fd_merlin_transcript_append_message( transcript, FD_MERLIN_LITERAL("dom-sep"), (uchar *)FD_MERLIN_LITERAL("inner-product") );
      32           0 :   fd_merlin_transcript_append_u64( transcript, FD_MERLIN_LITERAL("n"), n );
      33           0 : }
      34             : 
      35             : /* Append message:
      36             :    - point
      37             :    - validate_and_append_point
      38             :    - scalar
      39             :  */
      40             : 
      41             : static inline void
      42             : fd_rangeproofs_transcript_append_point( fd_merlin_transcript_t * transcript,
      43             :                                         char const * const       label,
      44             :                                         uint const               label_len,
      45           6 :                                         uchar const              point[ 32 ] ) {
      46           6 :   fd_merlin_transcript_append_message( transcript, label, label_len, point, 32 );
      47           6 : }
      48             : 
      49             : static inline int
      50             : fd_rangeproofs_transcript_validate_and_append_point( fd_merlin_transcript_t * transcript,
      51             :                                                      char const * const       label,
      52             :                                                      uint const               label_len,
      53           6 :                                                      uchar const              point[ 32 ] ) {
      54           6 :   if ( FD_UNLIKELY( fd_memeq( point, fd_ristretto255_compressed_zero, 32 ) ) ) {
      55           0 :     return FD_TRANSCRIPT_ERROR;
      56           0 :   }
      57           6 :   fd_rangeproofs_transcript_append_point( transcript, label, label_len, point );
      58           6 :   return FD_TRANSCRIPT_SUCCESS;
      59           6 : }
      60             : 
      61             : static inline void
      62             : fd_rangeproofs_transcript_append_scalar( fd_merlin_transcript_t * transcript,
      63             :                                          char const * const       label,
      64             :                                          uint const               label_len,
      65           0 :                                          uchar const              scalar[ 32 ] ) {
      66           0 :   fd_merlin_transcript_append_message( transcript, label, label_len, scalar, 32 );
      67           0 : }
      68             : 
      69             : /* Challenge:
      70             :    - scalar
      71             : */
      72             : 
      73             : static inline uchar *
      74             : fd_rangeproofs_transcript_challenge_scalar( uchar                    scalar[ 32 ],
      75             :                                             fd_merlin_transcript_t * transcript,
      76             :                                             char const * const       label,
      77           6 :                                             uint const               label_len ) {
      78           6 :   uchar unreduced[ 64 ];
      79           6 :   fd_merlin_transcript_challenge_bytes( transcript, label, label_len, unreduced, 64 );
      80           6 :   return fd_curve25519_scalar_reduce(scalar, unreduced);
      81           6 : }
      82             : 
      83             : FD_PROTOTYPES_END
      84             : #endif /* HEADER_fd_src_flamenco_runtime_program_rangeproofs_fd_transcript_h */

Generated by: LCOV version 1.14