Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions std/math/emulated/field_hint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ func (c *genericHintCircuitNativeInNativeOut[T]) Define(api frontend.API) error
return fmt.Errorf("expected 0 emulated outputs, got %d", len(outEm))
}
api.AssertIsEqual(outNative[0], c.Expected)
// duplicate constraint to ensure PLONK circuit has at least two constraints
api.AssertIsEqual(c.Expected, c.Expected)
return nil
}

Expand All @@ -247,7 +249,7 @@ func testGenericHintNativeInNativeOut[T FieldParams](t *testing.T) {
Denominator: b,
Expected: c,
}
assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(ecc.BN254))
assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(ecc.BN254), test.WithSolverOpts(solver.WithHints(hintNativeInNativeOut)))
}

func TestGenericHintNativeInNativeOut(t *testing.T) {
Expand Down Expand Up @@ -321,7 +323,7 @@ func testGenericHintNativeInEmulatedOut[T FieldParams](t *testing.T) {
Denominator: b,
Expected: ValueOf[T](c),
}
assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(ecc.BN254))
assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(ecc.BN254), test.WithSolverOpts(solver.WithHints(hintNativeInEmulatedOut)))
}

func TestGenericHintNativeInEmulatedOut(t *testing.T) {
Expand Down Expand Up @@ -394,7 +396,7 @@ func testGenericHintEmulatedInEmulatedOut[T FieldParams](t *testing.T) {
Denominator: ValueOf[T](b),
Expected: ValueOf[T](c),
}
assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness))
assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithSolverOpts(solver.WithHints(hintEmulatedInEmulatedOut)))
}

func TestGenericHintEmulatedInEmulatedOut(t *testing.T) {
Expand Down Expand Up @@ -450,6 +452,8 @@ func (c *genericHintCircuitEmulatedInNativeOut[T]) Define(api frontend.API) erro
return fmt.Errorf("expected 0 emulated outputs, got %d", len(outEm))
}
api.AssertIsEqual(outNat[0], c.Expected)
// duplicate constraint to ensure PLONK circuit has at least two constraints
api.AssertIsEqual(c.Expected, c.Expected)
return nil
}

Expand All @@ -467,7 +471,7 @@ func testGenericHintEmulatedInNativeOut[T FieldParams](t *testing.T) {
Denominator: ValueOf[T](b),
Expected: c,
}
assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(ecc.BN254))
assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(ecc.BN254), test.WithSolverOpts(solver.WithHints(hintEmulatedInNativeOut)))
}

func TestGenericHintEmulatedInNativeOut(t *testing.T) {
Expand Down Expand Up @@ -570,7 +574,7 @@ func testCrossFieldHint[T1, T2 FieldParams](t *testing.T) {
ExpectedEmulated1: ValueOf[T1](res2),
ExpectedEmulated2: ValueOf[T2](res3),
}
assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(ecc.BN254))
assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(ecc.BN254), test.WithSolverOpts(solver.WithHints(crossfieldHint)))
}

func TestCrossFieldHint(t *testing.T) {
Expand Down Expand Up @@ -651,7 +655,7 @@ func testMatchingFieldHint[T FieldParams](t *testing.T) {
ExpectedNative: res1,
ExpectedEmulated: ValueOf[T](res2),
}
assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(utils.FieldToCurve(fr.Modulus())))
assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(utils.FieldToCurve(fr.Modulus())), test.WithSolverOpts(solver.WithHints(matchingFieldHint)))
}

func TestMatchingFieldHint(t *testing.T) {
Expand Down
42 changes: 21 additions & 21 deletions test/unsafekzg/kzgsrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,16 @@ func toLagrange(canonicalSRS kzg.SRS, tau *big.Int) kzg.SRS {

switch srs := canonicalSRS.(type) {
case *kzg_bn254.SRS:
ttau := new(fr_bn254.Element).SetBigInt(tau)
newSRS := &kzg_bn254.SRS{Vk: srs.Vk}
size := uint64(len(srs.Pk.G1)) - 3

// instead of using ToLagrangeG1 we can directly do a fft on the powers of alpha
// since we know the randomness in test.
pAlpha := make([]fr_bn254.Element, size)
pAlpha[0].SetUint64(1)
pAlpha[1].SetBigInt(tau)
for i := 2; i < len(pAlpha); i++ {
pAlpha[i].Mul(&pAlpha[i-1], &pAlpha[1])
for i := 1; i < len(pAlpha); i++ {
pAlpha[i].Mul(&pAlpha[i-1], ttau)
}
// do a fft on this.
d := fft_bn254.NewDomain(size)
Expand All @@ -217,16 +217,16 @@ func toLagrange(canonicalSRS kzg.SRS, tau *big.Int) kzg.SRS {

lagrangeSRS = newSRS
case *kzg_bls12381.SRS:
ttau := new(fr_bls12381.Element).SetBigInt(tau)
newSRS := &kzg_bls12381.SRS{Vk: srs.Vk}
size := uint64(len(srs.Pk.G1)) - 3

// instead of using ToLagrangeG1 we can directly do a fft on the powers of alpha
// since we know the randomness in test.
pAlpha := make([]fr_bls12381.Element, size)
pAlpha[0].SetUint64(1)
pAlpha[1].SetBigInt(tau)
for i := 2; i < len(pAlpha); i++ {
pAlpha[i].Mul(&pAlpha[i-1], &pAlpha[1])
for i := 1; i < len(pAlpha); i++ {
pAlpha[i].Mul(&pAlpha[i-1], ttau)
}
// do a fft on this.
d := fft_bls12381.NewDomain(size)
Expand All @@ -239,16 +239,16 @@ func toLagrange(canonicalSRS kzg.SRS, tau *big.Int) kzg.SRS {

lagrangeSRS = newSRS
case *kzg_bls12377.SRS:
ttau := new(fr_bls12377.Element).SetBigInt(tau)
newSRS := &kzg_bls12377.SRS{Vk: srs.Vk}
size := uint64(len(srs.Pk.G1)) - 3

// instead of using ToLagrangeG1 we can directly do a fft on the powers of alpha
// since we know the randomness in test.
pAlpha := make([]fr_bls12377.Element, size)
pAlpha[0].SetUint64(1)
pAlpha[1].SetBigInt(tau)
for i := 2; i < len(pAlpha); i++ {
pAlpha[i].Mul(&pAlpha[i-1], &pAlpha[1])
for i := 1; i < len(pAlpha); i++ {
pAlpha[i].Mul(&pAlpha[i-1], ttau)
}
// do a fft on this.
d := fft_bls12377.NewDomain(size)
Expand All @@ -261,16 +261,16 @@ func toLagrange(canonicalSRS kzg.SRS, tau *big.Int) kzg.SRS {

lagrangeSRS = newSRS
case *kzg_bw6761.SRS:
ttau := new(fr_bw6761.Element).SetBigInt(tau)
newSRS := &kzg_bw6761.SRS{Vk: srs.Vk}
size := uint64(len(srs.Pk.G1)) - 3

// instead of using ToLagrangeG1 we can directly do a fft on the powers of alpha
// since we know the randomness in test.
pAlpha := make([]fr_bw6761.Element, size)
pAlpha[0].SetUint64(1)
pAlpha[1].SetBigInt(tau)
for i := 2; i < len(pAlpha); i++ {
pAlpha[i].Mul(&pAlpha[i-1], &pAlpha[1])
for i := 1; i < len(pAlpha); i++ {
pAlpha[i].Mul(&pAlpha[i-1], ttau)
}

// do a fft on this.
Expand All @@ -284,16 +284,16 @@ func toLagrange(canonicalSRS kzg.SRS, tau *big.Int) kzg.SRS {

lagrangeSRS = newSRS
case *kzg_bls24317.SRS:
ttau := new(fr_bls24317.Element).SetBigInt(tau)
newSRS := &kzg_bls24317.SRS{Vk: srs.Vk}
size := uint64(len(srs.Pk.G1)) - 3

// instead of using ToLagrangeG1 we can directly do a fft on the powers of alpha
// since we know the randomness in test.
pAlpha := make([]fr_bls24317.Element, size)
pAlpha[0].SetUint64(1)
pAlpha[1].SetBigInt(tau)
for i := 2; i < len(pAlpha); i++ {
pAlpha[i].Mul(&pAlpha[i-1], &pAlpha[1])
for i := 1; i < len(pAlpha); i++ {
pAlpha[i].Mul(&pAlpha[i-1], ttau)
}

// do a fft on this.
Expand All @@ -307,16 +307,16 @@ func toLagrange(canonicalSRS kzg.SRS, tau *big.Int) kzg.SRS {

lagrangeSRS = newSRS
case *kzg_bls24315.SRS:
ttau := new(fr_bls24315.Element).SetBigInt(tau)
newSRS := &kzg_bls24315.SRS{Vk: srs.Vk}
size := uint64(len(srs.Pk.G1)) - 3

// instead of using ToLagrangeG1 we can directly do a fft on the powers of alpha
// since we know the randomness in test.
pAlpha := make([]fr_bls24315.Element, size)
pAlpha[0].SetUint64(1)
pAlpha[1].SetBigInt(tau)
for i := 2; i < len(pAlpha); i++ {
pAlpha[i].Mul(&pAlpha[i-1], &pAlpha[1])
for i := 1; i < len(pAlpha); i++ {
pAlpha[i].Mul(&pAlpha[i-1], ttau)
}

// do a fft on this.
Expand All @@ -330,16 +330,16 @@ func toLagrange(canonicalSRS kzg.SRS, tau *big.Int) kzg.SRS {

lagrangeSRS = newSRS
case *kzg_bw6633.SRS:
ttau := new(fr_bw6633.Element).SetBigInt(tau)
newSRS := &kzg_bw6633.SRS{Vk: srs.Vk}
size := uint64(len(srs.Pk.G1)) - 3

// instead of using ToLagrangeG1 we can directly do a fft on the powers of alpha
// since we know the randomness in test.
pAlpha := make([]fr_bw6633.Element, size)
pAlpha[0].SetUint64(1)
pAlpha[1].SetBigInt(tau)
for i := 2; i < len(pAlpha); i++ {
pAlpha[i].Mul(&pAlpha[i-1], &pAlpha[1])
for i := 1; i < len(pAlpha); i++ {
pAlpha[i].Mul(&pAlpha[i-1], ttau)
}

// do a fft on this.
Expand Down