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 0 : #define FD_TRANSCRIPT_SUCCESS 0
11 0 : #define FD_TRANSCRIPT_ERROR -1
12 :
13 0 : #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 0 : ulong const n ) {
25 0 : fd_merlin_transcript_append_message( transcript, FD_MERLIN_LITERAL("dom-sep"), (uchar *)FD_MERLIN_LITERAL("range-proof") );
26 0 : fd_merlin_transcript_append_u64( transcript, FD_MERLIN_LITERAL("n"), n );
27 0 : }
28 :
29 : static inline void
30 : fd_rangeproofs_transcript_domsep_inner_product( fd_merlin_transcript_t * transcript,
31 0 : ulong const n ) {
32 0 : fd_merlin_transcript_append_message( transcript, FD_MERLIN_LITERAL("dom-sep"), (uchar *)FD_MERLIN_LITERAL("inner-product") );
33 0 : fd_merlin_transcript_append_u64( transcript, FD_MERLIN_LITERAL("n"), n );
34 0 : }
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 0 : uchar const point[ 32 ] ) {
47 0 : fd_merlin_transcript_append_message( transcript, label, label_len, point, 32 );
48 0 : }
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 0 : uchar const point[ 32 ] ) {
55 0 : if ( FD_UNLIKELY( fd_memeq( point, fd_ristretto255_compressed_zero, 32 ) ) ) {
56 0 : return FD_TRANSCRIPT_ERROR;
57 0 : }
58 0 : fd_rangeproofs_transcript_append_point( transcript, label, label_len, point );
59 0 : return FD_TRANSCRIPT_SUCCESS;
60 0 : }
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 0 : uchar const scalar[ 32 ] ) {
67 0 : fd_merlin_transcript_append_message( transcript, label, label_len, scalar, 32 );
68 0 : }
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 0 : uint const label_len ) {
79 0 : uchar unreduced[ 64 ];
80 0 : fd_merlin_transcript_challenge_bytes( transcript, label, label_len, unreduced, 64 );
81 0 : return fd_curve25519_scalar_reduce(scalar, unreduced);
82 0 : }
83 :
84 : FD_PROTOTYPES_END
85 : #endif /* HEADER_fd_src_flamenco_runtime_program_rangeproofs_fd_transcript_h */
|