github.com/consensys/gnark-crypto@v0.14.0/ecc/bls24-315/fr/permutation/permutation_test.go (about)

     1  // Copyright 2020 Consensys Software Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Code generated by consensys/gnark-crypto DO NOT EDIT
    16  
    17  package permutation
    18  
    19  import (
    20  	"math/big"
    21  	"testing"
    22  
    23  	"github.com/stretchr/testify/assert"
    24  
    25  	"github.com/consensys/gnark-crypto/ecc/bls24-315/fr"
    26  	"github.com/consensys/gnark-crypto/ecc/bls24-315/kzg"
    27  )
    28  
    29  func TestProof(t *testing.T) {
    30  
    31  	kzgSrs, err := kzg.NewSRS(64, big.NewInt(13))
    32  	assert.NoError(t, err)
    33  
    34  	a := make([]fr.Element, 8)
    35  	b := make([]fr.Element, 8)
    36  
    37  	for i := 0; i < 8; i++ {
    38  		a[i].SetUint64(uint64(4*i + 1))
    39  	}
    40  	for i := 0; i < 8; i++ {
    41  		b[i].Set(&a[(5*i)%8])
    42  	}
    43  
    44  	// correct proof
    45  	{
    46  		proof, err := Prove(kzgSrs.Pk, a, b)
    47  		if err != nil {
    48  			t.Fatal(err)
    49  		}
    50  
    51  		err = Verify(kzgSrs.Vk, proof)
    52  		if err != nil {
    53  			t.Fatal(err)
    54  		}
    55  	}
    56  
    57  	// wrong proof
    58  	{
    59  		a[0].SetRandom()
    60  		proof, err := Prove(kzgSrs.Pk, a, b)
    61  		if err != nil {
    62  			t.Fatal(err)
    63  		}
    64  
    65  		err = Verify(kzgSrs.Vk, proof)
    66  		if err == nil {
    67  			t.Fatal(err)
    68  		}
    69  	}
    70  
    71  }
    72  
    73  func BenchmarkProver(b *testing.B) {
    74  
    75  	srsSize := 1 << 15
    76  	polySize := 1 << 14
    77  
    78  	kzgSrs, _ := kzg.NewSRS(uint64(srsSize), big.NewInt(13))
    79  	a := make([]fr.Element, polySize)
    80  	c := make([]fr.Element, polySize)
    81  
    82  	for i := 0; i < polySize; i++ {
    83  		a[i].SetUint64(uint64(i))
    84  	}
    85  	for i := 0; i < polySize; i++ {
    86  		c[i].Set(&a[(5*i)%(polySize)])
    87  	}
    88  
    89  	b.ResetTimer()
    90  	for i := 0; i < b.N; i++ {
    91  		Prove(kzgSrs.Pk, a, c)
    92  	}
    93  
    94  }