-
Notifications
You must be signed in to change notification settings - Fork 10
Description
The substobj and substmorph types in https://github.com/anoma/geb/blob/main/src/specs/geb.lisp should be extended with those required for built-in modular arithmetic.
Specifically, there will be a new object called something like fs n for each non-zero natural n (not for zero, because arithmetic mod 0 is Nat itself, and circuits can only support fixed-size natural numbers).
There will be the following new morphisms with the following signatures, where bool is coprod so1 so1, and fs <n> means for every non-zero natural number <n>:
- For each natural number
mincluding zero and less thann,const m:so1 -> fs n inj:fs m -> fs n(injects one bounded type into another -- may wrap around ifm > n; equal toidifm == n)+:prod (fs m) (fs n) -> fs p*:prod (fs m) (fs n) -> fs p-:prod (fs m) (fs n) -> fs p/:prod (fs m) (fs n) -> fs p%:prod (fs m) (fs n) -> fs p==:prod (fs m) (fs n) -> bool<:prod (fs m) (fs n) -> bool
Because the arithmetic is modular, overflows just cause wraparound. Division and modulus by zero will produce errors at witness generation time in VampIR. (Once we support dependent types in Geb, we will be able to allow users to include proof content demonstrating that they are not dividing by zero.)
VampIR higher-order functions might be helpful in integrating this with #60 ; see https://github.com/anoma/vamp-ir/blob/main/tests/funcs.pir for examples.