@@ -21,7 +21,7 @@ mod getters;
21
21
mod keyhash ;
22
22
mod slice_field ;
23
23
use crate::redux::JSON ;
24
- use crate::slice_field::slice_field ;
24
+ use crate::slice_field:: { slice_fields , slice_field } ;
25
25
use crate::keyhash:: {slice_200_bits_from_field , get_keyhash_chunky , sum_var_bytes_into_field };
26
26
use crate::lt::lt_field_16_bit ;
27
27
global LEN = 10000 ;
@@ -66,11 +66,208 @@ unconstrained fn preamble(_json: JSON<1024, 64>) -> JSON<1024, 64> {
66
66
// diff = 15? that can't be right
67
67
// wo range check 128. 5012 vs 5021 = 9
68
68
69
+ // slice limbs
70
+ // 99 = 37955
71
+ // 100 = 38283
72
+ // delta = 283 + 45 = 328 lol fuck
73
+
74
+ // size 1 slice limbs
75
+ // 99 = 28303
76
+ // 100 = 28533
77
+ // delta = 230 man painful
78
+
79
+ // size 2
80
+ // 99 = 33227
81
+ // 100 = 33508
82
+ // delta = 285 pain
83
+
84
+ // size 5 slice limbs
85
+ // 99 = 48103
86
+ // 100 = 48533
87
+ // delta = 430
88
+
89
+ // 607
90
+ // 601 6
91
+ // 595 6
92
+ // 589 6
93
+
94
+ // 645
95
+ // 640
96
+
97
+ // 606
98
+ // 600
99
+
100
+ // 6006
101
+ // 5145
102
+ // 150?
103
+ global TEST1 : [Field ; 35 ] = [
104
+ 0x000000000 , // 0 0 0 0 0 0 0 0 0
105
+ 0x000000001 , // 0 0 0 0 0 0 0 0 1
106
+ 0x000000002 , // 0 0 0 0 0 0 0 1 0
107
+ 0x000000004 , // 0 0 0 0 0 0 1 0 0
108
+ 0x000000008 , // 0 0 0 0 0 1 0 0 0
109
+ 0x000000010 , // 0 0 0 0 1 0 0 0 0
110
+ 0x000000020 , // 0 0 0 1 0 0 0 0 0
111
+ 0x000000040 , // 0 0 1 0 0 0 0 0 0
112
+ 0x000000080 , // 0 1 0 0 0 0 0 0 0
113
+ 0x000000100 , // 1 0 0 0 0 0 0 0 0
114
+ 0x000000000 , // 0 0 0 0 0 0 0 0 0
115
+ 0x000000001 , // 0 0 0 0 0 0 0 0 1
116
+ 0x000000002 , // 0 0 0 0 0 0 0 1 0
117
+ 0x000000004 , // 0 0 0 0 0 0 1 0 0
118
+ 0x000000008 , // 0 0 0 0 0 1 0 0 0
119
+ 0x000000010 , // 0 0 0 0 1 0 0 0 0
120
+ 0x000000020 , // 0 0 0 1 0 0 0 0 0
121
+ 0x000000040 , // 0 0 1 0 0 0 0 0 0
122
+ 0x000000080 , // 0 1 0 0 0 0 0 0 0
123
+ 0x000000100 , // 1 0 0 0 0 0 0 0 0
124
+ 0x000000000 , // 0 0 0 0 0 0 0 0 0
125
+ 0x000000001 , // 0 0 0 0 0 0 0 0 1
126
+ 0x000000002 , // 0 0 0 0 0 0 0 1 0
127
+ 0x000000004 , // 0 0 0 0 0 0 1 0 0
128
+ 0x000000008 , // 0 0 0 0 0 1 0 0 0
129
+ 0x000000010 , // 0 0 0 0 1 0 0 0 0
130
+ 0x000000020 , // 0 0 0 1 0 0 0 0 0
131
+ 0x000000040 , // 0 0 1 0 0 0 0 0 0
132
+ 0x000000080 , // 0 1 0 0 0 0 0 0 0
133
+ 0x000000100 , // 1 0 0 0 0 0 0 0 0
134
+ 0x000000010 , // 0 0 0 0 1 0 0 0 0
135
+ 0x000000020 , // 0 0 0 1 0 0 0 0 0
136
+ 0x000000040 , // 0 0 1 0 0 0 0 0 0
137
+ 0x000000080 , // 0 1 0 0 0 0 0 0 0
138
+ 0x000000100 , // 1 0 0 0 0 0 0 0 0
139
+ ];
140
+
141
+ global FOO : [Field ; 4 ] = [0 , 1 , 2 , 3 ];
142
+ fn maiff (p : Field ) {
143
+ // let k = LAST_LIMB_PATH[p[0]];
144
+ // println(f"{k}");
145
+ // let q = TEST1[p[0]];
146
+ // println(f"{q}"); // 47
147
+ // let k = LAST_LIMB_PATH[lhs[0]];
148
+ // println(f"{k}");
149
+ // let k = FOO[p];
150
+ // println(f"{k}");
151
+ // let k = LAST_LIMB_PATH[p];
152
+ // let k: [Field; 2] = get_last_limb_path(p);
153
+ // println(f"{k}");
154
+ // reading array = 147 gates
155
+ // get_last_limb_path =150 gates
156
+ // init = 145 - 8 = 137
157
+ // 35 * 3 = 105 . + 32?
158
+ // 35 range check...
159
+ // 6 bit = 64 / 3 values = 22 values
160
+ // 4 3 3 3 3 3 3 - = 8 gates padding * 2 = 16 gates padding
161
+ // hmm hmm hmm hmm
162
+ // OK so we save 1 gate per call to keyfind.
163
+ // We have 64 keys max per 1kb json = save 64. cost is quite a bit higher. blah
164
+ // we save 3? gates if key len is 3 fields
165
+ // 8 -> 17 = 9 gates
166
+ // 4 gates to make
167
+ // 2 gates to read
168
+ // 17 gates = 2 9 gates init
169
+ // 20 gate = size 3 12 gates init
170
+ // 23 gates = size 4 hmm? 15 gates init
171
+ // 3 gates + (3 * size) boo
172
+ // 35 * 3 = 105 + 3 = 108 + 8 = 116 + 5 = 121
173
+ // cost = 140 gates
174
+ // where are the 3 gates coming from?
175
+ // 122 -> 220 = 100. why not 70?
176
+ // for i in 0..1 {
177
+ // let k0: Field = (i as Field == p[i]) as Field;
178
+ // let k1 = (i as Field == lhs[i]) as Field;
179
+ // println(f"{k0}{k1}");
180
+ // //let k: [Field; 2] = get_last_limb_path(p[i]);
181
+ // // println(f"{k}");
182
+ // // let is_last = (i as Field == p[i]) as Field; // 3 gates
183
+ // // let new = (rhs[i] - lhs[i]) * is_last + lhs[i]; // 2 gates
184
+ // // assert(new == r[i]); // 1 gate
185
+ // }
186
+ }
187
+ // hmm something weird here
188
+ fn main (foo : [Field ; 100 ], bar : [u8 ; 1000 ], num_bytes : [u16 ; 100 ], start_bytes : [u16 ; 100 ]) {
189
+ // 3,621 for 100
190
+ // 3,613 for 99 = 8 which is expected
191
+ // 54 bits
192
+
193
+ // 3,726 for 100
194
+ // 3,723 for 99 = 3 gates = expected
195
+
196
+ // slice 200 bits
197
+ // 100 = 6181
198
+ // 99 = 6154
199
+ // 27 gates ok expected
200
+ // so something squiffy is happening
201
+ // aaaah the cost of an extr arange table was glomming things
202
+
203
+ // 5,871
204
+ // 28600 28055 26669 24689 24540
205
+ // 28833 28283 26883 24883 24733
206
+
207
+ // current 27834 with path valid via lookups
208
+ // now 27184 without "no data" (via field padding)
209
+ // and 26987 after tweaking with path stuff
210
+ // and 26837 after removing u16 cast
211
+
212
+ // more lookup messiness 28700 vs 28471 = 229 erm regression?
213
+ // ok fixed. 24997 vs 24805 = 192? wow?
214
+
215
+ // 25349 vs 25153 = 150 + 46 = 196 hmmmm
216
+ // 24749 vs 24559 = 190 lol a bit better
217
+ // 45 * 3 = 135 => extra = 55 gates hmm
218
+
219
+ // 26987 vs 26773 delta = 214
220
+ // 26900 vs 26687 delta = 213?
221
+ // 26837 vs 26624 delta = 213? hmm
222
+ // hmm
223
+ // 27433 if we can remove no data
224
+ // 26483 if we can remove slice_valid somehow = 10 gates hmm hmm
225
+ // 233 hmmmmm this beats original version
226
+ // 228
227
+ // 214
228
+ // 194 (we need to remove that damn write-at-arb-index)
229
+ // 193
230
+ // 45 * 3 = 135
231
+
232
+ // num_whole_limbs => path for slice valid
233
+ // 0 = 0 0 0 0 0
234
+ // 1 = 0 0 0 0 1
235
+ // 2 = 0 0 0 1 1
236
+ // 3 = 0 0 1 1 1
237
+ // etc etc
238
+ // nice! let's do that!
239
+
240
+ // e.g. if outputfields = 2
241
+ // 3 gates to sort out
242
+ // 2 gates to read
243
+ // 5 gates total
244
+ // 1: 18499 18630 -> 131
245
+ // how to remove arb index
246
+ // say we compute idx of final limb
247
+ // we say if (i == idx) set value we write to last limb
248
+ for i in 0 ..100 {
249
+ let x : [Field ; 2 ] = slice_fields (foo , start_bytes [i ], num_bytes [i ]);
250
+ println (f"{ x} " );
251
+ // assert(x.0 == x.1);
252
+ }
253
+ // for i in 0..99 {
254
+ // let x = sum_var_bytes_into_field(bar, 10, 10);
255
+ // println(f"{x}");
256
+ // }
257
+ }
258
+ // 27983
259
+ // 27759
260
+ // 224
261
+ // vs
262
+ // 27883
263
+ // 27659
264
+ // 224
265
+ // wat?
69
266
// 10,285 (10,087)
70
267
// 10,344 (10,144)
71
268
// diff = 44 + 15 = 59 (diff = 57)
72
269
// maybe 58 gates all in?
73
- fn main (foo : [Field ; 100 ], bar : [u8 ; 1000 ], num_bytes : [u16 ; 100 ]) {
270
+ fn mainddddold (foo : [Field ; 100 ], bar : [u8 ; 1000 ], num_bytes : [u16 ; 100 ]) {
74
271
// 3,621 for 100
75
272
// 3,613 for 99 = 8 which is expected
76
273
println (f"{ bar} " );
@@ -105,11 +302,23 @@ fn main(foo: [Field; 100], bar: [u8; 1000], num_bytes: [u16; 100]) {
105
302
// w/o range checks its 27,902 still crazy
106
303
// 27965 with fn shell
107
304
// ok something squiffy was getting masked away - constraining the input adds the gates
108
- fn makkkkin (body_text : [u8 ; 1024 ], body_indices : [u16 ; 64 ], key_lengths : [u16 ; 64 ], dd : Field ) {
305
+
306
+ // 63 = 10953
307
+ // 64 = 11010
308
+ // diff = 57
309
+
310
+ // 63 = 12590
311
+ // 64 = 12674
312
+ // diff = 84 ? for 64 byte eh oh most commented out
313
+
314
+ // 34392
315
+ // 34821
316
+ // 429 per key painful (poseidon hash is squiffy though)
317
+ fn mainkkkk (body_text : [u8 ; 1024 ], body_indices : [u16 ; 64 ], key_lengths : [u16 ; 64 ], dd : Field ) {
109
318
println (f"{ body_text} { body_indices} { key_lengths} " );
110
319
let kk = slice_200_bits_from_field (dd );
111
320
println (f"{ kk} " );
112
- for i in 0 ..63 {
321
+ for i in 0 ..64 {
113
322
let x = get_keyhash_chunky (body_text , body_indices [i ], key_lengths [i ]);
114
323
println (f"{ x} " );
115
324
}
@@ -226,11 +435,13 @@ expectations:
226
435
227
436
// chunks 1 removal cuts from 8.779 to 8.275 = 504 / 63 = 8
228
437
*/
229
- fn maikn (body_text : [u8 ; 1024 ], body_indices : [u16 ; 64 ], key_lengths : [u16 ; 64 ], dd : Field ) {
438
+ // 63: 8275
439
+ // 64: 8290
440
+ fn mainkjghg (body_text : [u8 ; 1024 ], body_indices : [u16 ; 64 ], key_lengths : [u16 ; 64 ], dd : Field ) {
230
441
println (f"{ body_text} { body_indices} { key_lengths} " );
231
442
let kk = slice_200_bits_from_field (dd );
232
443
println (f"{ kk} " );
233
- for i in 0 ..63 {
444
+ for i in 0 ..64 {
234
445
let x = sum_var_bytes_into_field (body_text , body_indices [i ] as Field , key_lengths [i ] as Field );
235
446
// let x = get_keyhash_chunky(body_text, body_indices[i], key_lengths[i]);
236
447
println (f"{ x} " );
0 commit comments