From 04c4b67fcaa85c9b4d8bc379b6938a169866e093 Mon Sep 17 00:00:00 2001 From: Özgür Kesim Date: Thu, 14 Nov 2024 18:06:01 +0100 Subject: simplify API and structs --- nizk/commit.go | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'nizk/commit.go') diff --git a/nizk/commit.go b/nizk/commit.go index 957e4a9..5634b16 100644 --- a/nizk/commit.go +++ b/nizk/commit.go @@ -7,18 +7,20 @@ import ( type Bit struct { id Bytes - bit bool + set bool α *Scalar β *Scalar - com *Commitment + *Commitment prf *Proof + + *Stage } type Commitment struct { A *Point // g^α B *Point // g^β - C *Point // g^(ab)g^(bit) + C *Point // g^(ab)g^(set) } // This is a construction of a proof of a statement of the form @@ -36,51 +38,43 @@ type Proof struct { } } -func NewBit(id Bytes, bit bool) *Bit { +func NewBit(id Bytes, set bool) *Bit { α, β := Curve.RandomScalar(), Curve.RandomScalar() - return NewBitFromScalars(id, bit, α, β) + return NewBitFromScalars(id, set, α, β) } -func NewBitFromScalars(id Bytes, bit bool, α, β *Scalar) *Bit { +func NewBitFromScalars(id Bytes, set bool, α, β *Scalar) *Bit { return &Bit{ id: id, - bit: bit, + set: set, α: α, β: β, } } func (b *Bit) IsSet() bool { - return b.bit -} - -func (b *Bit) Id() Bytes { - return b.id -} - -func (b *Bit) Scalars() (α *Scalar, β *Scalar) { - return b.α, b.β + return b.set } func (b *Bit) commit() *Commitment { - if b.com != nil { - return b.com + if b.Commitment != nil { + return b.Commitment } var C *Point c := b.α.Mul(b.β) - if b.bit { + if b.set { C = G.Exp(c.Add(One)) } else { C = G.Exp(c) } - b.com = &Commitment{ + b.Commitment = &Commitment{ C: C, A: G.Exp(b.α), B: G.Exp(b.β), } - return b.com + return b.Commitment } func (s *Bit) proof() *Proof { @@ -95,7 +89,7 @@ func (s *Bit) proof() *Proof { w = Curve.RandomScalar() c := s.commit() - if s.bit { + if s.set { e[0][0] = G.Exp(r1) e[0][1] = c.B.Exp(r1).Mul(G.Exp(w)) e[1][0] = G.Exp(r2) @@ -110,7 +104,7 @@ func (s *Bit) proof() *Proof { ch := Challenge(G, c.C, c.A, c.B, e[0][0], e[0][1], e[1][0], e[1][1], s.id) pr := &Proof{} - if s.bit { + if s.set { pr.C.Ch[0] = w pr.C.Ch[1] = ch.Sub(w) pr.C.R[0] = r1.Sub(s.α.Mul(pr.C.Ch[0])) -- cgit v1.2.3