Constraints for conditionals #226
vivekvpandya
started this conversation in
Ideas
Replies: 2 comments
-
We can adapt Ola's technique for |
Beta Was this translation helpful? Give feedback.
0 replies
-
820ac58 Proptest for verifying constraint works for BGE/BGEU |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This design is based on OlaVM's cmp builtin.
See source code for constraint at: https://github.com/Sin7Y/olavm/blob/main/circuits/src/builtins/cmp/cmp_stark.rs
How they generate trace at https://github.com/Sin7Y/olavm/blob/main/executor/src/lib.rs#L773 and particularly how they compute abs_diff before converting to field https://github.com/Sin7Y/olavm/blob/main/executor/src/lib.rs#L809
Constraints for BGE/BGEU which checks if opd1 >= op2
examples
5 > 1 :
cond = (5 - 1 - 4) = 0;
cond_inv = 0;
check = 0
so branch is taken and we constrain accordingly
5 > 8:
cond = (5 - 8 - 3) = -6;
cond_inv = 1/-3;
check = 1;
so branch is not taken and we constrain accordingly
-5 > -1:
cond = (-5 - (-1) - 4) = -8;
cond_inv = 1/-8;
check = 1
...
-5 > -8:
cond = (-5 - (-8) - 3) = 0;
cond_inv = 0
check = 0
...
5 > -1:
cond = (5 - (-1) - 6) = 0;
cond_inv = 0
check = 0
...
-5 > 1:
cond = (-5 - 1 - 6) = -12;
cond_inv = 1/-12;
check = 1
...
Constraints for BLT/BLTU which checks if opd1 < op2
Based on Ola https://github.com/Sin7Y/olavm/blob/main/circuits/src/cpu/cmp.rs
Constraints for BEQ
Constraints for BNE
Constraints for SLT/SLTU
Beta Was this translation helpful? Give feedback.
All reactions