mirror of
https://github.com/luxfi/threshold.git
synced 2026-10-30 15:15:53 +00:00
- Fix go vet error in lss_bench_test.go: replace b.Fatal with panic in goroutine - Fix go vet error in lss_test.go: remove t.Skip call from goroutine - Apply gofmt to all files to fix formatting issues All go vet errors and formatting issues have been resolved.
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package zkmulstar
|
|
|
|
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 TestMulG(t *testing.T) {
|
|
group := curve.Secp256k1{}
|
|
|
|
verifierPaillier := zk.VerifierPaillierPublic
|
|
verifierPedersen := zk.Pedersen
|
|
|
|
c := new(saferith.Int).SetUint64(12)
|
|
C, _ := verifierPaillier.Enc(c)
|
|
|
|
x := sample.IntervalL(rand.Reader)
|
|
X := group.NewScalar().SetNat(x.Mod(group.Order())).ActOnBase()
|
|
|
|
D := C.Clone().Mul(verifierPaillier, x)
|
|
n := verifierPaillier.N()
|
|
rho := sample.UnitModN(rand.Reader, n)
|
|
D.Randomize(verifierPaillier, rho)
|
|
|
|
public := Public{
|
|
C: C,
|
|
D: D,
|
|
X: X,
|
|
Verifier: verifierPaillier,
|
|
Aux: verifierPedersen,
|
|
}
|
|
private := Private{
|
|
X: x,
|
|
Rho: rho,
|
|
}
|
|
proof := NewProof(group, hash.New(), public, private)
|
|
assert.True(t, proof.Verify(group, 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(group, hash.New(), public))
|
|
}
|