Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Constrain MSTORE_32BYTES new offset limbs (0xPolygonZero#1415)
Browse files Browse the repository at this point in the history
  • Loading branch information
hratoanina authored Dec 13, 2023
1 parent bc1a3c4 commit 71dff6e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions evm/src/cpu/byte_unpacking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) fn eval_packed<P: PackedField>(
// The MSTORE_32BYTES opcodes are differentiated from MLOAD_32BYTES
// by the 5th bit set to 0.
let filter = lv.op.m_op_32bytes * (lv.opcode_bits[5] - P::ONES);
let new_offset = nv.mem_channels[0].value[0];
let new_offset = nv.mem_channels[0].value;
let virt = lv.mem_channels[2].value[0];
// Read len from opcode bits and constrain the pushed new offset.
let len_bits: P = lv.opcode_bits[..5]
Expand All @@ -25,7 +25,10 @@ pub(crate) fn eval_packed<P: PackedField>(
.map(|(i, &bit)| bit * P::Scalar::from_canonical_u64(1 << i))
.sum();
let len = len_bits + P::ONES;
yield_constr.constraint(filter * (new_offset - virt - len));
yield_constr.constraint(filter * (new_offset[0] - virt - len));
for &limb in &new_offset[1..] {
yield_constr.constraint(filter * limb);
}
}

pub(crate) fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
Expand All @@ -38,7 +41,7 @@ pub(crate) fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
// by the 5th bit set to 0.
let filter =
builder.mul_sub_extension(lv.op.m_op_32bytes, lv.opcode_bits[5], lv.op.m_op_32bytes);
let new_offset = nv.mem_channels[0].value[0];
let new_offset = nv.mem_channels[0].value;
let virt = lv.mem_channels[2].value[0];
// Read len from opcode bits and constrain the pushed new offset.
let len_bits = lv.opcode_bits[..5].iter().enumerate().fold(
Expand All @@ -47,8 +50,12 @@ pub(crate) fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
builder.mul_const_add_extension(F::from_canonical_u64(1 << i), bit, cumul)
},
);
let diff = builder.sub_extension(new_offset, virt);
let diff = builder.sub_extension(new_offset[0], virt);
let diff = builder.sub_extension(diff, len_bits);
let constr = builder.mul_sub_extension(filter, diff, filter);
yield_constr.constraint(builder, constr);
for &limb in &new_offset[1..] {
let constr = builder.mul_extension(filter, limb);
yield_constr.constraint(builder, constr);
}
}

0 comments on commit 71dff6e

Please sign in to comment.