Skip to content

Commit

Permalink
polynomials: rename PolyDomainEval to PolyRootsDomainEval as it's spe…
Browse files Browse the repository at this point in the history
…cialized to roots of unity domain
  • Loading branch information
mratsim committed Jun 8, 2024
1 parent 5ad064d commit cf730a1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion constantine/commitments/kzg_polynomial_commitments.nim
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func kzg_prove*[N: static int, C: static Curve](
proof: var ECP_ShortW_Aff[Fp[C], G1],
eval_at_challenge: var Fr[C],
poly: PolynomialEval[N, Fr[C]],
domain: PolyDomainEval[N, Fr[C]],
domain: PolyRootsDomainEval[N, Fr[C]],
challenge: Fr[C],
powers_of_tau: PolynomialEval[N, G1aff[C]],
isBitReversedDomain: static bool) {.tags:[Alloca, HeapAlloc, Vartime].} =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ proc kzg_prove_parallel*[N: static int, C: static Curve](
proof: var ECP_ShortW_Aff[Fp[C], G1],
eval_at_challenge: var Fr[C],
poly: ptr PolynomialEval[N, Fr[C]],
domain: ptr PolyDomainEval[N, Fr[C]],
domain: ptr PolyRootsDomainEval[N, Fr[C]],
challenge: ptr Fr[C],
powers_of_tau: PolynomialEval[N, G1aff[C]],
isBitReversedDomain: static bool) =
Expand Down Expand Up @@ -265,4 +265,4 @@ proc kzg_verify_batch_parallel*[bits: static int, F2; C: static Curve](
var gt {.noInit.}: C.getGT()
gt.pairing(sums, [tauG2, negG2])

return gt.isOne().bool()
return gt.isOne().bool()
9 changes: 5 additions & 4 deletions constantine/math/polynomials/polynomials.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ type
## https://en.wikipedia.org/wiki/Lagrange_polynomial#Barycentric_form
evals*{.align: 64.}: array[N, Group]

PolyDomainEval*[N: static int, Field] = object
PolyRootsDomainEval*[N: static int, Field] = object
## Metadata for polynomial in Lagrange basis (evaluation form)
## with evaluation points at roots of unity.
##
## Note on inverses
## 1/ωⁱ (mod N) = ωⁿ⁻ⁱ (mod N)
Expand All @@ -50,7 +51,7 @@ type

func inverseRootsMinusZ_vartime*[N: static int, Field](
invRootsMinusZ: var array[N, Field],
domain: PolyDomainEval[N, Field],
domain: PolyRootsDomainEval[N, Field],
z: Field,
earlyReturnOnZero: static bool): int =
## Compute 1/(ωⁱ-z) for i in [0, N)
Expand Down Expand Up @@ -111,7 +112,7 @@ func evalPolyAt*[N: static int, Field](
poly: PolynomialEval[N, Field],
z: Field,
invRootsMinusZ: array[N, Field],
domain: PolyDomainEval[N, Field]) =
domain: PolyRootsDomainEval[N, Field]) =
## Evaluate a polynomial in evaluation form
## at the point z
## z MUST NOT be one of the roots of unity
Expand Down Expand Up @@ -159,7 +160,7 @@ func differenceQuotientEvalInDomain*[N: static int, Field](
poly: PolynomialEval[N, Field],
zIndex: uint32,
invRootsMinusZ: array[N, Field],
domain: PolyDomainEval[N, Field],
domain: PolyRootsDomainEval[N, Field],
isBitReversedDomain: static bool) =
## Compute r(x) = (p(x) - p(z)) / (x - z)
##
Expand Down
6 changes: 3 additions & 3 deletions constantine/math/polynomials/polynomials_parallel.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ proc evalPolyAt_parallel*[N: static int, Field](
poly: ptr PolynomialEval[N, Field],
z: ptr Field,
invRootsMinusZ: ptr array[N, Field],
domain: ptr PolyDomainEval[N, Field]) =
domain: ptr PolyRootsDomainEval[N, Field]) =
## Evaluate a polynomial in evaluation form
## at the point z
## z MUST NOT be one of the roots of unity
Expand Down Expand Up @@ -100,7 +100,7 @@ proc differenceQuotientEvalInDomain_parallel*[N: static int, Field](
poly: ptr PolynomialEval[N, Field],
zIndex: uint32,
invRootsMinusZ: ptr array[N, Field],
domain: ptr PolyDomainEval[N, Field],
domain: ptr PolyRootsDomainEval[N, Field],
isBitReversedDomain: static bool) =
## Compute r(x) = (p(x) - p(z)) / (x - z)
##
Expand Down Expand Up @@ -153,4 +153,4 @@ proc differenceQuotientEvalInDomain_parallel*[N: static int, Field](
epilogue:
return worker_ri

r.evals[zIndex] = sync(evalsZindex)
r.evals[zIndex] = sync(evalsZindex)
2 changes: 1 addition & 1 deletion constantine/trusted_setups/ethereum_kzg_srs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ type
# For most schemes (Marlin, Plonk, Sonic, Ethereum's Deneb), only [τ]H is needed
# but Ethereum's sharding will need 64 (65 with the generator H)

domain*{.align: 64.}: PolyDomainEval[FIELD_ELEMENTS_PER_BLOB, Fr[BLS12_381]]
domain*{.align: 64.}: PolyRootsDomainEval[FIELD_ELEMENTS_PER_BLOB, Fr[BLS12_381]]

TrustedSetupStatus* = enum
tsSuccess
Expand Down

0 comments on commit cf730a1

Please sign in to comment.