Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deactivate range proof when it is an ownership transfer #151

Merged
merged 4 commits into from
Dec 14, 2021
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
17 changes: 12 additions & 5 deletions token/core/zkatdlog/crypto/transfer/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,19 @@ func NewProver(inputwitness, outputwitness []*token.TokenDataWitness, inputs, ou
for i := 0; i < len(outputwitness); i++ {
outW[i] = outputwitness[i].Clone()
}

p.RangeCorrectness = rangeproof.NewProver(outW, outputs, pp.RangeProofParams.SignedValues, pp.RangeProofParams.Exponent, pp.ZKATPedParams, pp.RangeProofParams.SignPK, pp.P, pp.RangeProofParams.Q, math.Curves[pp.Curve])
if len(inputwitness) != 1 || len(outputwitness) != 1 {
p.RangeCorrectness = rangeproof.NewProver(outW, outputs, pp.RangeProofParams.SignedValues, pp.RangeProofParams.Exponent, pp.ZKATPedParams, pp.RangeProofParams.SignPK, pp.P, pp.RangeProofParams.Q, math.Curves[pp.Curve])
}
wfw := NewWellFormednessWitness(inW, outW)
p.WellFormedness = NewWellFormednessProver(wfw, pp.ZKATPedParams, inputs, outputs, math.Curves[pp.Curve])
return p
}

func NewVerifier(inputs, outputs []*math.G1, pp *crypto.PublicParams) *Verifier {
v := &Verifier{}
v.RangeCorrectness = rangeproof.NewVerifier(outputs, uint64(len(pp.RangeProofParams.SignedValues)), pp.RangeProofParams.Exponent, pp.ZKATPedParams, pp.RangeProofParams.SignPK, pp.P, pp.RangeProofParams.Q, math.Curves[pp.Curve])
if len(inputs) != 1 || len(outputs) != 1 {
v.RangeCorrectness = rangeproof.NewVerifier(outputs, uint64(len(pp.RangeProofParams.SignedValues)), pp.RangeProofParams.Exponent, pp.ZKATPedParams, pp.RangeProofParams.SignPK, pp.P, pp.RangeProofParams.Q, math.Curves[pp.Curve])
}
v.WellFormedness = NewWellFormednessVerifier(pp.ZKATPedParams, inputs, outputs, math.Curves[pp.Curve])

return v
Expand All @@ -80,7 +83,9 @@ func (p *Prover) Prove() ([]byte, error) {

go func() {
defer wg.Done()
rangeProof, rangeErr = p.RangeCorrectness.Prove()
if p.RangeCorrectness != nil {
rangeProof, rangeErr = p.RangeCorrectness.Prove()
}
}()

wfProof, wfErr = p.WellFormedness.Prove()
Expand Down Expand Up @@ -121,7 +126,9 @@ func (v *Verifier) Verify(proof []byte) error {
go func() {
defer wg.Done()
// verify range proof
rangeErr = v.RangeCorrectness.Verify(tp.RangeCorrectness)
if v.RangeCorrectness != nil {
rangeErr = v.RangeCorrectness.Verify(tp.RangeCorrectness)
}
}()

wg.Wait()
Expand Down
54 changes: 53 additions & 1 deletion token/core/zkatdlog/crypto/transfer/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
func TestParallelProveVerify(t *testing.T) {
parallelism := 1000

prover, verifier := prepareZKTransfer()
prover, verifier := prepareOwnershipTransfer()

var wg sync.WaitGroup
wg.Add(parallelism)
Expand Down Expand Up @@ -238,3 +238,55 @@ func prepareInvalidInputsForZKTransfer(pp *crypto.PublicParams) (*transfer.WellF

return transfer.NewWellFormednessWitness(intw, outtw), in, out
}

func prepareInputsForOwnershipTransfer(pp *crypto.PublicParams) (*transfer.WellFormednessWitness, []*math.G1, []*math.G1) {
c := math.Curves[pp.Curve]
rand, err := c.Rand()
Expect(err).NotTo(HaveOccurred())

inBF := c.NewRandomZr(rand)
outBF := c.NewRandomZr(rand)
ttype := "ABC"
inValue := c.NewZrFromInt(90)
outValue := c.NewZrFromInt(90)

in, out := prepareInputsOutputs([]*math.Zr{inValue}, []*math.Zr{outValue}, []*math.Zr{inBF}, []*math.Zr{outBF}, ttype, pp.ZKATPedParams, c)
intw := make([]*token.TokenDataWitness, 1)
for i := 0; i < len(intw); i++ {
intw[i] = &token.TokenDataWitness{BlindingFactor: inBF, Value: inValue, Type: ttype}
}

outtw := make([]*token.TokenDataWitness, 1)
for i := 0; i < len(outtw); i++ {
outtw[i] = &token.TokenDataWitness{BlindingFactor: outBF, Value: outValue, Type: ttype}
}
return transfer.NewWellFormednessWitness(intw, outtw), in, out
}

func prepareOwnershipTransfer() (*transfer.Prover, *transfer.Verifier) {
pp, err := crypto.Setup(100, 2, nil)
Expect(err).NotTo(HaveOccurred())

wfw, in, out := prepareInputsForOwnershipTransfer(pp)

inBF := wfw.GetInBlindingFators()
outBF := wfw.GetOutBlindingFators()

inValues := wfw.GetInValues()
outValues := wfw.GetOutValues()

ttype := "ABC"
intw := make([]*token.TokenDataWitness, len(inValues))
for i := 0; i < len(intw); i++ {
intw[i] = &token.TokenDataWitness{BlindingFactor: inBF[i], Value: inValues[i], Type: ttype}
}

outtw := make([]*token.TokenDataWitness, len(outValues))
for i := 0; i < len(outtw); i++ {
outtw[i] = &token.TokenDataWitness{BlindingFactor: outBF[i], Value: outValues[i], Type: ttype}
}
prover := transfer.NewProver(intw, outtw, in, out, pp)
verifier := transfer.NewVerifier(in, out, pp)

return prover, verifier
}