Files
linea-monorepo/prover/crypto/ringsis/templates/limb_decompose_test.go.tmpl
Lakshminarayanan Nandakumar 8ddd4c1d3d Prover/wizard performance monitor (#768)
* wizard runtime perf monitor

* ring-sis before revert

* sanity check successful

* rm test config file
2025-03-12 08:43:31 +00:00

48 lines
1.2 KiB
Cheetah

package ringsis_{{.ModulusDegree}}_{{.LogTwoBound}}
import (
"math/big"
"math/rand/v2"
"testing"
"github.com/consensys/linea-monorepo/prover/maths/field"
"github.com/stretchr/testify/assert"
)
{{- $bitPerField := 256}}
{{- $limbPerField := div $bitPerField .LogTwoBound}}
{{- $fieldPerPoly := div .ModulusDegree $limbPerField}}
{{- $numMask := pow 2 $fieldPerPoly}}
func TestLimbDecompose(t *testing.T) {
var (
limbs = make([]int64, {{.ModulusDegree}})
rng = rand.New(rand.NewChaCha8([32]byte{}))
inputs = make([]field.Element, {{$fieldPerPoly}})
obtainedLimbs = make([]field.Element, {{.ModulusDegree}})
)
for i := range limbs {
if i%{{$limbPerField}} > {{sub $limbPerField 1}} {
limbs[i] = int64(rng.IntN(1 << {{.LogTwoBound}}))
}
}
for i := 0; i < {{$fieldPerPoly}}; i++ {
buf := &big.Int{}
for j := {{sub $limbPerField 2}}; j >= 0; j-- {
buf.Mul(buf, big.NewInt(1<<{{.LogTwoBound}}))
tmp := new(big.Int).SetInt64(limbs[{{$limbPerField}}*i+j])
buf.Add(buf, tmp)
}
inputs[i].SetBigInt(buf)
}
limbDecompose(obtainedLimbs, inputs)
for i := range obtainedLimbs {
assert.Equal(t, uint64(limbs[i]), obtainedLimbs[i][0])
}
}