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.1/zk-sdk/src/transcript.rs */ 5 : 6 : #include "../../merlin/fd_merlin.h" 7 : #include "../../ed25519/fd_ristretto255.h" 8 : 9 845 : #define FD_TRANSCRIPT_SUCCESS 0 10 0 : #define FD_TRANSCRIPT_ERROR -1 11 : 12 1080 : #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 30 : ulong const n ) { 24 30 : fd_merlin_transcript_append_message( transcript, FD_MERLIN_LITERAL("dom-sep"), (uchar *)FD_MERLIN_LITERAL("range-proof") ); 25 30 : fd_merlin_transcript_append_u64( transcript, FD_MERLIN_LITERAL("n"), n ); 26 30 : } 27 : 28 : static inline void 29 : fd_rangeproofs_transcript_domsep_inner_product( fd_merlin_transcript_t * transcript, 30 30 : ulong const n ) { 31 30 : fd_merlin_transcript_append_message( transcript, FD_MERLIN_LITERAL("dom-sep"), (uchar *)FD_MERLIN_LITERAL("inner-product") ); 32 30 : fd_merlin_transcript_append_u64( transcript, FD_MERLIN_LITERAL("n"), n ); 33 30 : } 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 780 : uchar const point[ 32 ] ) { 46 780 : fd_merlin_transcript_append_message( transcript, label, label_len, point, 32 ); 47 780 : } 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 730 : uchar const point[ 32 ] ) { 54 730 : if ( FD_UNLIKELY( fd_memeq( point, fd_ristretto255_compressed_zero, 32 ) ) ) { 55 0 : return FD_TRANSCRIPT_ERROR; 56 0 : } 57 730 : fd_rangeproofs_transcript_append_point( transcript, label, label_len, point ); 58 730 : return FD_TRANSCRIPT_SUCCESS; 59 730 : } 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 330 : uchar const scalar[ 32 ] ) { 66 330 : fd_merlin_transcript_append_message( transcript, label, label_len, scalar, 32 ); 67 330 : } 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 567 : uint const label_len ) { 78 567 : uchar unreduced[ 64 ]; 79 567 : fd_merlin_transcript_challenge_bytes( transcript, label, label_len, unreduced, 64 ); 80 567 : return fd_curve25519_scalar_reduce(scalar, unreduced); 81 567 : } 82 : 83 : FD_PROTOTYPES_END 84 : #endif /* HEADER_fd_src_flamenco_runtime_program_rangeproofs_fd_transcript_h */