// Copyright 2023 Ingonyama // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Code generated by Ingonyama DO NOT EDIT package bw6761 import ( "fmt" "math" "testing" "time" "unsafe" "github.com/ingonyama-zk/icicle/goicicle" "github.com/stretchr/testify/assert" ) func GeneratePoints(count int) []G1PointAffine { // Declare a slice of integers var points []G1PointAffine // populate the slice for i := 0; i < 10; i++ { var pointProjective G1ProjectivePoint pointProjective.Random() var pointAffine G1PointAffine pointAffine.FromProjective(&pointProjective) points = append(points, pointAffine) } log2_10 := math.Log2(10) log2Count := math.Log2(float64(count)) log2Size := int(math.Ceil(log2Count - log2_10)) for i := 0; i < log2Size; i++ { points = append(points, points...) } return points[:count] } func GeneratePointsProj(count int) []G1ProjectivePoint { // Declare a slice of integers var points []G1ProjectivePoint // Use a loop to populate the slice for i := 0; i < count; i++ { var p G1ProjectivePoint p.Random() points = append(points, p) } return points } func GenerateScalars(count int, skewed bool) []G1ScalarField { // Declare a slice of integers var scalars []G1ScalarField var rand G1ScalarField var zero G1ScalarField var one G1ScalarField var randLarge G1ScalarField zero.SetZero() one.SetOne() randLarge.Random() if skewed && count > 1_200_000 { for i := 0; i < count-1_200_000; i++ { rand.Random() scalars = append(scalars, rand) } for i := 0; i < 600_000; i++ { scalars = append(scalars, randLarge) } for i := 0; i < 400_000; i++ { scalars = append(scalars, zero) } for i := 0; i < 200_000; i++ { scalars = append(scalars, one) } } else { for i := 0; i < count; i++ { rand.Random() scalars = append(scalars, rand) } } return scalars[:count] } func TestMSM(t *testing.T) { fmt.Print() // this prevents the test from hanging. TODO: figure out why for _, v := range []int{8} { count := 1 << v points := GeneratePoints(count) fmt.Print("Finished generating points\n") scalars := GenerateScalars(count, false) fmt.Print("Finished generating scalars\n") out := new(G1ProjectivePoint) startTime := time.Now() _, e := Msm(out, points, scalars, 0) // non mont fmt.Printf("icicle MSM took: %d ms\n", time.Since(startTime).Milliseconds()) assert.Equal(t, e, nil, "error should be nil") assert.True(t, out.IsOnCurve()) } } func TestCommitMSM(t *testing.T) { for _, v := range []int{8} { count := 1<