diff --git a/accumulator/merkletree/readers.go b/accumulator/merkletree/readers.go index 84be3be63c..ca444fd00c 100644 --- a/accumulator/merkletree/readers.go +++ b/accumulator/merkletree/readers.go @@ -1,4 +1,21 @@ -// from https://gitlab.com/NebulousLabs/merkletree +// Original Copyright (c) 2015 Nebulous +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. package merkletree diff --git a/accumulator/merkletree/tree.go b/accumulator/merkletree/tree.go index be3619bfa0..86e693a69e 100644 --- a/accumulator/merkletree/tree.go +++ b/accumulator/merkletree/tree.go @@ -1,5 +1,25 @@ -// from https://gitlab.com/NebulousLabs/merkletree - +// Original Copyright (c) 2015 Nebulous +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +// Package merkletree provides Merkle tree and proof following RFC 6962. +// +// From https://gitlab.com/NebulousLabs/merkletree package merkletree import ( diff --git a/accumulator/merkletree/verify.go b/accumulator/merkletree/verify.go index 122296722d..7c4b8392a5 100644 --- a/accumulator/merkletree/verify.go +++ b/accumulator/merkletree/verify.go @@ -1,4 +1,21 @@ -// from https://gitlab.com/NebulousLabs/merkletree +// Original Copyright (c) 2015 Nebulous +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. package merkletree diff --git a/ecc/bls12-377/doc.go b/ecc/bls12-377/doc.go new file mode 100644 index 0000000000..562982cc7e --- /dev/null +++ b/ecc/bls12-377/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package bls12377 efficient elliptic curve and pairing implementation for bls12-377. +package bls12377 diff --git a/ecc/bls12-377/fp/doc.go b/ecc/bls12-377/fp/doc.go new file mode 100644 index 0000000000..d14a2fc3d2 --- /dev/null +++ b/ecc/bls12-377/fp/doc.go @@ -0,0 +1,43 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package fp contains field arithmetic operations for modulus = 0x1ae3a4...000001. +// +// The API is similar to math/big (big.Int), but the operations are significantly faster (up to 20x for the modular multiplication on amd64, see also https://hackmd.io/@zkteam/modular_multiplication) +// +// The modulus is hardcoded in all the operations. +// +// Field elements are represented as an array, and assumed to be in Montgomery form in all methods: +// type Element [6]uint64 +// +// Example API signature +// // Mul z = x * y mod q +// func (z *Element) Mul(x, y *Element) *Element +// +// and can be used like so: +// var a, b Element +// a.SetUint64(2) +// b.SetString("984896738") +// a.Mul(a, b) +// a.Sub(a, a) +// .Add(a, b) +// .Inv(a) +// b.Exp(b, new(big.Int).SetUint64(42)) +// +// Modulus +// 0x1ae3a4617c510eac63b05c06ca1493b1a22d9f300f5138f1ef3622fba094800170b5d44300000008508c00000000001 // base 16 +// 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177 // base 10 +package fp diff --git a/ecc/bls12-377/fp/element.go b/ecc/bls12-377/fp/element.go index cc6d06d268..914877304b 100644 --- a/ecc/bls12-377/fp/element.go +++ b/ecc/bls12-377/fp/element.go @@ -14,7 +14,6 @@ // Code generated by consensys/gnark-crypto DO NOT EDIT -// Package fp contains field arithmetic operations for modulus 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177 package fp // /!\ WARNING /!\ diff --git a/ecc/bls12-377/fr/doc.go b/ecc/bls12-377/fr/doc.go new file mode 100644 index 0000000000..06d4199338 --- /dev/null +++ b/ecc/bls12-377/fr/doc.go @@ -0,0 +1,43 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package fr contains field arithmetic operations for modulus = 0x12ab65...000001. +// +// The API is similar to math/big (big.Int), but the operations are significantly faster (up to 20x for the modular multiplication on amd64, see also https://hackmd.io/@zkteam/modular_multiplication) +// +// The modulus is hardcoded in all the operations. +// +// Field elements are represented as an array, and assumed to be in Montgomery form in all methods: +// type Element [4]uint64 +// +// Example API signature +// // Mul z = x * y mod q +// func (z *Element) Mul(x, y *Element) *Element +// +// and can be used like so: +// var a, b Element +// a.SetUint64(2) +// b.SetString("984896738") +// a.Mul(a, b) +// a.Sub(a, a) +// .Add(a, b) +// .Inv(a) +// b.Exp(b, new(big.Int).SetUint64(42)) +// +// Modulus +// 0x12ab655e9a2ca55660b44d1e5c37b00159aa76fed00000010a11800000000001 // base 16 +// 8444461749428370424248824938781546531375899335154063827935233455917409239041 // base 10 +package fr diff --git a/ecc/bls12-377/fr/element.go b/ecc/bls12-377/fr/element.go index 19f0317619..e60ba9e0af 100644 --- a/ecc/bls12-377/fr/element.go +++ b/ecc/bls12-377/fr/element.go @@ -14,7 +14,6 @@ // Code generated by consensys/gnark-crypto DO NOT EDIT -// Package fr contains field arithmetic operations for modulus 8444461749428370424248824938781546531375899335154063827935233455917409239041 package fr // /!\ WARNING /!\ diff --git a/ecc/bls12-377/fr/fft/doc.go b/ecc/bls12-377/fr/fft/doc.go new file mode 100644 index 0000000000..3c35170e8d --- /dev/null +++ b/ecc/bls12-377/fr/fft/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package fft provides in-place discrete Fourier transform. +package fft diff --git a/ecc/bls12-377/fr/mimc/doc.go b/ecc/bls12-377/fr/mimc/doc.go new file mode 100644 index 0000000000..497bd40a97 --- /dev/null +++ b/ecc/bls12-377/fr/mimc/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package mimc provides MiMC hash function using Miyaguchi–Preneel construction. +package mimc diff --git a/ecc/bls12-377/fr/polynomial/doc.go b/ecc/bls12-377/fr/polynomial/doc.go new file mode 100644 index 0000000000..83479b058b --- /dev/null +++ b/ecc/bls12-377/fr/polynomial/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package polynomial provides polynomial methods and commitment schemes. +package polynomial diff --git a/ecc/bls12-377/fr/polynomial/mockcommitment/doc.go b/ecc/bls12-377/fr/polynomial/mockcommitment/doc.go new file mode 100644 index 0000000000..5473a4d437 --- /dev/null +++ b/ecc/bls12-377/fr/polynomial/mockcommitment/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package mockcommitment provides a mock commitment scheme, for development and test purposes. +package mockcommitment diff --git a/ecc/bls12-377/marshal.go b/ecc/bls12-377/marshal.go index 0850b5e413..0b2946e0c1 100644 --- a/ecc/bls12-377/marshal.go +++ b/ecc/bls12-377/marshal.go @@ -14,7 +14,6 @@ // Code generated by consensys/gnark-crypto DO NOT EDIT -// Package bls12377 provides efficient elliptic curve and pairing implementation for bls12-377 package bls12377 import ( diff --git a/ecc/bls12-377/twistededwards/doc.go b/ecc/bls12-377/twistededwards/doc.go new file mode 100644 index 0000000000..ed25f6a630 --- /dev/null +++ b/ecc/bls12-377/twistededwards/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package twistededwards provides bls12-377's twisted edwards "companion curve" defined on fr. +package twistededwards diff --git a/ecc/bls12-377/twistededwards/eddsa/doc.go b/ecc/bls12-377/twistededwards/eddsa/doc.go new file mode 100644 index 0000000000..568432e874 --- /dev/null +++ b/ecc/bls12-377/twistededwards/eddsa/doc.go @@ -0,0 +1,22 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package eddsa provides EdDSA signature scheme on bls12-377's twisted edwards curve. +// +// See also +// +// https://en.wikipedia.org/wiki/EdDSA +package eddsa diff --git a/ecc/bls12-377/twistededwards/eddsa/eddsa_test.go b/ecc/bls12-377/twistededwards/eddsa/eddsa_test.go index 646e6d94fa..6eb3c73082 100644 --- a/ecc/bls12-377/twistededwards/eddsa/eddsa_test.go +++ b/ecc/bls12-377/twistededwards/eddsa/eddsa_test.go @@ -21,11 +21,40 @@ import ( "math/rand" "testing" + crand "crypto/rand" + + "fmt" + "github.com/consensys/gnark-crypto/ecc/bls12-377/fr" "github.com/consensys/gnark-crypto/hash" "github.com/consensys/gnark-crypto/signature" ) +func Example() { + // instantiate hash function + hFunc := hash.MIMC_BLS12_377.New("seed") + + // create a eddsa key pair + privateKey, _ := signature.EDDSA_BLS12_377.New(crand.Reader) + publicKey := privateKey.Public() + + // note that the message is on 4 bytes + msg := []byte{0xde, 0xad, 0xf0, 0x0d} + + // sign the message + signature, _ := privateKey.Sign(msg, hFunc) + + // verifies signature + isValid, _ := publicKey.Verify(signature, msg, hFunc) + if !isValid { + fmt.Println("1. invalid signature") + } else { + fmt.Println("1. valid signature") + } + + // Output: 1. valid signature +} + func TestSerialization(t *testing.T) { src := rand.NewSource(0) diff --git a/ecc/bls12-381/doc.go b/ecc/bls12-381/doc.go new file mode 100644 index 0000000000..350ffacced --- /dev/null +++ b/ecc/bls12-381/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package bls12381 efficient elliptic curve and pairing implementation for bls12-381. +package bls12381 diff --git a/ecc/bls12-381/fp/doc.go b/ecc/bls12-381/fp/doc.go new file mode 100644 index 0000000000..57f14285c3 --- /dev/null +++ b/ecc/bls12-381/fp/doc.go @@ -0,0 +1,43 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package fp contains field arithmetic operations for modulus = 0x1a0111...ffaaab. +// +// The API is similar to math/big (big.Int), but the operations are significantly faster (up to 20x for the modular multiplication on amd64, see also https://hackmd.io/@zkteam/modular_multiplication) +// +// The modulus is hardcoded in all the operations. +// +// Field elements are represented as an array, and assumed to be in Montgomery form in all methods: +// type Element [6]uint64 +// +// Example API signature +// // Mul z = x * y mod q +// func (z *Element) Mul(x, y *Element) *Element +// +// and can be used like so: +// var a, b Element +// a.SetUint64(2) +// b.SetString("984896738") +// a.Mul(a, b) +// a.Sub(a, a) +// .Add(a, b) +// .Inv(a) +// b.Exp(b, new(big.Int).SetUint64(42)) +// +// Modulus +// 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab // base 16 +// 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787 // base 10 +package fp diff --git a/ecc/bls12-381/fp/element.go b/ecc/bls12-381/fp/element.go index 46fdcda4dd..1abeac6e3b 100644 --- a/ecc/bls12-381/fp/element.go +++ b/ecc/bls12-381/fp/element.go @@ -14,7 +14,6 @@ // Code generated by consensys/gnark-crypto DO NOT EDIT -// Package fp contains field arithmetic operations for modulus 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787 package fp // /!\ WARNING /!\ diff --git a/ecc/bls12-381/fr/doc.go b/ecc/bls12-381/fr/doc.go new file mode 100644 index 0000000000..912e69b2f7 --- /dev/null +++ b/ecc/bls12-381/fr/doc.go @@ -0,0 +1,43 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package fr contains field arithmetic operations for modulus = 0x73eda7...000001. +// +// The API is similar to math/big (big.Int), but the operations are significantly faster (up to 20x for the modular multiplication on amd64, see also https://hackmd.io/@zkteam/modular_multiplication) +// +// The modulus is hardcoded in all the operations. +// +// Field elements are represented as an array, and assumed to be in Montgomery form in all methods: +// type Element [4]uint64 +// +// Example API signature +// // Mul z = x * y mod q +// func (z *Element) Mul(x, y *Element) *Element +// +// and can be used like so: +// var a, b Element +// a.SetUint64(2) +// b.SetString("984896738") +// a.Mul(a, b) +// a.Sub(a, a) +// .Add(a, b) +// .Inv(a) +// b.Exp(b, new(big.Int).SetUint64(42)) +// +// Modulus +// 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001 // base 16 +// 52435875175126190479447740508185965837690552500527637822603658699938581184513 // base 10 +package fr diff --git a/ecc/bls12-381/fr/element.go b/ecc/bls12-381/fr/element.go index 25022cf6e7..ae6981d5be 100644 --- a/ecc/bls12-381/fr/element.go +++ b/ecc/bls12-381/fr/element.go @@ -14,7 +14,6 @@ // Code generated by consensys/gnark-crypto DO NOT EDIT -// Package fr contains field arithmetic operations for modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 package fr // /!\ WARNING /!\ diff --git a/ecc/bls12-381/fr/fft/doc.go b/ecc/bls12-381/fr/fft/doc.go new file mode 100644 index 0000000000..3c35170e8d --- /dev/null +++ b/ecc/bls12-381/fr/fft/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package fft provides in-place discrete Fourier transform. +package fft diff --git a/ecc/bls12-381/fr/mimc/doc.go b/ecc/bls12-381/fr/mimc/doc.go new file mode 100644 index 0000000000..497bd40a97 --- /dev/null +++ b/ecc/bls12-381/fr/mimc/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package mimc provides MiMC hash function using Miyaguchi–Preneel construction. +package mimc diff --git a/ecc/bls12-381/fr/polynomial/doc.go b/ecc/bls12-381/fr/polynomial/doc.go new file mode 100644 index 0000000000..83479b058b --- /dev/null +++ b/ecc/bls12-381/fr/polynomial/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package polynomial provides polynomial methods and commitment schemes. +package polynomial diff --git a/ecc/bls12-381/fr/polynomial/mockcommitment/doc.go b/ecc/bls12-381/fr/polynomial/mockcommitment/doc.go new file mode 100644 index 0000000000..5473a4d437 --- /dev/null +++ b/ecc/bls12-381/fr/polynomial/mockcommitment/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package mockcommitment provides a mock commitment scheme, for development and test purposes. +package mockcommitment diff --git a/ecc/bls12-381/marshal.go b/ecc/bls12-381/marshal.go index 2d65c042f1..e823c3f69c 100644 --- a/ecc/bls12-381/marshal.go +++ b/ecc/bls12-381/marshal.go @@ -14,7 +14,6 @@ // Code generated by consensys/gnark-crypto DO NOT EDIT -// Package bls12381 provides efficient elliptic curve and pairing implementation for bls12-381 package bls12381 import ( diff --git a/ecc/bls12-381/twistededwards/doc.go b/ecc/bls12-381/twistededwards/doc.go new file mode 100644 index 0000000000..a6afbcbb73 --- /dev/null +++ b/ecc/bls12-381/twistededwards/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package twistededwards provides bls12-381's twisted edwards "companion curve" defined on fr. +package twistededwards diff --git a/ecc/bls12-381/twistededwards/eddsa/doc.go b/ecc/bls12-381/twistededwards/eddsa/doc.go new file mode 100644 index 0000000000..fb47126331 --- /dev/null +++ b/ecc/bls12-381/twistededwards/eddsa/doc.go @@ -0,0 +1,22 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package eddsa provides EdDSA signature scheme on bls12-381's twisted edwards curve. +// +// See also +// +// https://en.wikipedia.org/wiki/EdDSA +package eddsa diff --git a/ecc/bls12-381/twistededwards/eddsa/eddsa_test.go b/ecc/bls12-381/twistededwards/eddsa/eddsa_test.go index 9f60d80b95..480cee2b55 100644 --- a/ecc/bls12-381/twistededwards/eddsa/eddsa_test.go +++ b/ecc/bls12-381/twistededwards/eddsa/eddsa_test.go @@ -21,11 +21,40 @@ import ( "math/rand" "testing" + crand "crypto/rand" + + "fmt" + "github.com/consensys/gnark-crypto/ecc/bls12-381/fr" "github.com/consensys/gnark-crypto/hash" "github.com/consensys/gnark-crypto/signature" ) +func Example() { + // instantiate hash function + hFunc := hash.MIMC_BLS12_381.New("seed") + + // create a eddsa key pair + privateKey, _ := signature.EDDSA_BLS12_381.New(crand.Reader) + publicKey := privateKey.Public() + + // note that the message is on 4 bytes + msg := []byte{0xde, 0xad, 0xf0, 0x0d} + + // sign the message + signature, _ := privateKey.Sign(msg, hFunc) + + // verifies signature + isValid, _ := publicKey.Verify(signature, msg, hFunc) + if !isValid { + fmt.Println("1. invalid signature") + } else { + fmt.Println("1. valid signature") + } + + // Output: 1. valid signature +} + func TestSerialization(t *testing.T) { src := rand.NewSource(0) diff --git a/ecc/bn254/doc.go b/ecc/bn254/doc.go new file mode 100644 index 0000000000..df3457ba2a --- /dev/null +++ b/ecc/bn254/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package bn254 efficient elliptic curve and pairing implementation for bn254. +package bn254 diff --git a/ecc/bn254/fp/doc.go b/ecc/bn254/fp/doc.go new file mode 100644 index 0000000000..806095a1d0 --- /dev/null +++ b/ecc/bn254/fp/doc.go @@ -0,0 +1,43 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package fp contains field arithmetic operations for modulus = 0x30644e...7cfd47. +// +// The API is similar to math/big (big.Int), but the operations are significantly faster (up to 20x for the modular multiplication on amd64, see also https://hackmd.io/@zkteam/modular_multiplication) +// +// The modulus is hardcoded in all the operations. +// +// Field elements are represented as an array, and assumed to be in Montgomery form in all methods: +// type Element [4]uint64 +// +// Example API signature +// // Mul z = x * y mod q +// func (z *Element) Mul(x, y *Element) *Element +// +// and can be used like so: +// var a, b Element +// a.SetUint64(2) +// b.SetString("984896738") +// a.Mul(a, b) +// a.Sub(a, a) +// .Add(a, b) +// .Inv(a) +// b.Exp(b, new(big.Int).SetUint64(42)) +// +// Modulus +// 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47 // base 16 +// 21888242871839275222246405745257275088696311157297823662689037894645226208583 // base 10 +package fp diff --git a/ecc/bn254/fp/element.go b/ecc/bn254/fp/element.go index 1fc30c09fc..f40fe0e51e 100644 --- a/ecc/bn254/fp/element.go +++ b/ecc/bn254/fp/element.go @@ -14,7 +14,6 @@ // Code generated by consensys/gnark-crypto DO NOT EDIT -// Package fp contains field arithmetic operations for modulus 21888242871839275222246405745257275088696311157297823662689037894645226208583 package fp // /!\ WARNING /!\ diff --git a/ecc/bn254/fr/doc.go b/ecc/bn254/fr/doc.go new file mode 100644 index 0000000000..e726bd9bc6 --- /dev/null +++ b/ecc/bn254/fr/doc.go @@ -0,0 +1,43 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package fr contains field arithmetic operations for modulus = 0x30644e...000001. +// +// The API is similar to math/big (big.Int), but the operations are significantly faster (up to 20x for the modular multiplication on amd64, see also https://hackmd.io/@zkteam/modular_multiplication) +// +// The modulus is hardcoded in all the operations. +// +// Field elements are represented as an array, and assumed to be in Montgomery form in all methods: +// type Element [4]uint64 +// +// Example API signature +// // Mul z = x * y mod q +// func (z *Element) Mul(x, y *Element) *Element +// +// and can be used like so: +// var a, b Element +// a.SetUint64(2) +// b.SetString("984896738") +// a.Mul(a, b) +// a.Sub(a, a) +// .Add(a, b) +// .Inv(a) +// b.Exp(b, new(big.Int).SetUint64(42)) +// +// Modulus +// 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001 // base 16 +// 21888242871839275222246405745257275088548364400416034343698204186575808495617 // base 10 +package fr diff --git a/ecc/bn254/fr/element.go b/ecc/bn254/fr/element.go index f4b975fca4..9ca91337f3 100644 --- a/ecc/bn254/fr/element.go +++ b/ecc/bn254/fr/element.go @@ -14,7 +14,6 @@ // Code generated by consensys/gnark-crypto DO NOT EDIT -// Package fr contains field arithmetic operations for modulus 21888242871839275222246405745257275088548364400416034343698204186575808495617 package fr // /!\ WARNING /!\ diff --git a/ecc/bn254/fr/fft/doc.go b/ecc/bn254/fr/fft/doc.go new file mode 100644 index 0000000000..3c35170e8d --- /dev/null +++ b/ecc/bn254/fr/fft/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package fft provides in-place discrete Fourier transform. +package fft diff --git a/ecc/bn254/fr/mimc/doc.go b/ecc/bn254/fr/mimc/doc.go new file mode 100644 index 0000000000..497bd40a97 --- /dev/null +++ b/ecc/bn254/fr/mimc/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package mimc provides MiMC hash function using Miyaguchi–Preneel construction. +package mimc diff --git a/ecc/bn254/fr/polynomial/doc.go b/ecc/bn254/fr/polynomial/doc.go new file mode 100644 index 0000000000..83479b058b --- /dev/null +++ b/ecc/bn254/fr/polynomial/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package polynomial provides polynomial methods and commitment schemes. +package polynomial diff --git a/ecc/bn254/fr/polynomial/mockcommitment/doc.go b/ecc/bn254/fr/polynomial/mockcommitment/doc.go new file mode 100644 index 0000000000..5473a4d437 --- /dev/null +++ b/ecc/bn254/fr/polynomial/mockcommitment/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package mockcommitment provides a mock commitment scheme, for development and test purposes. +package mockcommitment diff --git a/ecc/bn254/marshal.go b/ecc/bn254/marshal.go index 68a0b40523..30386fc5b2 100644 --- a/ecc/bn254/marshal.go +++ b/ecc/bn254/marshal.go @@ -14,7 +14,6 @@ // Code generated by consensys/gnark-crypto DO NOT EDIT -// Package bn254 provides efficient elliptic curve and pairing implementation for bn254 package bn254 import ( diff --git a/ecc/bn254/twistededwards/doc.go b/ecc/bn254/twistededwards/doc.go new file mode 100644 index 0000000000..eced0ef56c --- /dev/null +++ b/ecc/bn254/twistededwards/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package twistededwards provides bn254's twisted edwards "companion curve" defined on fr. +package twistededwards diff --git a/ecc/bn254/twistededwards/eddsa/doc.go b/ecc/bn254/twistededwards/eddsa/doc.go new file mode 100644 index 0000000000..ca822aea81 --- /dev/null +++ b/ecc/bn254/twistededwards/eddsa/doc.go @@ -0,0 +1,22 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package eddsa provides EdDSA signature scheme on bn254's twisted edwards curve. +// +// See also +// +// https://en.wikipedia.org/wiki/EdDSA +package eddsa diff --git a/ecc/bn254/twistededwards/eddsa/eddsa_test.go b/ecc/bn254/twistededwards/eddsa/eddsa_test.go index c04c683c72..d07a182c0b 100644 --- a/ecc/bn254/twistededwards/eddsa/eddsa_test.go +++ b/ecc/bn254/twistededwards/eddsa/eddsa_test.go @@ -21,11 +21,40 @@ import ( "math/rand" "testing" + crand "crypto/rand" + + "fmt" + "github.com/consensys/gnark-crypto/ecc/bn254/fr" "github.com/consensys/gnark-crypto/hash" "github.com/consensys/gnark-crypto/signature" ) +func Example() { + // instantiate hash function + hFunc := hash.MIMC_BN254.New("seed") + + // create a eddsa key pair + privateKey, _ := signature.EDDSA_BN254.New(crand.Reader) + publicKey := privateKey.Public() + + // note that the message is on 4 bytes + msg := []byte{0xde, 0xad, 0xf0, 0x0d} + + // sign the message + signature, _ := privateKey.Sign(msg, hFunc) + + // verifies signature + isValid, _ := publicKey.Verify(signature, msg, hFunc) + if !isValid { + fmt.Println("1. invalid signature") + } else { + fmt.Println("1. valid signature") + } + + // Output: 1. valid signature +} + func TestSerialization(t *testing.T) { src := rand.NewSource(0) diff --git a/ecc/bw6-761/doc.go b/ecc/bw6-761/doc.go new file mode 100644 index 0000000000..2501654184 --- /dev/null +++ b/ecc/bw6-761/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package bw6761 efficient elliptic curve and pairing implementation for bw6-761. +package bw6761 diff --git a/ecc/bw6-761/fp/doc.go b/ecc/bw6-761/fp/doc.go new file mode 100644 index 0000000000..c4ac5bf0ef --- /dev/null +++ b/ecc/bw6-761/fp/doc.go @@ -0,0 +1,43 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package fp contains field arithmetic operations for modulus = 0x122e82...00008b. +// +// The API is similar to math/big (big.Int), but the operations are significantly faster (up to 20x for the modular multiplication on amd64, see also https://hackmd.io/@zkteam/modular_multiplication) +// +// The modulus is hardcoded in all the operations. +// +// Field elements are represented as an array, and assumed to be in Montgomery form in all methods: +// type Element [12]uint64 +// +// Example API signature +// // Mul z = x * y mod q +// func (z *Element) Mul(x, y *Element) *Element +// +// and can be used like so: +// var a, b Element +// a.SetUint64(2) +// b.SetString("984896738") +// a.Mul(a, b) +// a.Sub(a, a) +// .Add(a, b) +// .Inv(a) +// b.Exp(b, new(big.Int).SetUint64(42)) +// +// Modulus +// 0x122e824fb83ce0ad187c94004faff3eb926186a81d14688528275ef8087be41707ba638e584e91903cebaff25b423048689c8ed12f9fd9071dcd3dc73ebff2e98a116c25667a8f8160cf8aeeaf0a437e6913e6870000082f49d00000000008b // base 16 +// 6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068299 // base 10 +package fp diff --git a/ecc/bw6-761/fp/element.go b/ecc/bw6-761/fp/element.go index 1552725870..00d8019453 100644 --- a/ecc/bw6-761/fp/element.go +++ b/ecc/bw6-761/fp/element.go @@ -14,7 +14,6 @@ // Code generated by consensys/gnark-crypto DO NOT EDIT -// Package fp contains field arithmetic operations for modulus 6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068299 package fp // /!\ WARNING /!\ diff --git a/ecc/bw6-761/fr/doc.go b/ecc/bw6-761/fr/doc.go new file mode 100644 index 0000000000..0dc4b859bc --- /dev/null +++ b/ecc/bw6-761/fr/doc.go @@ -0,0 +1,43 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package fr contains field arithmetic operations for modulus = 0x1ae3a4...000001. +// +// The API is similar to math/big (big.Int), but the operations are significantly faster (up to 20x for the modular multiplication on amd64, see also https://hackmd.io/@zkteam/modular_multiplication) +// +// The modulus is hardcoded in all the operations. +// +// Field elements are represented as an array, and assumed to be in Montgomery form in all methods: +// type Element [6]uint64 +// +// Example API signature +// // Mul z = x * y mod q +// func (z *Element) Mul(x, y *Element) *Element +// +// and can be used like so: +// var a, b Element +// a.SetUint64(2) +// b.SetString("984896738") +// a.Mul(a, b) +// a.Sub(a, a) +// .Add(a, b) +// .Inv(a) +// b.Exp(b, new(big.Int).SetUint64(42)) +// +// Modulus +// 0x1ae3a4617c510eac63b05c06ca1493b1a22d9f300f5138f1ef3622fba094800170b5d44300000008508c00000000001 // base 16 +// 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177 // base 10 +package fr diff --git a/ecc/bw6-761/fr/element.go b/ecc/bw6-761/fr/element.go index f5f8848ef7..c8e743fcae 100644 --- a/ecc/bw6-761/fr/element.go +++ b/ecc/bw6-761/fr/element.go @@ -14,7 +14,6 @@ // Code generated by consensys/gnark-crypto DO NOT EDIT -// Package fr contains field arithmetic operations for modulus 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177 package fr // /!\ WARNING /!\ diff --git a/ecc/bw6-761/fr/fft/doc.go b/ecc/bw6-761/fr/fft/doc.go new file mode 100644 index 0000000000..3c35170e8d --- /dev/null +++ b/ecc/bw6-761/fr/fft/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package fft provides in-place discrete Fourier transform. +package fft diff --git a/ecc/bw6-761/fr/mimc/doc.go b/ecc/bw6-761/fr/mimc/doc.go new file mode 100644 index 0000000000..497bd40a97 --- /dev/null +++ b/ecc/bw6-761/fr/mimc/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package mimc provides MiMC hash function using Miyaguchi–Preneel construction. +package mimc diff --git a/ecc/bw6-761/fr/polynomial/doc.go b/ecc/bw6-761/fr/polynomial/doc.go new file mode 100644 index 0000000000..83479b058b --- /dev/null +++ b/ecc/bw6-761/fr/polynomial/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package polynomial provides polynomial methods and commitment schemes. +package polynomial diff --git a/ecc/bw6-761/fr/polynomial/mockcommitment/doc.go b/ecc/bw6-761/fr/polynomial/mockcommitment/doc.go new file mode 100644 index 0000000000..5473a4d437 --- /dev/null +++ b/ecc/bw6-761/fr/polynomial/mockcommitment/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package mockcommitment provides a mock commitment scheme, for development and test purposes. +package mockcommitment diff --git a/ecc/bw6-761/marshal.go b/ecc/bw6-761/marshal.go index 202b29a560..3e7f996535 100644 --- a/ecc/bw6-761/marshal.go +++ b/ecc/bw6-761/marshal.go @@ -14,7 +14,6 @@ // Code generated by consensys/gnark-crypto DO NOT EDIT -// Package bw6761 provides efficient elliptic curve and pairing implementation for bw6-761 package bw6761 import ( diff --git a/ecc/bw6-761/twistededwards/doc.go b/ecc/bw6-761/twistededwards/doc.go new file mode 100644 index 0000000000..c615898fb3 --- /dev/null +++ b/ecc/bw6-761/twistededwards/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package twistededwards provides bw6-761's twisted edwards "companion curve" defined on fr. +package twistededwards diff --git a/ecc/bw6-761/twistededwards/eddsa/doc.go b/ecc/bw6-761/twistededwards/eddsa/doc.go new file mode 100644 index 0000000000..fa989472fd --- /dev/null +++ b/ecc/bw6-761/twistededwards/eddsa/doc.go @@ -0,0 +1,22 @@ +// Copyright 2020 ConsenSys Software Inc. +// +// 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 consensys/gnark-crypto DO NOT EDIT + +// Package eddsa provides EdDSA signature scheme on bw6-761's twisted edwards curve. +// +// See also +// +// https://en.wikipedia.org/wiki/EdDSA +package eddsa diff --git a/ecc/bw6-761/twistededwards/eddsa/eddsa_test.go b/ecc/bw6-761/twistededwards/eddsa/eddsa_test.go index ff65a7ad68..038d9a16ff 100644 --- a/ecc/bw6-761/twistededwards/eddsa/eddsa_test.go +++ b/ecc/bw6-761/twistededwards/eddsa/eddsa_test.go @@ -21,11 +21,40 @@ import ( "math/rand" "testing" + crand "crypto/rand" + + "fmt" + "github.com/consensys/gnark-crypto/ecc/bw6-761/fr" "github.com/consensys/gnark-crypto/hash" "github.com/consensys/gnark-crypto/signature" ) +func Example() { + // instantiate hash function + hFunc := hash.MIMC_BW6_761.New("seed") + + // create a eddsa key pair + privateKey, _ := signature.EDDSA_BW6_761.New(crand.Reader) + publicKey := privateKey.Public() + + // note that the message is on 4 bytes + msg := []byte{0xde, 0xad, 0xf0, 0x0d} + + // sign the message + signature, _ := privateKey.Sign(msg, hFunc) + + // verifies signature + isValid, _ := publicKey.Verify(signature, msg, hFunc) + if !isValid { + fmt.Println("1. invalid signature") + } else { + fmt.Println("1. valid signature") + } + + // Output: 1. valid signature +} + func TestSerialization(t *testing.T) { src := rand.NewSource(0) diff --git a/ecc/ecc.go b/ecc/ecc.go index 46b4845005..dfbb79886f 100644 --- a/ecc/ecc.go +++ b/ecc/ecc.go @@ -14,8 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package ecc is an elliptic curve (+pairing) library. -// Provides implementation for bls12-381, bls12-377, bn254, bw6-761 and their twisted edwards "companion curves" +// Package ecc provides bls12-381, bls12-377, bn254 and bw6-761 elliptic curves implementation (+pairing). +// +// Also +// +// * Multi exponentiation +// * FFT +// * Polynomial commitment schemes +// * MiMC +// * twisted edwards "companion curves" +// * EdDSA (on the "companion" twisted edwards curves) package ecc import "sync" diff --git a/field/asm/amd64/build.go b/field/asm/amd64/build.go index 70448df77c..0e2a3f8d13 100644 --- a/field/asm/amd64/build.go +++ b/field/asm/amd64/build.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package amd64 contains syntactic sugar to generate amd64 assembly code in goff +// Package amd64 contains syntactic sugar to generate amd64 assembly code package amd64 import ( diff --git a/field/field.go b/field/field.go index 732181d115..b5165acfde 100644 --- a/field/field.go +++ b/field/field.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Package field provides Golang code generation for efficient field arithmetic operations. package field import ( @@ -24,10 +25,12 @@ var ( errParseModulus = errors.New("can't parse modulus") ) +// Field precomputed values used in template for code generation of field element APIs type Field struct { PackageName string ElementName string Modulus string + ModulusHex string NbWords int NbBits int NbWordsLastIndex int @@ -55,8 +58,9 @@ type Field struct { NonResidue []uint64 // (montgomery form) } -// ------------------------------------------------------------------------------------------------- -// Field data precompute functions +// NewField returns a data structure with needed informations to generate apis for field element +// +// See field/generator package func NewField(packageName, elementName, modulus string) (*Field, error) { // parse modulus var bModulus big.Int @@ -69,6 +73,7 @@ func NewField(packageName, elementName, modulus string) (*Field, error) { PackageName: packageName, ElementName: elementName, Modulus: modulus, + ModulusHex: bModulus.Text(16), } // pre compute field constants F.NbBits = bModulus.BitLen() diff --git a/field/generator/generator.go b/field/generator/generator.go index 2c9c38fb19..a460c321cf 100644 --- a/field/generator/generator.go +++ b/field/generator/generator.go @@ -19,6 +19,11 @@ import ( // base field. in Go 1.16, can embed the template in the binary, and use same pattern than gnark-crypto/internal // GenerateFF will generate go (and .s) files in outputDir for modulus (in base 10) +// +// Example usage +// +// fp, _ = field.NewField("fp", "Element", fpModulus") +// generator.GenerateFF(fp, filepath.Join(baseDir, "fp")) func GenerateFF(F *field.Field, outputDir string) error { // source file templates src := []string{ @@ -58,21 +63,20 @@ func GenerateFF(F *field.Field, outputDir string) error { bavard.Apache2("ConsenSys Software Inc.", 2020), bavard.Package(F.PackageName), bavard.GeneratedBy("consensys/gnark-crypto"), - bavard.Funcs(template.FuncMap{"toTitle": strings.Title}), + bavard.Funcs(template.FuncMap{"toTitle": strings.Title, "shorten": shorten}), } - optsWithPackageDoc := append(bavardOpts, bavard.Package(F.PackageName, "contains field arithmetic operations for modulus "+F.Modulus)) // generate source file - if err := bavard.Generate(pathSrc, src, F, optsWithPackageDoc...); err != nil { + if err := bavard.GenerateFromString(pathSrc, src, F, bavardOpts...); err != nil { return err } // generate arithmetics source file - if err := bavard.Generate(pathSrcArith, []string{element.Arith}, F, bavardOpts...); err != nil { + if err := bavard.GenerateFromString(pathSrcArith, []string{element.Arith}, F, bavardOpts...); err != nil { return err } // generate test file - if err := bavard.Generate(pathTest, tst, F, bavardOpts...); err != nil { + if err := bavard.GenerateFromString(pathTest, tst, F, bavardOpts...); err != nil { return err } @@ -163,7 +167,7 @@ func GenerateFF(F *field.Field, outputDir string) error { element.OpsAMD64, } pathSrc := filepath.Join(outputDir, eName+"_ops_amd64.go") - if err := bavard.Generate(pathSrc, src, F, bavardOpts...); err != nil { + if err := bavard.GenerateFromString(pathSrc, src, F, bavardOpts...); err != nil { return err } } @@ -182,7 +186,18 @@ func GenerateFF(F *field.Field, outputDir string) error { if F.ASM { bavardOptsCpy = append(bavardOptsCpy, bavard.BuildTag("!amd64")) } - if err := bavard.Generate(pathSrc, src, F, bavardOptsCpy...); err != nil { + if err := bavard.GenerateFromString(pathSrc, src, F, bavardOptsCpy...); err != nil { + return err + } + } + + { + // generate doc.go + src := []string{ + element.Doc, + } + pathSrc := filepath.Join(outputDir, "doc.go") + if err := bavard.GenerateFromString(pathSrc, src, F, bavardOpts...); err != nil { return err } } @@ -196,7 +211,7 @@ func GenerateFF(F *field.Field, outputDir string) error { bavardOptsCpy := make([]func(*bavard.Bavard) error, len(bavardOpts)) copy(bavardOptsCpy, bavardOpts) bavardOptsCpy = append(bavardOptsCpy, bavard.BuildTag("!noadx")) - if err := bavard.Generate(pathSrc, src, F, bavardOptsCpy...); err != nil { + if err := bavard.GenerateFromString(pathSrc, src, F, bavardOptsCpy...); err != nil { return err } } @@ -209,7 +224,7 @@ func GenerateFF(F *field.Field, outputDir string) error { bavardOptsCpy := make([]func(*bavard.Bavard) error, len(bavardOpts)) copy(bavardOptsCpy, bavardOpts) bavardOptsCpy = append(bavardOptsCpy, bavard.BuildTag("noadx")) - if err := bavard.Generate(pathSrc, src, F, bavardOptsCpy...); err != nil { + if err := bavard.GenerateFromString(pathSrc, src, F, bavardOptsCpy...); err != nil { return err } } @@ -224,3 +239,11 @@ func GenerateFF(F *field.Field, outputDir string) error { return nil } + +func shorten(input string) string { + const maxLen = 15 + if len(input) > maxLen { + return input[:6] + "..." + input[len(input)-6:] + } + return input +} diff --git a/field/internal/templates/element/doc.go b/field/internal/templates/element/doc.go new file mode 100644 index 0000000000..d5070c4e94 --- /dev/null +++ b/field/internal/templates/element/doc.go @@ -0,0 +1,31 @@ +package element + +const Doc = ` +// Package {{.PackageName}} contains field arithmetic operations for modulus = 0x{{shorten .ModulusHex}}. +// +// The API is similar to math/big (big.Int), but the operations are significantly faster (up to 20x for the modular multiplication on amd64, see also https://hackmd.io/@zkteam/modular_multiplication) +// +// The modulus is hardcoded in all the operations. +// +// Field elements are represented as an array, and assumed to be in Montgomery form in all methods: +// type {{.ElementName}} [{{.NbWords}}]uint64 +// +// Example API signature +// // Mul z = x * y mod q +// func (z *Element) Mul(x, y *Element) *Element +// +// and can be used like so: +// var a, b Element +// a.SetUint64(2) +// b.SetString("984896738") +// a.Mul(a, b) +// a.Sub(a, a) +// .Add(a, b) +// .Inv(a) +// b.Exp(b, new(big.Int).SetUint64(42)) +// +// Modulus +// 0x{{.ModulusHex}} // base 16 +// {{.Modulus}} // base 10 +package {{.PackageName}} +` diff --git a/go.mod b/go.mod index 1197dd86a8..a49d68956d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/consensys/gnark-crypto go 1.16 require ( - github.com/consensys/bavard v0.1.8-0.20210329205436-c3e862ba4e5f + github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572 // indirect github.com/leanovate/gopter v0.2.9 golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 golang.org/x/sys v0.0.0-20210326220804-49726bf1d181 diff --git a/go.sum b/go.sum index 34aef50864..8ca62805d0 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,21 @@ -github.com/consensys/bavard v0.1.8-0.20210329205436-c3e862ba4e5f h1:Smz/coLzPOgl74T1haF8SfqPAkB760cSO59+FyLPzG0= -github.com/consensys/bavard v0.1.8-0.20210329205436-c3e862ba4e5f/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ= +github.com/consensys/bavard v0.1.8-0.20210406025751-9d7732285dc8 h1:crvgEZ8E7gDzugwgsUIz4Clrtg/801QUkq5dhNHD5QY= +github.com/consensys/bavard v0.1.8-0.20210406025751-9d7732285dc8/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ= +github.com/consensys/bavard v0.1.8-0.20210406030959-0667cd328a44 h1:12SY5Wq9ULSWK6RYDmLkjv3/qcVNu4BY4M9wwR3Knpg= +github.com/consensys/bavard v0.1.8-0.20210406030959-0667cd328a44/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ= +github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572 h1:+R8G1+Ftumd0DaveLgMIjrFPcAS4G8MsVXWXiyZL5BY= +github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210326220804-49726bf1d181 h1:64ChN/hjER/taL4YJuA+gpLfIMT+/NFherRZixbxOhg= golang.org/x/sys v0.0.0-20210326220804-49726bf1d181/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/hash/hashes.go b/hash/hashes.go index 2b46e82995..d6ef2f8e16 100644 --- a/hash/hashes.go +++ b/hash/hashes.go @@ -12,10 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package hash gathers the different custom hash functions (which -// are not available in golang's crypto library) built for being -// within a ZKP scheme. The structure of the package is similar to what -// can be found in golang's crypto/ package. +// Package hash provides MiMC hash function defined over curves implemented in gnark-crypto/ecc. +// +// Originally developed and used in a ZKP context. package hash import ( diff --git a/internal/generator/config/bls12-377.go b/internal/generator/config/bls12-377.go index ed2909852f..e33bee3fb3 100644 --- a/internal/generator/config/bls12-377.go +++ b/internal/generator/config/bls12-377.go @@ -2,11 +2,11 @@ package config func init() { Curves = append(Curves, Curve{ - Name: "bls12-377", - Package: "bls12377", - EnumID: "BLS12_377", - FrModulus: "8444461749428370424248824938781546531375899335154063827935233455917409239041", - FpModulus: "258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177", + Name: "bls12-377", + CurvePackage: "bls12377", + EnumID: "BLS12_377", + FrModulus: "8444461749428370424248824938781546531375899335154063827935233455917409239041", + FpModulus: "258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177", G1: Point{ CoordType: "fp.Element", PointName: "g1", diff --git a/internal/generator/config/bls12-381.go b/internal/generator/config/bls12-381.go index 8c4d508abf..689833f183 100644 --- a/internal/generator/config/bls12-381.go +++ b/internal/generator/config/bls12-381.go @@ -2,11 +2,11 @@ package config func init() { Curves = append(Curves, Curve{ - Name: "bls12-381", - Package: "bls12381", - EnumID: "BLS12_381", - FrModulus: "52435875175126190479447740508185965837690552500527637822603658699938581184513", - FpModulus: "4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787", + Name: "bls12-381", + CurvePackage: "bls12381", + EnumID: "BLS12_381", + FrModulus: "52435875175126190479447740508185965837690552500527637822603658699938581184513", + FpModulus: "4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787", G1: Point{ CoordType: "fp.Element", PointName: "g1", diff --git a/internal/generator/config/bn254.go b/internal/generator/config/bn254.go index f8ffafc159..4e5ecc7ecb 100644 --- a/internal/generator/config/bn254.go +++ b/internal/generator/config/bn254.go @@ -2,11 +2,11 @@ package config func init() { Curves = append(Curves, Curve{ - Name: "bn254", - Package: "bn254", - EnumID: "BN254", - FrModulus: "21888242871839275222246405745257275088548364400416034343698204186575808495617", - FpModulus: "21888242871839275222246405745257275088696311157297823662689037894645226208583", + Name: "bn254", + CurvePackage: "bn254", + EnumID: "BN254", + FrModulus: "21888242871839275222246405745257275088548364400416034343698204186575808495617", + FpModulus: "21888242871839275222246405745257275088696311157297823662689037894645226208583", G1: Point{ CoordType: "fp.Element", PointName: "g1", diff --git a/internal/generator/config/bw6-761.go b/internal/generator/config/bw6-761.go index 72b4ba934b..543cff4cd1 100644 --- a/internal/generator/config/bw6-761.go +++ b/internal/generator/config/bw6-761.go @@ -2,11 +2,11 @@ package config func init() { Curves = append(Curves, Curve{ - Name: "bw6-761", - Package: "bw6761", - EnumID: "BW6_761", - FrModulus: "258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177", - FpModulus: "6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068299", + Name: "bw6-761", + CurvePackage: "bw6761", + EnumID: "BW6_761", + FrModulus: "258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177", + FpModulus: "6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068299", G1: Point{ CoordType: "fp.Element", PointName: "g1", diff --git a/internal/generator/config/curve.go b/internal/generator/config/curve.go index 930bf0dce2..b6969e83c5 100644 --- a/internal/generator/config/curve.go +++ b/internal/generator/config/curve.go @@ -7,11 +7,12 @@ import ( // Curve describes parameters of the curve useful for the template type Curve struct { - Name string - Package string - EnumID string - FpModulus string - FrModulus string + Name string + CurvePackage string + Package string // current package being generated + EnumID string + FpModulus string + FrModulus string Fp *field.Field Fr *field.Field diff --git a/internal/generator/crypto/hash/mimc/generate.go b/internal/generator/crypto/hash/mimc/generate.go index 3e9aa2ab66..c26a08452d 100644 --- a/internal/generator/crypto/hash/mimc/generate.go +++ b/internal/generator/crypto/hash/mimc/generate.go @@ -8,9 +8,11 @@ import ( ) func Generate(conf config.Curve, baseDir string, bgen *bavard.BatchGenerator) error { - entriesF := []bavard.EntryF{ - {File: filepath.Join(baseDir, "mimc.go"), TemplateF: []string{"mimc.go.tmpl"}}, + conf.Package = "mimc" + entries := []bavard.Entry{ + {File: filepath.Join(baseDir, "doc.go"), Templates: []string{"doc.go.tmpl"}}, + {File: filepath.Join(baseDir, "mimc.go"), Templates: []string{"mimc.go.tmpl"}}, } - return bgen.GenerateF(conf, "mimc", "./crypto/hash/mimc/template", entriesF...) + return bgen.Generate(conf, conf.Package, "./crypto/hash/mimc/template", entries...) } diff --git a/internal/generator/crypto/hash/mimc/template/doc.go.tmpl b/internal/generator/crypto/hash/mimc/template/doc.go.tmpl new file mode 100644 index 0000000000..6e02e37877 --- /dev/null +++ b/internal/generator/crypto/hash/mimc/template/doc.go.tmpl @@ -0,0 +1,2 @@ +// Package {{.Package}} provides MiMC hash function using Miyaguchi–Preneel construction. +package {{.Package}} \ No newline at end of file diff --git a/internal/generator/crypto/signature/eddsa/generate.go b/internal/generator/crypto/signature/eddsa/generate.go index 7594847dda..1422a4137e 100644 --- a/internal/generator/crypto/signature/eddsa/generate.go +++ b/internal/generator/crypto/signature/eddsa/generate.go @@ -8,13 +8,14 @@ import ( ) func Generate(conf config.Curve, baseDir string, bgen *bavard.BatchGenerator) error { - // eddsa - entriesF := []bavard.EntryF{ - {File: filepath.Join(baseDir, "eddsa.go"), TemplateF: []string{"eddsa.go.tmpl"}}, - {File: filepath.Join(baseDir, "eddsa_test.go"), TemplateF: []string{"eddsa.test.go.tmpl"}}, - {File: filepath.Join(baseDir, "marshal.go"), TemplateF: []string{"marshal.go.tmpl"}}, + conf.Package = "eddsa" + entries := []bavard.Entry{ + {File: filepath.Join(baseDir, "doc.go"), Templates: []string{"doc.go.tmpl"}}, + {File: filepath.Join(baseDir, "eddsa.go"), Templates: []string{"eddsa.go.tmpl"}}, + {File: filepath.Join(baseDir, "eddsa_test.go"), Templates: []string{"eddsa.test.go.tmpl"}}, + {File: filepath.Join(baseDir, "marshal.go"), Templates: []string{"marshal.go.tmpl"}}, } - return bgen.GenerateF(conf, "eddsa", "./crypto/signature/eddsa/template", entriesF...) + return bgen.Generate(conf, conf.Package, "./crypto/signature/eddsa/template", entries...) } diff --git a/internal/generator/crypto/signature/eddsa/template/doc.go.tmpl b/internal/generator/crypto/signature/eddsa/template/doc.go.tmpl new file mode 100644 index 0000000000..b2ab24e63e --- /dev/null +++ b/internal/generator/crypto/signature/eddsa/template/doc.go.tmpl @@ -0,0 +1,6 @@ +// Package {{.Package}} provides EdDSA signature scheme on {{.Name}}'s twisted edwards curve. +// +// See also +// +// https://en.wikipedia.org/wiki/EdDSA +package {{.Package}} \ No newline at end of file diff --git a/internal/generator/crypto/signature/eddsa/template/eddsa.test.go.tmpl b/internal/generator/crypto/signature/eddsa/template/eddsa.test.go.tmpl index 71fd69e40e..1b79d6746a 100644 --- a/internal/generator/crypto/signature/eddsa/template/eddsa.test.go.tmpl +++ b/internal/generator/crypto/signature/eddsa/template/eddsa.test.go.tmpl @@ -3,11 +3,41 @@ import ( "math/rand" "testing" + crand "crypto/rand" + + "fmt" + "github.com/consensys/gnark-crypto/signature" "github.com/consensys/gnark-crypto/hash" "github.com/consensys/gnark-crypto/ecc/{{.Name}}/fr" ) + +func Example() { + // instantiate hash function + hFunc := hash.MIMC_{{ .EnumID }}.New("seed") + + // create a eddsa key pair + privateKey, _ := signature.EDDSA_{{ .EnumID }}.New(crand.Reader) + publicKey := privateKey.Public() + + // note that the message is on 4 bytes + msg := []byte{0xde, 0xad, 0xf0, 0x0d} + + // sign the message + signature, _ := privateKey.Sign(msg, hFunc) + + // verifies signature + isValid, _ := publicKey.Verify(signature, msg, hFunc) + if !isValid { + fmt.Println("1. invalid signature") + } else { + fmt.Println("1. valid signature") + } + + // Output: 1. valid signature +} + func TestSerialization(t *testing.T) { src := rand.NewSource(0) diff --git a/internal/generator/ecc/generate.go b/internal/generator/ecc/generate.go index 5a829185bb..8cd38585c3 100644 --- a/internal/generator/ecc/generate.go +++ b/internal/generator/ecc/generate.go @@ -9,37 +9,38 @@ import ( ) func Generate(conf config.Curve, baseDir string, bgen *bavard.BatchGenerator) error { - doc := "provides efficient elliptic curve and pairing implementation for " + conf.Name packageName := strings.ReplaceAll(conf.Name, "-", "") g1 := pconf{conf, conf.G1} g2 := pconf{conf, conf.G2} - entriesF := []bavard.EntryF{ - {File: filepath.Join(baseDir, "multiexp.go"), TemplateF: []string{"multiexp.go.tmpl"}}, - {File: filepath.Join(baseDir, "multiexp_test.go"), TemplateF: []string{"tests/multiexp.go.tmpl"}}, - {File: filepath.Join(baseDir, "marshal.go"), TemplateF: []string{"marshal.go.tmpl"}, PackageDoc: doc}, - {File: filepath.Join(baseDir, "marshal_test.go"), TemplateF: []string{"tests/marshal.go.tmpl"}}, + entries := []bavard.Entry{ + {File: filepath.Join(baseDir, "doc.go"), Templates: []string{"doc.go.tmpl"}}, + {File: filepath.Join(baseDir, "multiexp.go"), Templates: []string{"multiexp.go.tmpl"}}, + {File: filepath.Join(baseDir, "multiexp_test.go"), Templates: []string{"tests/multiexp.go.tmpl"}}, + {File: filepath.Join(baseDir, "marshal.go"), Templates: []string{"marshal.go.tmpl"}}, + {File: filepath.Join(baseDir, "marshal_test.go"), Templates: []string{"tests/marshal.go.tmpl"}}, } - if err := bgen.GenerateF(conf, packageName, "./ecc/template", entriesF...); err != nil { + conf.Package = packageName + if err := bgen.Generate(conf, packageName, "./ecc/template", entries...); err != nil { return err } // G1 - entriesF = []bavard.EntryF{ - {File: filepath.Join(baseDir, "g1.go"), TemplateF: []string{"point.go.tmpl"}}, - {File: filepath.Join(baseDir, "g1_test.go"), TemplateF: []string{"tests/point.go.tmpl"}}, + entries = []bavard.Entry{ + {File: filepath.Join(baseDir, "g1.go"), Templates: []string{"point.go.tmpl"}}, + {File: filepath.Join(baseDir, "g1_test.go"), Templates: []string{"tests/point.go.tmpl"}}, } - if err := bgen.GenerateF(g1, packageName, "./ecc/template", entriesF...); err != nil { + if err := bgen.Generate(g1, packageName, "./ecc/template", entries...); err != nil { return err } // G2 - entriesF = []bavard.EntryF{ - {File: filepath.Join(baseDir, "g2.go"), TemplateF: []string{"point.go.tmpl"}}, - {File: filepath.Join(baseDir, "g2_test.go"), TemplateF: []string{"tests/point.go.tmpl"}}, + entries = []bavard.Entry{ + {File: filepath.Join(baseDir, "g2.go"), Templates: []string{"point.go.tmpl"}}, + {File: filepath.Join(baseDir, "g2_test.go"), Templates: []string{"tests/point.go.tmpl"}}, } - return bgen.GenerateF(g2, packageName, "./ecc/template", entriesF...) + return bgen.Generate(g2, packageName, "./ecc/template", entries...) } diff --git a/internal/generator/ecc/template/doc.go.tmpl b/internal/generator/ecc/template/doc.go.tmpl new file mode 100644 index 0000000000..1f6f464935 --- /dev/null +++ b/internal/generator/ecc/template/doc.go.tmpl @@ -0,0 +1,2 @@ +// Package {{.Package}} efficient elliptic curve and pairing implementation for {{.Name}}. +package {{.Package}} \ No newline at end of file diff --git a/internal/generator/edwards/generate.go b/internal/generator/edwards/generate.go index 4b5ca4f92c..48f329c41d 100644 --- a/internal/generator/edwards/generate.go +++ b/internal/generator/edwards/generate.go @@ -8,8 +8,13 @@ import ( ) func Generate(conf config.Curve, baseDir string, bgen *bavard.BatchGenerator) error { - return bgen.GenerateF(conf, "twistededwards", "./edwards/template", bavard.EntryF{ - File: filepath.Join(baseDir, "point.go"), TemplateF: []string{"pointtwistededwards.go.tmpl"}, - }) + conf.Package = "twistededwards" + + entries := []bavard.Entry{ + {File: filepath.Join(baseDir, "point.go"), Templates: []string{"pointtwistededwards.go.tmpl"}}, + {File: filepath.Join(baseDir, "doc.go"), Templates: []string{"doc.go.tmpl"}}, + } + + return bgen.Generate(conf, conf.Package, "./edwards/template", entries...) } diff --git a/internal/generator/edwards/template/doc.go.tmpl b/internal/generator/edwards/template/doc.go.tmpl new file mode 100644 index 0000000000..3cce357324 --- /dev/null +++ b/internal/generator/edwards/template/doc.go.tmpl @@ -0,0 +1,2 @@ +// Package {{.Package}} provides {{.Name}}'s twisted edwards "companion curve" defined on fr. +package {{.Package}} \ No newline at end of file diff --git a/internal/generator/fft/generate.go b/internal/generator/fft/generate.go index abbd057081..7fc01f599a 100644 --- a/internal/generator/fft/generate.go +++ b/internal/generator/fft/generate.go @@ -8,11 +8,13 @@ import ( ) func Generate(conf config.Curve, baseDir string, bgen *bavard.BatchGenerator) error { - entries := []bavard.EntryF{ - {File: filepath.Join(baseDir, "domain_test.go"), TemplateF: []string{"tests/domain.go.tmpl", "imports.go.tmpl"}}, - {File: filepath.Join(baseDir, "domain.go"), TemplateF: []string{"domain.go.tmpl", "imports.go.tmpl"}}, - {File: filepath.Join(baseDir, "fft_test.go"), TemplateF: []string{"tests/fft.go.tmpl", "imports.go.tmpl"}}, - {File: filepath.Join(baseDir, "fft.go"), TemplateF: []string{"fft.go.tmpl", "imports.go.tmpl"}}, + conf.Package = "fft" + entries := []bavard.Entry{ + {File: filepath.Join(baseDir, "doc.go"), Templates: []string{"doc.go.tmpl"}}, + {File: filepath.Join(baseDir, "domain_test.go"), Templates: []string{"tests/domain.go.tmpl", "imports.go.tmpl"}}, + {File: filepath.Join(baseDir, "domain.go"), Templates: []string{"domain.go.tmpl", "imports.go.tmpl"}}, + {File: filepath.Join(baseDir, "fft_test.go"), Templates: []string{"tests/fft.go.tmpl", "imports.go.tmpl"}}, + {File: filepath.Join(baseDir, "fft.go"), Templates: []string{"fft.go.tmpl", "imports.go.tmpl"}}, } - return bgen.GenerateF(conf, "fft", "./fft/template/", entries...) + return bgen.Generate(conf, conf.Package, "./fft/template/", entries...) } diff --git a/internal/generator/fft/template/doc.go.tmpl b/internal/generator/fft/template/doc.go.tmpl new file mode 100644 index 0000000000..7dc4f4d3b6 --- /dev/null +++ b/internal/generator/fft/template/doc.go.tmpl @@ -0,0 +1,2 @@ +// Package {{.Package}} provides in-place discrete Fourier transform. +package {{.Package}} \ No newline at end of file diff --git a/internal/generator/pairing/generate.go b/internal/generator/pairing/generate.go index f975a758ac..95688db774 100644 --- a/internal/generator/pairing/generate.go +++ b/internal/generator/pairing/generate.go @@ -14,8 +14,8 @@ func Generate(conf config.Curve, baseDir string, bgen *bavard.BatchGenerator) er return nil } packageName := strings.ReplaceAll(conf.Name, "-", "") - return bgen.GenerateF(conf, packageName, "./pairing/template", bavard.EntryF{ - File: filepath.Join(baseDir, "pairing_test.go"), TemplateF: []string{"tests/pairing.go.tmpl"}, + return bgen.Generate(conf, packageName, "./pairing/template", bavard.Entry{ + File: filepath.Join(baseDir, "pairing_test.go"), Templates: []string{"tests/pairing.go.tmpl"}, }) } diff --git a/internal/generator/pairing/template/doc.go.tmpl b/internal/generator/pairing/template/doc.go.tmpl new file mode 100644 index 0000000000..3cce357324 --- /dev/null +++ b/internal/generator/pairing/template/doc.go.tmpl @@ -0,0 +1,2 @@ +// Package {{.Package}} provides {{.Name}}'s twisted edwards "companion curve" defined on fr. +package {{.Package}} \ No newline at end of file diff --git a/internal/generator/polynomial/generate.go b/internal/generator/polynomial/generate.go index 5acff449cd..31ef06cae4 100644 --- a/internal/generator/polynomial/generate.go +++ b/internal/generator/polynomial/generate.go @@ -8,21 +8,25 @@ import ( ) func Generate(conf config.Curve, baseDir string, bgen *bavard.BatchGenerator) error { - entries := []bavard.EntryF{ - {File: filepath.Join(baseDir, "polynomial.go"), TemplateF: []string{"polynomial.go.tmpl"}}, + conf.Package = "polynomial" + entries := []bavard.Entry{ + {File: filepath.Join(baseDir, "doc.go"), Templates: []string{"doc.go.tmpl"}}, + {File: filepath.Join(baseDir, "polynomial.go"), Templates: []string{"polynomial.go.tmpl"}}, } - if err := bgen.GenerateF(conf, "polynomial", "./polynomial/template/", entries...); err != nil { + if err := bgen.Generate(conf, conf.Package, "./polynomial/template/", entries...); err != nil { return err } // mock commitment scheme - entries = []bavard.EntryF{ - {File: filepath.Join(baseDir, "mockcommitment", "digest.go"), TemplateF: []string{"commitment_mock/digest.go.tmpl"}}, - {File: filepath.Join(baseDir, "mockcommitment", "proof.go"), TemplateF: []string{"commitment_mock/proof.go.tmpl"}}, - {File: filepath.Join(baseDir, "mockcommitment", "proof_single_point.go"), TemplateF: []string{"commitment_mock/proof.single.point.go.tmpl"}}, - {File: filepath.Join(baseDir, "mockcommitment", "scheme.go"), TemplateF: []string{"commitment_mock/scheme.go.tmpl"}}, + conf.Package = "mockcommitment" + entries = []bavard.Entry{ + {File: filepath.Join(baseDir, "mockcommitment", "doc.go"), Templates: []string{"commitment_mock/doc.go.tmpl"}}, + {File: filepath.Join(baseDir, "mockcommitment", "digest.go"), Templates: []string{"commitment_mock/digest.go.tmpl"}}, + {File: filepath.Join(baseDir, "mockcommitment", "proof.go"), Templates: []string{"commitment_mock/proof.go.tmpl"}}, + {File: filepath.Join(baseDir, "mockcommitment", "proof_single_point.go"), Templates: []string{"commitment_mock/proof.single.point.go.tmpl"}}, + {File: filepath.Join(baseDir, "mockcommitment", "scheme.go"), Templates: []string{"commitment_mock/scheme.go.tmpl"}}, } - return bgen.GenerateF(conf, "mockcommitment", "./polynomial/template/", entries...) + return bgen.Generate(conf, conf.Package, "./polynomial/template/", entries...) } diff --git a/internal/generator/polynomial/template/commitment_mock/doc.go.tmpl b/internal/generator/polynomial/template/commitment_mock/doc.go.tmpl new file mode 100644 index 0000000000..b117dd97e6 --- /dev/null +++ b/internal/generator/polynomial/template/commitment_mock/doc.go.tmpl @@ -0,0 +1,2 @@ +// Package {{.Package}} provides a mock commitment scheme, for development and test purposes. +package {{.Package}} \ No newline at end of file diff --git a/internal/generator/polynomial/template/commitment_mock/scheme.go.tmpl b/internal/generator/polynomial/template/commitment_mock/scheme.go.tmpl index affd6a244a..aa7745b25d 100644 --- a/internal/generator/polynomial/template/commitment_mock/scheme.go.tmpl +++ b/internal/generator/polynomial/template/commitment_mock/scheme.go.tmpl @@ -2,7 +2,7 @@ import ( "io" "github.com/consensys/gnark-crypto/polynomial" - {{toLower .Package}} "github.com/consensys/gnark-crypto/ecc/{{.Name}}/fr/polynomial" + {{toLower .CurvePackage}} "github.com/consensys/gnark-crypto/ecc/{{.Name}}/fr/polynomial" ) // Scheme mock commitment, useful for testing polynomial based IOP @@ -22,7 +22,7 @@ func (s *Scheme) ReadFrom(r io.Reader) (n int64, err error) { // Commit returns nil func (s *Scheme) Commit(p polynomial.Polynomial) polynomial.Digest { - res := &MockDigest{Digest: p.({{ toLower .Package }}.Polynomial)} + res := &MockDigest{Digest: p.({{ toLower .CurvePackage }}.Polynomial)} return res } diff --git a/internal/generator/polynomial/template/doc.go.tmpl b/internal/generator/polynomial/template/doc.go.tmpl new file mode 100644 index 0000000000..9a47cdf74f --- /dev/null +++ b/internal/generator/polynomial/template/doc.go.tmpl @@ -0,0 +1,2 @@ +// Package {{.Package}} provides polynomial methods and commitment schemes. +package {{.Package}} \ No newline at end of file diff --git a/internal/generator/tower/generate.go b/internal/generator/tower/generate.go index 6b7926c8b0..662dbbaced 100644 --- a/internal/generator/tower/generate.go +++ b/internal/generator/tower/generate.go @@ -17,20 +17,20 @@ func Generate(conf config.Curve, baseDir string, bgen *bavard.BatchGenerator) er return nil } - entries := []bavard.EntryF{ - {File: filepath.Join(baseDir, "e2.go"), TemplateF: []string{"fq2.go.tmpl"}}, - {File: filepath.Join(baseDir, "e6.go"), TemplateF: []string{"fq6.go.tmpl"}}, - {File: filepath.Join(baseDir, "e12.go"), TemplateF: []string{"fq12.go.tmpl"}}, - {File: filepath.Join(baseDir, "e2_amd64.go"), TemplateF: []string{"amd64.fq2.go.tmpl"}}, - {File: filepath.Join(baseDir, "e2_fallback.go"), TemplateF: []string{"fallback.fq2.go.tmpl"}, BuildTag: "!amd64"}, - {File: filepath.Join(baseDir, "e2_test.go"), TemplateF: []string{"tests/fq2.go.tmpl"}}, - {File: filepath.Join(baseDir, "e6_test.go"), TemplateF: []string{"tests/fq6.go.tmpl"}}, - {File: filepath.Join(baseDir, "e12_test.go"), TemplateF: []string{"tests/fq12.go.tmpl"}}, - {File: filepath.Join(baseDir, "asm.go"), TemplateF: []string{"asm.go.tmpl"}, BuildTag: "!noadx"}, - {File: filepath.Join(baseDir, "asm_noadx.go"), TemplateF: []string{"asm_noadx.go.tmpl"}, BuildTag: "noadx"}, + entries := []bavard.Entry{ + {File: filepath.Join(baseDir, "e2.go"), Templates: []string{"fq2.go.tmpl"}}, + {File: filepath.Join(baseDir, "e6.go"), Templates: []string{"fq6.go.tmpl"}}, + {File: filepath.Join(baseDir, "e12.go"), Templates: []string{"fq12.go.tmpl"}}, + {File: filepath.Join(baseDir, "e2_amd64.go"), Templates: []string{"amd64.fq2.go.tmpl"}}, + {File: filepath.Join(baseDir, "e2_fallback.go"), Templates: []string{"fallback.fq2.go.tmpl"}, BuildTag: "!amd64"}, + {File: filepath.Join(baseDir, "e2_test.go"), Templates: []string{"tests/fq2.go.tmpl"}}, + {File: filepath.Join(baseDir, "e6_test.go"), Templates: []string{"tests/fq6.go.tmpl"}}, + {File: filepath.Join(baseDir, "e12_test.go"), Templates: []string{"tests/fq12.go.tmpl"}}, + {File: filepath.Join(baseDir, "asm.go"), Templates: []string{"asm.go.tmpl"}, BuildTag: "!noadx"}, + {File: filepath.Join(baseDir, "asm_noadx.go"), Templates: []string{"asm_noadx.go.tmpl"}, BuildTag: "noadx"}, } - if err := bgen.GenerateF(conf, "fptower", "./tower/template/fq12over6over2", entries...); err != nil { + if err := bgen.Generate(conf, "fptower", "./tower/template/fq12over6over2", entries...); err != nil { return err } diff --git a/polynomial/commitment.go b/polynomial/commitment.go index 7f8dc2a99b..b686ba3128 100644 --- a/polynomial/commitment.go +++ b/polynomial/commitment.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Package polynomial provides interfaces for polynomial and polynomial commitment schemes defined in gnark-crypto/ecc/.../fr. package polynomial import "io" diff --git a/signature/signature.go b/signature/signature.go index 5eb773e41e..2f6c4a15b5 100644 --- a/signature/signature.go +++ b/signature/signature.go @@ -14,10 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package signature defines interfaces for a signer, -// a verifier and a signature. It eases up testing the -// corresponding ZK implementations accross different -// curves. +// Package signature defines interfaces for a Signer and a PublicKey similarly to go/crypto standard package. package signature import ( @@ -90,8 +87,8 @@ const ( var signatures = make([]func(io.Reader) (Signer, error), maxSignatures) // Register registers a key pair generating function for a given signature scheme. -// We cannot import the corresponding constructors directly due to import cycles. func Register(ss SignatureScheme, f func(io.Reader) (Signer, error)) { + // we cannot import the corresponding constructors directly due to import cycles. signatures[ss] = f }