Skip to content

Commit

Permalink
Merge pull request #496 from Consensys/sis/export-fft64
Browse files Browse the repository at this point in the history
Chores: export the unrolled FFT64 out of SIS
  • Loading branch information
AlexandreBelling committed Apr 11, 2024
2 parents 73d5980 + fe0c2ca commit f2e861f
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions ecc/bls12-377/fr/sis/sis.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type RSis struct {

// domain for the polynomial multiplication
Domain *fft.Domain
twiddleCosets []fr.Element // see fft64 and precomputeTwiddlesCoset
twiddleCosets []fr.Element // see FFT64 and precomputeTwiddlesCoset

// d, the degree of X^{d}+1
Degree int
Expand Down Expand Up @@ -129,7 +129,7 @@ func NewRSis(seed int64, logTwoDegree, logTwoBound, maxNbElementsToHash int) (*R
}
if r.LogTwoBound == 8 && r.Degree == 64 {
// TODO @gbotrel fixme, that's dirty.
r.twiddleCosets = precomputeTwiddlesCoset(r.Domain.Generator, r.Domain.FrMultiplicativeGen)
r.twiddleCosets = PrecomputeTwiddlesCoset(r.Domain.Generator, r.Domain.FrMultiplicativeGen)
}

// filling A
Expand Down Expand Up @@ -199,7 +199,7 @@ func (r *RSis) Sum(b []byte) []byte {
k := m[i*r.Degree : (i+1)*r.Degree]
if fastPath {
// fast path.
fft64(k, r.twiddleCosets)
FFT64(k, r.twiddleCosets)
} else {
r.Domain.FFT(k, fft.DIF, fft.OnCoset(), fft.WithNbTasks(1))
}
Expand Down
10 changes: 5 additions & 5 deletions ecc/bls12-377/fr/sis/sis_fft.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ecc/bls12-377/fr/sis/sis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ func TestUnrolledFFT(t *testing.T) {
domain.FFT(k1, fft.DIF, fft.OnCoset(), fft.WithNbTasks(1))

// unrolled FFT
twiddlesCoset := precomputeTwiddlesCoset(domain.Generator, domain.FrMultiplicativeGen)
fft64(k2, twiddlesCoset)
twiddlesCoset := PrecomputeTwiddlesCoset(domain.Generator, domain.FrMultiplicativeGen)
FFT64(k2, twiddlesCoset)

// compare results
for i := 0; i < size; i++ {
Expand Down
6 changes: 3 additions & 3 deletions ecc/bn254/fr/sis/sis.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type RSis struct {

// domain for the polynomial multiplication
Domain *fft.Domain
twiddleCosets []fr.Element // see fft64 and precomputeTwiddlesCoset
twiddleCosets []fr.Element // see FFT64 and precomputeTwiddlesCoset

// d, the degree of X^{d}+1
Degree int
Expand Down Expand Up @@ -129,7 +129,7 @@ func NewRSis(seed int64, logTwoDegree, logTwoBound, maxNbElementsToHash int) (*R
}
if r.LogTwoBound == 8 && r.Degree == 64 {
// TODO @gbotrel fixme, that's dirty.
r.twiddleCosets = precomputeTwiddlesCoset(r.Domain.Generator, r.Domain.FrMultiplicativeGen)
r.twiddleCosets = PrecomputeTwiddlesCoset(r.Domain.Generator, r.Domain.FrMultiplicativeGen)
}

// filling A
Expand Down Expand Up @@ -199,7 +199,7 @@ func (r *RSis) Sum(b []byte) []byte {
k := m[i*r.Degree : (i+1)*r.Degree]
if fastPath {
// fast path.
fft64(k, r.twiddleCosets)
FFT64(k, r.twiddleCosets)
} else {
r.Domain.FFT(k, fft.DIF, fft.OnCoset(), fft.WithNbTasks(1))
}
Expand Down
10 changes: 5 additions & 5 deletions ecc/bn254/fr/sis/sis_fft.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ecc/bn254/fr/sis/sis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ func TestUnrolledFFT(t *testing.T) {
domain.FFT(k1, fft.DIF, fft.OnCoset(), fft.WithNbTasks(1))

// unrolled FFT
twiddlesCoset := precomputeTwiddlesCoset(domain.Generator, domain.FrMultiplicativeGen)
fft64(k2, twiddlesCoset)
twiddlesCoset := PrecomputeTwiddlesCoset(domain.Generator, domain.FrMultiplicativeGen)
FFT64(k2, twiddlesCoset)

// compare results
for i := 0; i < size; i++ {
Expand Down
10 changes: 5 additions & 5 deletions internal/generator/sis/template/fft.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import (
"math/big"
)

// fft64 is generated by gnark-crypto and contains the unrolled code for FFT (DIF) on 64 elements
// FFT64 is generated by gnark-crypto and contains the unrolled code for FFT (DIF) on 64 elements
// equivalent code: r.Domain.FFT(k, fft.DIF, fft.OnCoset(), fft.WithNbTasks(1))
// twiddlesCoset must be pre-computed from twiddles and coset table, see precomputeTwiddlesCoset
func fft64(a []fr.Element, twiddlesCoset []fr.Element) {
// twiddlesCoset must be pre-computed from twiddles and coset table, see PrecomputeTwiddlesCoset
func FFT64(a []fr.Element, twiddlesCoset []fr.Element) {

{{- /* notes:
this function can be updated with larger n
Expand Down Expand Up @@ -47,9 +47,9 @@ func fft64(a []fr.Element, twiddlesCoset []fr.Element) {
{{- end}}
}

// precomputeTwiddlesCoset precomputes twiddlesCoset from twiddles and coset table
// PrecomputeTwiddlesCoset precomputes twiddlesCoset from twiddles and coset table
// it then return all elements in the correct order for the unrolled FFT.
func precomputeTwiddlesCoset(generator, shifter fr.Element) []fr.Element {
func PrecomputeTwiddlesCoset(generator, shifter fr.Element) []fr.Element {
toReturn := make([]fr.Element, 63)
var r, s fr.Element
e := new(big.Int)
Expand Down

0 comments on commit f2e861f

Please sign in to comment.