@@ -15,6 +15,7 @@ pub struct MeteredCtx<const PAGE_BITS: usize = 6> {
15
15
16
16
pub memory_ctx : MemoryCtx < PAGE_BITS > ,
17
17
pub segmentation_ctx : SegmentationCtx ,
18
+ pub continuations_enabled : bool ,
18
19
}
19
20
20
21
impl < const PAGE_BITS : usize > MeteredCtx < PAGE_BITS > {
@@ -29,7 +30,7 @@ impl<const PAGE_BITS: usize> MeteredCtx<PAGE_BITS> {
29
30
widths : Vec < usize > ,
30
31
interactions : Vec < usize > ,
31
32
) -> Self {
32
- let ( mut trace_heights, is_trace_height_constant) : ( Vec < u32 > , Vec < bool > ) =
33
+ let ( trace_heights, is_trace_height_constant) : ( Vec < u32 > , Vec < bool > ) =
33
34
constant_trace_heights
34
35
. iter ( )
35
36
. map ( |& constant_height| {
@@ -41,7 +42,7 @@ impl<const PAGE_BITS: usize> MeteredCtx<PAGE_BITS> {
41
42
} )
42
43
. unzip ( ) ;
43
44
44
- let mut memory_ctx = MemoryCtx :: new (
45
+ let memory_ctx = MemoryCtx :: new (
45
46
has_public_values_chip,
46
47
continuations_enabled,
47
48
as_byte_alignment_bits,
@@ -57,22 +58,29 @@ impl<const PAGE_BITS: usize> MeteredCtx<PAGE_BITS> {
57
58
58
59
let segmentation_ctx = SegmentationCtx :: new ( air_names, widths, interactions) ;
59
60
61
+ let mut ctx = Self {
62
+ trace_heights,
63
+ is_trace_height_constant,
64
+ memory_ctx,
65
+ segmentation_ctx,
66
+ continuations_enabled,
67
+ } ;
68
+
60
69
// Add merkle height contributions for all registers
61
- if continuations_enabled {
62
- memory_ctx. update_boundary_merkle_heights (
63
- & mut trace_heights,
70
+ ctx. add_register_merkle_heights ( ) ;
71
+
72
+ ctx
73
+ }
74
+
75
+ fn add_register_merkle_heights ( & mut self ) {
76
+ if self . continuations_enabled {
77
+ self . memory_ctx . update_boundary_merkle_heights (
78
+ & mut self . trace_heights ,
64
79
RV32_REGISTER_AS ,
65
80
0 ,
66
81
( RV32_NUM_REGISTERS * RV32_REGISTER_NUM_LIMBS ) as u32 ,
67
82
) ;
68
83
}
69
-
70
- Self {
71
- trace_heights,
72
- is_trace_height_constant,
73
- memory_ctx,
74
- segmentation_ctx,
75
- }
76
84
}
77
85
78
86
pub fn with_max_trace_height ( mut self , max_trace_height : u32 ) -> Self {
@@ -111,6 +119,9 @@ impl<const PAGE_BITS: usize> MeteredCtx<PAGE_BITS> {
111
119
self . trace_heights [ i] = 0 ;
112
120
}
113
121
}
122
+
123
+ // Add merkle height contributions for all registers
124
+ self . add_register_merkle_heights ( ) ;
114
125
}
115
126
116
127
pub fn check_and_segment ( & mut self , instret : u64 ) {
@@ -124,6 +135,21 @@ impl<const PAGE_BITS: usize> MeteredCtx<PAGE_BITS> {
124
135
self . reset_segment ( ) ;
125
136
}
126
137
}
138
+
139
+ #[ allow( dead_code) ]
140
+ pub fn print_heights ( & self ) {
141
+ println ! ( "{:>10} {:<30}" , "Height" , "Air Name" ) ;
142
+ println ! ( "{}" , "-" . repeat( 42 ) ) ;
143
+ for ( i, height) in self . trace_heights . iter ( ) . enumerate ( ) {
144
+ let air_name = self
145
+ . segmentation_ctx
146
+ . air_names
147
+ . get ( i)
148
+ . map ( |s| s. as_str ( ) )
149
+ . unwrap_or ( "Unknown" ) ;
150
+ println ! ( "{:>10} {:<30}" , height, air_name) ;
151
+ }
152
+ }
127
153
}
128
154
129
155
impl < const PAGE_BITS : usize > E1E2ExecutionCtx for MeteredCtx < PAGE_BITS > {
0 commit comments