@@ -270,7 +270,7 @@ impl<F: PrimeField32> VmAdapterChipWom<F> for JaafAdapterChipWom<F> {
270
270
fn preprocess (
271
271
& mut self ,
272
272
memory : & mut MemoryController < F > ,
273
- _fp : u32 ,
273
+ fp : u32 ,
274
274
instruction : & Instruction < F > ,
275
275
) -> Result < (
276
276
<Self :: Interface as VmAdapterInterface < F > >:: Reads ,
@@ -281,11 +281,13 @@ impl<F: PrimeField32> VmAdapterChipWom<F> for JaafAdapterChipWom<F> {
281
281
let local_opcode =
282
282
JaafOpcode :: from_usize ( opcode. local_opcode_idx ( JaafOpcode :: CLASS_OFFSET ) ) ;
283
283
284
+ let fp_f = F :: from_canonical_u32 ( fp) ;
285
+
284
286
// Determine which registers to read based on opcode
285
287
let ( pc_source_record, pc_source_data) = match local_opcode {
286
288
JaafOpcode :: RET | JaafOpcode :: CALL_INDIRECT => {
287
289
// Read pc_source (c field) for target PC
288
- let pc_source = memory. read :: < RV32_REGISTER_NUM_LIMBS > ( F :: ONE , c) ;
290
+ let pc_source = memory. read :: < RV32_REGISTER_NUM_LIMBS > ( F :: ONE , c + fp_f ) ;
289
291
( Some ( pc_source. 0 ) , pc_source. 1 )
290
292
}
291
293
_ => {
@@ -296,7 +298,7 @@ impl<F: PrimeField32> VmAdapterChipWom<F> for JaafAdapterChipWom<F> {
296
298
} ;
297
299
298
300
// All opcodes always read fp_source (e field) for target FP
299
- let fp_source = memory. read :: < RV32_REGISTER_NUM_LIMBS > ( F :: ONE , e) ;
301
+ let fp_source = memory. read :: < RV32_REGISTER_NUM_LIMBS > ( F :: ONE , e + fp_f ) ;
300
302
301
303
Ok ( (
302
304
[ pc_source_data, fp_source. 1 ] ,
@@ -325,6 +327,8 @@ impl<F: PrimeField32> VmAdapterChipWom<F> for JaafAdapterChipWom<F> {
325
327
..
326
328
} = * instruction;
327
329
330
+ let to_fp = output. to_fp . unwrap ( ) ;
331
+
328
332
let local_opcode =
329
333
JaafOpcode :: from_usize ( opcode. local_opcode_idx ( JaafOpcode :: CLASS_OFFSET ) ) ;
330
334
@@ -340,13 +344,16 @@ impl<F: PrimeField32> VmAdapterChipWom<F> for JaafAdapterChipWom<F> {
340
344
JaafOpcode :: JAAF_SAVE => {
341
345
// Save fp to rd2 (b field)
342
346
memory. increment_timestamp ( ) ;
343
- let rd2 = memory. write ( F :: ONE , b, output. writes [ 1 ] ) ;
347
+ let rd2 =
348
+ memory. write ( F :: ONE , b + F :: from_canonical_u32 ( to_fp) , output. writes [ 1 ] ) ;
344
349
( None , Some ( rd2. 0 ) )
345
350
}
346
351
JaafOpcode :: CALL | JaafOpcode :: CALL_INDIRECT => {
347
352
// Save both pc to rd1 (a field) and fp to rd2 (b field)
348
- let rd1 = memory. write ( F :: ONE , a, output. writes [ 0 ] ) ;
349
- let rd2 = memory. write ( F :: ONE , b, output. writes [ 1 ] ) ;
353
+ let rd1 =
354
+ memory. write ( F :: ONE , a + F :: from_canonical_u32 ( to_fp) , output. writes [ 0 ] ) ;
355
+ let rd2 =
356
+ memory. write ( F :: ONE , b + F :: from_canonical_u32 ( to_fp) , output. writes [ 1 ] ) ;
350
357
( Some ( rd1. 0 ) , Some ( rd2. 0 ) )
351
358
}
352
359
}
@@ -361,7 +368,7 @@ impl<F: PrimeField32> VmAdapterChipWom<F> for JaafAdapterChipWom<F> {
361
368
pc : output. to_pc . unwrap_or ( from_state. pc + DEFAULT_PC_STEP ) ,
362
369
timestamp : memory. timestamp ( ) ,
363
370
} ,
364
- output . to_fp . unwrap_or ( from_frame . fp ) ,
371
+ to_fp,
365
372
Self :: WriteRecord {
366
373
from_state,
367
374
from_frame,
0 commit comments