-
Notifications
You must be signed in to change notification settings - Fork 1
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
Notes on Field Agnosticity #390
Comments
ConstraintsThe existing constraints split
What we see is that the |
Word SizeGiven a field (Configurations) Generally speaking, we want to choose a word size such that the underlying field can hold the result of summing at least |
AdditionWhen adding two Here, we are adding two values (defcolumns
(X3 :i16@prove) (X2 :i16@prove) (X1 :i16@prove) (X0 :i16@prove)
(Y3 :i16@prove) (Y2 :i16@prove) (Y1 :i16@prove) (Y0 :i16@prove)
(C3 :i1@prove) (C2 :i1@prove) (C1 :i1@prove) (C0 :i1@prove)
(Z3 :i16) (Z2 :i16) (Z1 :i16) (Z0 :i16))
(defconst OVERFLOW 65536)
(defpurefun (ADDER cin arg1 arg2 out cout)
(eq! (+ out (* cout OVERFLOW)) (+ arg1 arg2 cin)))
(defconstraint X_Y_Z ()
(begin
(ADDER 0 X0 Y0 Z0 C0)
(ADDER C0 X1 Y1 Z1 C1)
(ADDER C1 X2 Y2 Z2 C2)
(ADDER C2 X3 Y3 Z3 C3))) Here, columns for |
Zero TestThe zero test checks whether a given expression is zero or not. When a given
In this example, we are assuming that the sum |
NormalisationThe normalisation operator projects a given value
|
ConstraintsAn import question is how we apply all of this to actual constraints. As a simple example, consider:
And let's assume all columns are
Then, start by breaking up the constraints:
We can see this will fail because
Then, for our example, we get this:
Question 1Can we optimise this to use just temporary one column, or not?
Question 2Can we optimise the number of range constraints required?
|
Suggestion which uses four binary columns:
This seems a bit iffy though, as in some cases
And we require that |
A rough strategy starts to appear:
There are a couple of problems with this as a basic approach:
For example, consider expanding this constraint:
Problem) the expanded form requires several non-linear multiplication gates --- which are presumably expensive to implement? Therefore) It makes sense to work on the original logical form. It is actually possible to lower HIR into the logical form (LIR) rather than MIR then either go from there to MIR, or straight down to AIR. |
Overview
The goal here is to allow support for different underlying prime fields. Currently, the prime field is assumed to be BLS12-377. That requires a minimum of
252bits
of storage, and can comfortably holdu128
values for addition without overflow. Thus, representing au256
value (as found in the EVM) requires a vector of two field elements. The challenge with supporting different fields is that many of interest are much smaller:(Goldilocks) Elements on the goldilocks field fit into a single
u64
whose primep
is defined as2^64 - 2^32 + 1 = 18446744069414584321
. This means it can hold the result of adding fouru62
values without overflow. Thus, in order to represent au256
value, we would need a vector of at least five field elements.(Baby Bear) Elements on the Baby Bear field fit into a single
u32
whose primep
is defined as15*2^27 + 1 = 450359962737049
. This means it can hold the result of adding twou30
values without overflow. Thus, in order to represent au256
value, _we would need a vector of at least9
elements.The goal here is to give some example implementations of common operations, such as addition, multiplication, normalisation, comparison, etc. This is loosely based on an original set of notes.
The text was updated successfully, but these errors were encountered: