mirror of
https://github.com/arnaucube/gnark-plonky2-verifier.git
synced 2026-01-12 09:01:32 +01:00
Rearranged files (#17)
* removed unused file * change field import * change import of field package * changed field import * moved hash to poseidon and some changes to the field package * changed file structure
This commit is contained in:
@@ -7,13 +7,8 @@ import (
|
||||
"github.com/consensys/gnark/std/math/emulated"
|
||||
)
|
||||
|
||||
const D = 2
|
||||
|
||||
type EmulatedField = emulated.Goldilocks
|
||||
type F = emulated.Element[EmulatedField]
|
||||
type QuadraticExtension = [2]F
|
||||
type QEAlgebra = [D]QuadraticExtension
|
||||
type Hash = [4]F
|
||||
|
||||
var TEST_CURVE = ecc.BN254
|
||||
|
||||
@@ -8,6 +8,11 @@ import (
|
||||
"github.com/consensys/gnark/frontend"
|
||||
)
|
||||
|
||||
const D = 2
|
||||
|
||||
type QuadraticExtension = [2]F
|
||||
type QEAlgebra = [D]QuadraticExtension
|
||||
|
||||
type QuadraticExtensionAPI struct {
|
||||
fieldAPI frontend.API
|
||||
|
||||
|
||||
79
field/quadratic_extension_test.go
Normal file
79
field/quadratic_extension_test.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package field
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/consensys/gnark/frontend"
|
||||
"github.com/consensys/gnark/test"
|
||||
)
|
||||
|
||||
// TODO: ADD MORE TEST CASES!!!
|
||||
|
||||
// Test for quadratic extension multiplication
|
||||
type TestQuadraticExtensionMulCircuit struct {
|
||||
qeAPI *QuadraticExtensionAPI
|
||||
|
||||
operand1 QuadraticExtension
|
||||
operand2 QuadraticExtension
|
||||
expectedResult QuadraticExtension
|
||||
}
|
||||
|
||||
func (c *TestQuadraticExtensionMulCircuit) Define(api frontend.API) error {
|
||||
fieldAPI := NewFieldAPI(api)
|
||||
degreeBits := 3
|
||||
c.qeAPI = NewQuadraticExtensionAPI(fieldAPI, uint64(degreeBits))
|
||||
|
||||
actualRes := c.qeAPI.MulExtension(c.operand1, c.operand2)
|
||||
|
||||
fieldAPI.AssertIsEqual(actualRes[0], c.expectedResult[0])
|
||||
fieldAPI.AssertIsEqual(actualRes[1], c.expectedResult[1])
|
||||
|
||||
return nil
|
||||
}
|
||||
func TestQuadraticExtensionMul(t *testing.T) {
|
||||
assert := test.NewAssert(t)
|
||||
|
||||
operand1 := QuadraticExtension{NewFieldElement(4994088319481652598), NewFieldElement(16489566008211790727)}
|
||||
operand2 := QuadraticExtension{NewFieldElement(3797605683985595697), NewFieldElement(13424401189265534004)}
|
||||
expectedResult := QuadraticExtension{NewFieldElement(15052319864161058789), NewFieldElement(16841416332519902625)}
|
||||
|
||||
circuit := TestQuadraticExtensionMulCircuit{operand1: operand1, operand2: operand2, expectedResult: expectedResult}
|
||||
witness := TestQuadraticExtensionMulCircuit{operand1: operand1, operand2: operand2, expectedResult: expectedResult}
|
||||
err := test.IsSolved(&circuit, &witness, TEST_CURVE.ScalarField())
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
||||
// Test for quadratic extension division
|
||||
type TestQuadraticExtensionDivCircuit struct {
|
||||
qeAPI *QuadraticExtensionAPI
|
||||
|
||||
operand1 QuadraticExtension
|
||||
operand2 QuadraticExtension
|
||||
expectedResult QuadraticExtension
|
||||
}
|
||||
|
||||
func (c *TestQuadraticExtensionDivCircuit) Define(api frontend.API) error {
|
||||
fieldAPI := NewFieldAPI(api)
|
||||
degreeBits := 3
|
||||
c.qeAPI = NewQuadraticExtensionAPI(fieldAPI, uint64(degreeBits))
|
||||
|
||||
actualRes := c.qeAPI.DivExtension(c.operand1, c.operand2)
|
||||
|
||||
fieldAPI.AssertIsEqual(actualRes[0], c.expectedResult[0])
|
||||
fieldAPI.AssertIsEqual(actualRes[1], c.expectedResult[1])
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestQuadraticExtensionDiv(t *testing.T) {
|
||||
assert := test.NewAssert(t)
|
||||
|
||||
operand1 := QuadraticExtension{NewFieldElement(4994088319481652598), NewFieldElement(16489566008211790727)}
|
||||
operand2 := QuadraticExtension{NewFieldElement(7166004739148609569), NewFieldElement(14655965871663555016)}
|
||||
expectedResult := QuadraticExtension{NewFieldElement(15052319864161058789), NewFieldElement(16841416332519902625)}
|
||||
|
||||
circuit := TestQuadraticExtensionDivCircuit{operand1: operand1, operand2: operand2, expectedResult: expectedResult}
|
||||
witness := TestQuadraticExtensionDivCircuit{operand1: operand1, operand2: operand2, expectedResult: expectedResult}
|
||||
err := test.IsSolved(&circuit, &witness, TEST_CURVE.ScalarField())
|
||||
assert.NoError(err)
|
||||
}
|
||||
Reference in New Issue
Block a user