-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add new domain abstraction (#86)
* add new Domain abstraction * refactor rest of code to use new domain package * fix linter * chore: add back `TestSRSConversion`
- Loading branch information
1 parent
4aa46d3
commit d969d3a
Showing
17 changed files
with
201 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package domain | ||
|
||
import ( | ||
"github.com/consensys/gnark-crypto/ecc/bls12-381/fr" | ||
) | ||
|
||
// FFTCoset represents a coset for Fast Fourier Transform operations. | ||
// It contains the generator of the coset and its inverse. | ||
type FFTCoset struct { | ||
// CosetGen is the generator element of the coset. | ||
// It's used to shift the domain for coset FFT operations. | ||
CosetGen fr.Element | ||
|
||
// InvCosetGen is the inverse of the coset generator. | ||
// It's used in inverse coset FFT operations to shift back to the original domain. | ||
InvCosetGen fr.Element | ||
} | ||
|
||
// CosetDomain represents a domain for performing FFT operations over a coset. | ||
// It combines a standard FFT domain with coset information for efficient coset FFT computations. | ||
type CosetDomain struct { | ||
// domain is the underlying FFT domain. | ||
domain *Domain | ||
|
||
// coset contains the coset generator and its inverse for this domain. | ||
coset FFTCoset | ||
} | ||
|
||
// NewCosetDomain creates a new CosetDomain with the given Domain and FFTCoset. | ||
func NewCosetDomain(domain *Domain, fft_coset FFTCoset) *CosetDomain { | ||
return &CosetDomain{ | ||
domain: domain, | ||
coset: fft_coset, | ||
} | ||
} | ||
|
||
// CosetFFtFr performs a forward coset FFT on the input values. | ||
// | ||
// It first scales the input values by powers of the coset generator, | ||
// then performs a standard FFT on the scaled values. | ||
func (d *CosetDomain) CosetFFtFr(values []fr.Element) []fr.Element { | ||
result := make([]fr.Element, len(values)) | ||
|
||
cosetScale := fr.One() | ||
for i := 0; i < len(values); i++ { | ||
result[i].Mul(&values[i], &cosetScale) | ||
cosetScale.Mul(&cosetScale, &d.coset.CosetGen) | ||
} | ||
|
||
return d.domain.FftFr(result) | ||
} | ||
|
||
// CosetIFFtFr performs an inverse coset FFT on the input values. | ||
// | ||
// It first performs a standard inverse FFT, then scales the results | ||
// by powers of the inverse coset generator to shift back to the original domain. | ||
func (d *CosetDomain) CosetIFFtFr(values []fr.Element) []fr.Element { | ||
result := d.domain.IfftFr(values) | ||
|
||
cosetScale := fr.One() | ||
for i := 0; i < len(result); i++ { | ||
result[i].Mul(&result[i], &cosetScale) | ||
cosetScale.Mul(&cosetScale, &d.coset.InvCosetGen) | ||
} | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package domain | ||
|
||
import "errors" | ||
|
||
var ErrPolynomialMismatchedSizeDomain = errors.New("domain size does not equal the number of evaluations in the polynomial") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.