Files
threshold/pkg/zk/affg/affg_test.go
zeekay 3da6ad92e4 fix: apply golangci-lint auto-fixes
- Remove unnecessary trailing newlines
- Fix comment formatting
- Adjust indentation and spacing
- Remove unused nolint directives
2025-08-15 21:45:17 -05:00

66 lines
1.6 KiB
Go

package zkaffg
import (
"crypto/rand"
"testing"
"github.com/cronokirby/saferith"
"github.com/fxamacker/cbor/v2"
"github.com/luxfi/threshold/pkg/hash"
"github.com/luxfi/threshold/pkg/math/curve"
"github.com/luxfi/threshold/pkg/math/sample"
"github.com/luxfi/threshold/pkg/zk"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAffG(t *testing.T) {
group := curve.Secp256k1{}
verifierPaillier := zk.VerifierPaillierPublic
verifierPedersen := zk.Pedersen
prover := zk.ProverPaillierPublic
c := new(saferith.Int).SetUint64(12)
C, _ := verifierPaillier.Enc(c)
x := sample.IntervalL(rand.Reader)
X := group.NewScalar().SetNat(x.Mod(group.Order())).ActOnBase()
y := sample.IntervalLPrime(rand.Reader)
Y, rhoY := prover.Enc(y)
tmp := C.Clone().Mul(verifierPaillier, x)
D, rho := verifierPaillier.Enc(y)
D.Add(verifierPaillier, tmp)
public := Public{
Kv: C,
Dv: D,
Fp: Y,
Xp: X,
Prover: prover,
Verifier: verifierPaillier,
Aux: verifierPedersen,
}
private := Private{
X: x,
Y: y,
S: rho,
R: rhoY,
}
proof := NewProof(group, hash.New(), public, private)
assert.True(t, proof.Verify(hash.New(), public))
out, err := cbor.Marshal(proof)
require.NoError(t, err, "failed to marshal proof")
proof2 := Empty(group)
require.NoError(t, cbor.Unmarshal(out, proof2), "failed to unmarshal proof")
out2, err := cbor.Marshal(proof2)
require.NoError(t, err, "failed to marshal 2nd proof")
proof3 := Empty(group)
require.NoError(t, cbor.Unmarshal(out2, proof3), "failed to unmarshal 2nd proof")
assert.True(t, proof3.Verify(hash.New(), public))
}