Skip to content

dlog v1 finalization: proofs must belong to the elliptic curve defined in the public parameters #1049

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
34 changes: 33 additions & 1 deletion token/core/zkatdlog/nogh/v1/crypto/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ import (
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
)

type BaseElement interface {
CurveID() mathlib.CurveID
}

type Element interface {
BaseElement
IsInfinity() bool
CurveID() mathlib.CurveID
}

func CheckElements[E Element](elements []E, curveID mathlib.CurveID, length uint64) error {
Expand All @@ -30,6 +34,18 @@ func CheckElements[E Element](elements []E, curveID mathlib.CurveID, length uint
return nil
}

func CheckZrElements[E BaseElement](elements []E, curveID mathlib.CurveID, length uint64) error {
if uint64(len(elements)) != length {
return errors.Errorf("length of elements does not match length of curveID")
}
for _, g1 := range elements {
if err := CheckBaseElement[E](g1, curveID); err != nil {
return err
}
}
return nil
}

func CheckElement[E Element](element E, curveID mathlib.CurveID) (err error) {
defer func() {
if e := recover(); e != nil {
Expand All @@ -49,6 +65,22 @@ func CheckElement[E Element](element E, curveID mathlib.CurveID) (err error) {
return nil
}

func CheckBaseElement[E BaseElement](element E, curveID mathlib.CurveID) (err error) {
defer func() {
if e := recover(); e != nil {
err = errors.Errorf("caught panic while checking element, err [%s]", e)
}
}()

if isNilInterface(element) {
return errors.Errorf("elememt is nil")
}
if element.CurveID() != curveID {
return errors.Errorf("element curve must equal curve ID")
}
return nil
}

func isNilInterface(i interface{}) bool {
if i == nil {
return true
Expand Down
Loading