LCOV - code coverage report
Current view: top level - flamenco/runtime/program/zksdk/rangeproofs - fd_rangeproofs_transcript.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 26 29 89.7 %
Date: 2024-11-13 11:58:15 Functions: 27 90 30.0 %

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

Generated by: LCOV version 1.14