From de44f1a28bc8d14f5ae1aecc11edc0624a330ec4 Mon Sep 17 00:00:00 2001 From: Özgür Kesim Date: Fri, 15 Nov 2024 10:57:43 +0100 Subject: simplify NewBit signature --- nizk/commit.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'nizk/commit.go') diff --git a/nizk/commit.go b/nizk/commit.go index ecb1568..93c730f 100644 --- a/nizk/commit.go +++ b/nizk/commit.go @@ -12,7 +12,7 @@ type Bit struct { β *Scalar *Commitment - prf *Proof + Proof *Proof *Stage } @@ -38,28 +38,30 @@ type Proof struct { } } -func NewBit(id Bytes, set bool) (*Bit, *Commitment, *Proof) { +func NewBit(id Bytes, set bool) *Bit { α, β := Curve.RandomScalar(), Curve.RandomScalar() return NewBitFromScalars(id, set, α, β) } -func NewBitFromScalars(id Bytes, set bool, α, β *Scalar) (*Bit, *Commitment, *Proof) { +func NewBitFromScalars(id Bytes, set bool, α, β *Scalar) *Bit { b := &Bit{ id: id, set: set, α: α, β: β, } - return b, b.commit(), b.proof() + b.commit() + b.proof() + return b } func (b *Bit) IsSet() bool { return b.set } -func (b *Bit) commit() *Commitment { +func (b *Bit) commit() { if b.Commitment != nil { - return b.Commitment + return } var C *Point @@ -75,12 +77,11 @@ func (b *Bit) commit() *Commitment { A: G.Exp(b.α), B: G.Exp(b.β), } - return b.Commitment } -func (s *Bit) proof() *Proof { - if s.prf != nil { - return s.prf +func (s *Bit) proof() { + if s.Proof != nil { + return } var e [2][2]*Point @@ -88,7 +89,8 @@ func (s *Bit) proof() *Proof { r1 = Curve.RandomScalar() r2 = Curve.RandomScalar() w = Curve.RandomScalar() - c := s.commit() + s.commit() + c := s.Commitment if s.set { e[0][0] = G.Exp(r1) @@ -119,8 +121,7 @@ func (s *Bit) proof() *Proof { pr.A = (*schnorr.Statement)(s.α).Proof(s.id) pr.B = (*schnorr.Statement)(s.β).Proof(s.id) - s.prf = pr - return pr + s.Proof = pr } func (c *Commitment) Verify(id Bytes, p *Proof) bool { -- cgit v1.2.3