pub fn enforce_swapwx_constraints<E: FieldElement>(
    frame: &EvaluationFrame<E>,
    result: &mut [E],
    op_flag: &OpFlags<E>
) -> usize
Expand description

Enforces constraints of all the SWAP{W, W2, W3, DW} operations. Each of the operation effects the stack in the following way:

  • The SWAPW operation swaps the elements 0,1,2,3 with 4,5,6,7 in the stack.
  • The SWAPW2 operation swaps the elements 0,1,2,3 with 8,9,10,11 in the stack.
  • The SWAPW3 operation swaps the elements 0,1,2,3 with 12,13,14,15 in the stack.
  • The SWAPDW operation swaps the elements 0,1,2,3,4,5,6,7 with 8,9,10,11,12,13,14,15 in the stack.

Therefore, the following constraints are enforced:

  • During any frame, only one of these operation can be present (it is possible that none of these operations are present), therefore, the respective stack item can only transition into certain state and we can use this to combine these transition into one constraints where each transition are weighted by their respective flag. for eg. in the case of SWAPW3 the first item of the stack gets replaced with the 12 items and vice versa, therefore, only SWAPW3 transition will be ONE and rest all flags would be ZERO.