Skip to content

Commit 149f022

Browse files
committed
fix bug
1 parent 95c2b38 commit 149f022

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

executor/src/vm/instruction/execution.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ impl Instruction {
6464
}
6565
}
6666
Instruction::ArithImmW { dst, src, imm, op } => {
67-
// W-suffix: operate on lower 32 bits, sign-extend result to 64 bits
68-
let op1 = registers.read(src)? as i32;
67+
// W-suffix: operate on lower 32 bits, sign-extend result to 64 bits.
68+
// Log must store the RAW register value in src1_val (full 64 bits)
69+
// for the prover's MEMW register chain. The truncation to i32 is only
70+
// for the ALU computation.
71+
let raw_src = registers.read(src)?;
72+
let op1 = raw_src as i32;
6973
if matches!(op, ArithOp::Sub) {
7074
return Err(ExecutionError::SubImmNotSupported);
7175
}
@@ -75,7 +79,7 @@ impl Instruction {
7579
Log {
7680
current_pc: pc,
7781
next_pc: pc.wrapping_add(REGULAR_PC_UPDATE),
78-
src1_val: op1 as u64,
82+
src1_val: raw_src,
7983
src2_val: 0,
8084
dst_val: res,
8185
}
@@ -245,17 +249,21 @@ impl Instruction {
245249
src2,
246250
op,
247251
} => {
248-
// W-suffix: operate on lower 32 bits, sign-extend result to 64 bits
249-
let a = registers.read(src1)? as i32;
250-
let b = registers.read(src2)? as i32;
252+
// W-suffix: operate on lower 32 bits, sign-extend result to 64 bits.
253+
// Log must store RAW register values (full 64 bits) for the prover's
254+
// MEMW register chain. Truncation to i32 is only for ALU computation.
255+
let raw_src1 = registers.read(src1)?;
256+
let raw_src2 = registers.read(src2)?;
257+
let a = raw_src1 as i32;
258+
let b = raw_src2 as i32;
251259
let res32 = op.apply_word(a, b)?;
252260
let res = res32 as i64 as u64; // Sign-extend to 64 bits
253261
registers.write(dst, res)?;
254262
Log {
255263
current_pc: pc,
256264
next_pc: pc.wrapping_add(REGULAR_PC_UPDATE),
257-
src1_val: a as u64,
258-
src2_val: b as u64,
265+
src1_val: raw_src1,
266+
src2_val: raw_src2,
259267
dst_val: res,
260268
}
261269
}

0 commit comments

Comments
 (0)