1
+ use core :: array :: SpanTrait ;
1
2
use core :: traits :: Destruct ;
2
3
use cairo_verifier :: channel :: channel :: ChannelTrait ;
3
4
use cairo_verifier :: table_commitment :: {
@@ -6,6 +7,32 @@ use cairo_verifier::table_commitment::{
6
7
use core :: array :: ArrayTrait ;
7
8
use cairo_verifier :: table_commitment :: table_commit;
8
9
use cairo_verifier :: channel :: channel :: Channel ;
10
+ use cairo_verifier :: channel :: channel :: {ChannelUnsentFelt , ChannelSentFelt };
11
+ use cairo_verifier :: fri :: fri_config :: FriConfig ;
12
+ use cairo_verifier :: common :: math;
13
+
14
+ // Commitment values for FRI. Used to generate a commitment by "reading" these values
15
+ // from the channel.
16
+ #[derive(Drop , Copy )]
17
+ struct FriUnsentCommitment {
18
+ // Array of size n_layers - 1 containing unsent table commitments for each inner layer.
19
+ inner_layers : Span <TableUnsentCommitment >,
20
+ // Array of size 2**log_last_layer_degree_bound containing coefficients for the last layer
21
+ // polynomial.
22
+ last_layer_coefficients : Span <ChannelUnsentFelt >,
23
+ }
24
+
25
+ #[derive(Drop , Copy )]
26
+ struct FriCommitment {
27
+ config : FriConfig ,
28
+ // Array of size n_layers - 1 containing table commitments for each inner layer.
29
+ inner_layers : Span <TableCommitment >,
30
+ // Array of size n_layers, of one evaluation point for each layer.
31
+ eval_points : Span <felt252 >,
32
+ // Array of size 2**log_last_layer_degree_bound containing coefficients for the last layer
33
+ // polynomial.
34
+ last_layer_coefficients : Span <ChannelSentFelt >,
35
+ }
9
36
10
37
// A FRI phase with N layers starts with a single input layer.
11
38
// Afterwards, there are N - 1 inner layers resulting from FRI-folding each preceding layer.
@@ -34,7 +61,6 @@ fn fri_commit_rounds(
34
61
configs : Span <TableCommitmentConfig >,
35
62
unsent_commitments : Span <TableUnsentCommitment >,
36
63
step_sizes : Span <felt252 >,
37
- commitments : Span <TableCommitment >,
38
64
) -> (Array <TableCommitment >, Array <felt252 >) {
39
65
let mut commitments = ArrayTrait :: <TableCommitment >:: new ();
40
66
let mut eval_points = ArrayTrait :: <felt252 >:: new ();
@@ -54,3 +80,29 @@ fn fri_commit_rounds(
54
80
55
81
(commitments , eval_points )
56
82
}
83
+
84
+ fn fri_commit (
85
+ ref channel : Channel , unsent_commitment : FriUnsentCommitment , config : FriConfig
86
+ ) -> FriCommitment {
87
+ assert ((* config . fri_step_sizes. at (0 )) == 0 , ' Invalid value' );
88
+
89
+ let (commitments , eval_points ) = fri_commit_rounds (
90
+ ref channel ,
91
+ config . n_layers,
92
+ config . inner_layers,
93
+ unsent_commitment . inner_layers,
94
+ config . fri_step_sizes,
95
+ );
96
+
97
+ // Read last layer coefficients.
98
+ let n_coefficients = math :: pow (2 , config . log_last_layer_degree_bound);
99
+ let coefficients = channel
100
+ . read_felt_vector_from_prover (unsent_commitment . last_layer_coefficients);
101
+
102
+ FriCommitment {
103
+ config : config ,
104
+ inner_layers : commitments . span (),
105
+ eval_points : eval_points . span (),
106
+ last_layer_coefficients : coefficients . span ()
107
+ }
108
+ }
0 commit comments