Zokrates / ZoKrates

A toolbox for zkSNARKs on Ethereum
https://zokrates.github.io
GNU Lesser General Public License v3.0
1.8k stars 360 forks source link

Unexpected Result When Dividing Field Elements #1337

Closed silvesterdrago closed 9 months ago

silvesterdrago commented 1 year ago

Description: When dividing certain field elements the result is unexpected. Specifically, dividing 11 by 10 yields a large field element instead of the expected 1 or its equivalent representation in the field.

Code to Reproduce:

field x = 11;
field y = x / 10;
assert(y == 15321770010287492655572484021680092561983855080291224040588742930603065946933);

Expected Behavior: The division of 11 by 10 should result in 1 or its equivalent representation in the field.

Actual Behavior: The division results in the field element 15321770010287492655572484021680092561983855080291224040588742930603065946933.

Version: ZoKrates 0.8.7

dark64 commented 1 year ago

This behavior is correct, division is defined as multiplication by the inverse modulo p. What you want is integer division, this is being added in https://github.com/Zokrates/ZoKrates/pull/1349