Skip to content

Commit

Permalink
bench(sis): adds a benchmark for the ringsis hash (#511)
Browse files Browse the repository at this point in the history
* bench(sis): adds a benchmark for the ringsis hash
  • Loading branch information
AlexandreBelling authored Jan 8, 2025
1 parent b194b90 commit 35a8ded
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions prover/crypto/ringsis/ringsis_64_16/transerval_hash_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ringsis_64_16_test

import (
"fmt"
"math/rand"
"testing"

"github.com/consensys/gnark-crypto/ecc/bls12-377/fr/fft"
"github.com/consensys/linea-monorepo/prover/crypto/ringsis"
"github.com/consensys/linea-monorepo/prover/crypto/ringsis/ringsis_64_16"
"github.com/consensys/linea-monorepo/prover/maths/common/smartvectors"
wfft "github.com/consensys/linea-monorepo/prover/maths/fft"
"github.com/consensys/linea-monorepo/prover/maths/field"
)

func BenchmarkTransversalHash(b *testing.B) {

var (
numRow = 1024
numCols = 1024
rng = rand.New(rand.NewSource(786868)) // nolint
domain = fft.NewDomain(64, fft.WithShift(wfft.GetOmega(64*2)))
twiddles = ringsis_64_16.PrecomputeTwiddlesCoset(domain.Generator, domain.FrMultiplicativeGen)
params = ringsis.Params{LogTwoBound: 16, LogTwoDegree: 6}
numInputPerPoly = params.OutputSize() / (field.Bytes * 8 / params.LogTwoBound)
key = ringsis.GenerateKey(params, numRow)
numTestCases = 1 << numInputPerPoly
numPoly = numRow / numInputPerPoly
)

for tc := 0; tc < numTestCases; tc++ {

b.Run(fmt.Sprintf("testcase-%b", tc), func(b *testing.B) {

inputs := make([]smartvectors.SmartVector, 0, numPoly*numInputPerPoly)

for p := 0; p < numPoly; p++ {
for i := 0; i < numInputPerPoly; i++ {
if (tc>>i)&1 == 0 {
inputs = append(inputs, randomConstRow(rng, numCols))
} else {
inputs = append(inputs, randomRegularRow(rng, numCols))
}
}
}

b.ResetTimer()

for c := 0; c < b.N; c++ {
_ = ringsis_64_16.TransversalHash(key.Ag(), inputs, twiddles, domain)
}

})

}
}

0 comments on commit 35a8ded

Please sign in to comment.