Constrain partial_channel (#1436)

This commit is contained in:
Hamy Ratoanina 2023-12-21 15:59:16 -05:00 committed by GitHub
parent cb3f91a003
commit c3d707c126
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 0 deletions

View File

@ -335,6 +335,9 @@ pub(crate) fn eval_packed<P: PackedField>(
eval_packed_dup(n, lv, nv, yield_constr);
eval_packed_swap(n, lv, nv, yield_constr);
// For both, disable the partial channel.
yield_constr.constraint(lv.op.dup_swap * lv.partial_channel.used);
}
/// Circuit version of `eval_packed`.
@ -354,4 +357,10 @@ pub(crate) fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
eval_ext_circuit_dup(builder, n, lv, nv, yield_constr);
eval_ext_circuit_swap(builder, n, lv, nv, yield_constr);
// For both, disable the partial channel.
{
let constr = builder.mul_extension(lv.op.dup_swap, lv.partial_channel.used);
yield_constr.constraint(builder, constr);
}
}

View File

@ -142,6 +142,8 @@ pub(crate) fn eval_packed_jump_jumpi<P: PackedField>(
for &channel in &lv.mem_channels[2..NUM_GP_CHANNELS - 1] {
yield_constr.constraint(filter * channel.used);
}
yield_constr.constraint(filter * lv.partial_channel.used);
// Channel 1 is unused by the `JUMP` instruction.
yield_constr.constraint(is_jump * lv.mem_channels[1].used);
@ -324,6 +326,10 @@ pub(crate) fn eval_ext_circuit_jump_jumpi<F: RichField + Extendable<D>, const D:
let constr = builder.mul_extension(filter, channel.used);
yield_constr.constraint(builder, constr);
}
{
let constr = builder.mul_extension(filter, lv.partial_channel.used);
yield_constr.constraint(builder, constr);
}
// Channel 1 is unused by the `JUMP` instruction.
{
let constr = builder.mul_extension(is_jump, lv.mem_channels[1].used);

View File

@ -56,6 +56,7 @@ fn eval_packed_load<P: PackedField>(
for &channel in &lv.mem_channels[4..NUM_GP_CHANNELS] {
yield_constr.constraint(filter * channel.used);
}
yield_constr.constraint(filter * lv.partial_channel.used);
// Stack constraints
stack::eval_packed_one(
@ -120,6 +121,10 @@ fn eval_ext_circuit_load<F: RichField + Extendable<D>, const D: usize>(
let constr = builder.mul_extension(filter, channel.used);
yield_constr.constraint(builder, constr);
}
{
let constr = builder.mul_extension(filter, lv.partial_channel.used);
yield_constr.constraint(builder, constr);
}
// Stack constraints
stack::eval_ext_circuit_one(

View File

@ -357,6 +357,8 @@ pub(crate) fn eval_packed<P: PackedField>(
for &channel in &lv.mem_channels[1..] {
yield_constr.constraint(lv.op.not_pop * (lv.opcode_bits[0] - P::ONES) * channel.used);
}
yield_constr
.constraint(lv.op.not_pop * (lv.opcode_bits[0] - P::ONES) * lv.partial_channel.used);
// Constrain the new stack length for POP.
yield_constr.constraint_transition(
@ -700,6 +702,10 @@ pub(crate) fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
let constr = builder.mul_extension(filter, channel.used);
yield_constr.constraint(builder, constr);
}
{
let constr = builder.mul_extension(filter, lv.partial_channel.used);
yield_constr.constraint(builder, constr);
}
// Constrain the new stack length for POP.
let diff = builder.sub_extension(nv.stack_len, lv.stack_len);