-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stdlib: comparator & bigint #180
base: main
Are you sure you want to change the base?
Conversation
1 == (-1 * v_2 + 1) * (1) | ||
1 == (v_4) * (1) | ||
1 == (-1 * v_6 + 1) * (1) | ||
v_1 == (v_2 + 2 * v_4 + 4 * v_6) * (1) | ||
0 == (v_8) * (1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the asm diffs originated from the fact that the builtin version stored constant as cell vars.
One idea inspired from this experiment about hint function is how we can deal with the unconstrained / unsafe expressions to:
Example of using builtin function as hint function// native version of `bits::to_bits`
fn to_bits(const LEN: Field, value: Field) -> [Bool; LEN] {
let mut bits = [false; LEN];
let mut lc1 = 0;
let mut e2 = 1;
let one = 1;
let zero = 0;
for index in 0..LEN {
// code for `bits::nth_bit`: https://github.com/zksecurity/noname/blob/564ae004cf4c580efb0f473c69a198b88127baed/src/stdlib/bits.rs#L37-L81
bits[index] = bits::nth_bit(value, index);
let bit_num = if bits[index] {one} else {zero};
assert_eq(bit_num * (bit_num - 1), 0);
lc1 = lc1 + if bits[index] {e2} else {zero};
e2 = e2 + e2;
}
assert_eq(lc1, value);
return bits;
} Attribute unsafe
To make the code explicit about where the non-deterministic expressions are, we can require an attribute called bits[index] = unsafe bits::nth_bit(value, index); We may also require the unsafe nth_bit(val: Field, const nth: Field) -> Bool While the unsafe attribute is for the users to acknowledge that they are responsible for having additional constraints, it can also help type check if an expression can be added as constraints. The type check workflow would be:
In comparison to how circom handles hint calculations, this approach makes it explicit whether an expression is non-deterministic at the first place. Potential design for native hint functionThe For constructing the hint calculations for a hint function, we may just handle it in a separate synthesizer workflow that doesn't add any constraints but only build up a set of symbolic values. Each of them can be mapped to a cell var in a backend. |
5f2769e
to
f794eeb
Compare
new stdlib
comparator bd2e612
bigint 1e586e9
data type bd2e612
Issues to resolve
Adjustments