@@ -71,7 +71,15 @@ pub struct MemcpyIterCols<T> {
71
71
pub data_4 : [ T ; MEMCPY_LOOP_NUM_LIMBS ] ,
72
72
pub read_aux : [ MemoryReadAuxCols < T > ; 4 ] ,
73
73
pub write_aux : [ MemoryWriteAuxCols < T , MEMCPY_LOOP_NUM_LIMBS > ; 4 ] ,
74
- }
74
+ } // number of columns is 68
75
+ // other air constraints not that confident, check myself to see if confident with correctness
76
+
77
+ /*
78
+ talk about bug in #zk-circuits the same way that previous comment was made
79
+ - after have concrete idea of what the bug is, and why its failing
80
+ - i mean i kinda do tho lol? just making sure that the AIR constraints are correct and make sense
81
+
82
+ */
75
83
76
84
pub const NUM_MEMCPY_ITER_COLS : usize = size_of :: < MemcpyIterCols < u8 > > ( ) ;
77
85
@@ -125,7 +133,13 @@ impl<AB: InteractionBuilder> Air<AB> for MemcpyIterAir {
125
133
let is_not_start = ( local. is_boundary + AB :: Expr :: ONE )
126
134
* ( AB :: Expr :: TWO - local. is_boundary )
127
135
* ( AB :: F :: TWO ) . inverse ( ) ;
136
+
137
+ let prev_is_not_start = ( prev. is_boundary + AB :: Expr :: ONE )
138
+ * ( AB :: Expr :: TWO - prev. is_boundary )
139
+ * ( AB :: F :: TWO ) . inverse ( ) ;
140
+
128
141
let prev_is_not_end = not :: < AB :: Expr > (
142
+ // returns 0 if prev.isBoundary == 1, 1 otherwise, since we take the not
129
143
( prev. is_boundary + AB :: Expr :: ONE ) * prev. is_boundary * ( AB :: F :: TWO ) . inverse ( ) ,
130
144
) ;
131
145
@@ -202,9 +216,17 @@ impl<AB: InteractionBuilder> Air<AB> for MemcpyIterAir {
202
216
let mut is_valid_not_start_when = builder. when ( local. is_valid_not_start ) ;
203
217
is_valid_not_start_when. assert_eq ( len. clone ( ) , prev_len - AB :: Expr :: from_canonical_u32 ( 16 ) ) ;
204
218
205
- // TODO: fix this constraint
206
- // is_valid_not_start_when
207
- // .assert_eq(local.source, prev.source + AB::Expr::from_canonical_u32(16));
219
+ // TODO: fix this constraint? or why is this constraint failing
220
+
221
+ /*
222
+
223
+ error is if the initial source value is < 12, then -16, we do a saturating sub so its bounded below by 0
224
+ then, it results in a mismatch of values
225
+ */
226
+ is_valid_not_start_when. assert_eq (
227
+ prev_is_not_start. clone ( ) * local. source ,
228
+ prev_is_not_start. clone ( ) * ( prev. source + AB :: Expr :: from_canonical_u32 ( 16 ) ) ,
229
+ ) ;
208
230
209
231
is_valid_not_start_when. assert_eq ( local. dest , prev. dest + AB :: Expr :: from_canonical_u32 ( 16 ) ) ;
210
232
local
@@ -217,7 +239,7 @@ impl<AB: InteractionBuilder> Air<AB> for MemcpyIterAir {
217
239
218
240
// make sure if previous row is valid and not end, then local.is_valid = 1
219
241
builder
220
- . when ( prev_is_not_end - not :: < AB :: Expr > ( prev. is_valid ) )
242
+ . when ( prev_is_not_end. clone ( ) - not :: < AB :: Expr > ( prev. is_valid ) )
221
243
. assert_one ( local. is_valid ) ;
222
244
223
245
// if prev.is_valid_start, then timestamp = prev_timestamp + is_shift_non_zero
@@ -461,8 +483,10 @@ where
461
483
// Create a record sized to the exact number of 16-byte iterations (header + iterations)
462
484
// This calculation must match extract_layout and fill_trace
463
485
464
- let effective_len = len. saturating_sub ( shift as u32 ) ; // n >= 16 + shift
465
- let num_iters = ( effective_len >> 4 ) as usize ;
486
+ let head = if shift == 0 { 0 } else { 4 - shift as u32 } ;
487
+ let effective_len = len. saturating_sub ( head) ;
488
+ let num_iters = ( effective_len / 16 ) as usize ; // floor((len - head)/16)
489
+
466
490
// eprintln!(
467
491
// "PREFLIGHT: len={}, shift={}, effective_len={}, num_iters={}, allocated_rows={}",
468
492
// len,
@@ -624,6 +648,16 @@ where
624
648
}
625
649
}
626
650
651
+ /*
652
+ - generate_proving_ctx is what creates trace fill
653
+ - row major matrix, so stored in a vector, row by row
654
+ - look at common_main, is where trace is filled
655
+
656
+ - print into excel, look in trace
657
+
658
+
659
+ - LAST STEP:
660
+ */
627
661
impl < F : PrimeField32 > TraceFiller < F > for MemcpyIterFiller {
628
662
fn fill_trace (
629
663
& self ,
@@ -699,7 +733,14 @@ impl<F: PrimeField32> TraceFiller<F> for MemcpyIterFiller {
699
733
timestamp - timestamp_delta
700
734
} ;
701
735
702
- let mut dest = record. inner . dest + ( ( num_rows - 1 ) << 4 ) as u32 ;
736
+ // eprintln!("record.inner.source: {:?}", record.inner.source);
737
+ // eprintln!(
738
+ // "num_rows: {:?}, record.inner.source + ((num_rows - 1) << 4): {:?}",
739
+ // num_rows,
740
+ // record.inner.source + ((num_rows - 1) << 4) as u32
741
+ // );
742
+
743
+ let mut dest = record. inner . dest + ( ( num_rows - 1 ) << 4 ) as u32 ; // got rid of -1 here???
703
744
let mut source = ( record. inner . source + ( ( num_rows - 1 ) << 4 ) as u32 )
704
745
. saturating_sub ( 12 * ( record. inner . shift != 0 ) as u32 ) ;
705
746
let mut len =
@@ -805,6 +846,11 @@ impl<F: PrimeField32> TraceFiller<F> for MemcpyIterFiller {
805
846
cols. timestamp = F :: from_canonical_u32 ( get_timestamp ( false ) ) ;
806
847
807
848
dest = dest. saturating_sub ( 16 ) ;
849
+
850
+ if source < 16 {
851
+ eprintln ! ( "source: {:?}" , source) ;
852
+ eprintln ! ( "cols.is_boundary: {:?}" , cols. is_boundary) ;
853
+ }
808
854
source = source. saturating_sub ( 16 ) ;
809
855
len += 16 ;
810
856
@@ -1006,8 +1052,10 @@ unsafe fn execute_e12_impl<F: PrimeField32, CTX: ExecutionCtxTrait>(
1006
1052
let mut source = u32:: from_le_bytes ( source) . saturating_sub ( 12 * ( shift != 0 ) as u32 ) ;
1007
1053
let mut len = u32:: from_le_bytes ( len) ;
1008
1054
1009
- let effective_len = len. saturating_sub ( shift as u32 ) ; // n >= 16 + shift
1010
- let num_iters = ( effective_len >> 4 ) as u32 ;
1055
+ let head = if shift == 0 { 0 } else { 4 - shift as u32 } ;
1056
+ let effective_len = len. saturating_sub ( head) ;
1057
+ let num_iters = ( effective_len / 16 ) as u32 ; // floor((len - head)/16)
1058
+
1011
1059
// Check address ranges are valid
1012
1060
1013
1061
/*
0 commit comments