Skip to content

Commit

Permalink
Move some errors to package level vars. Fix grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
OBrezhniev committed Jan 20, 2025
1 parent 11515c8 commit 0fae577
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions babyjub/eddsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package babyjub
import (
"crypto/rand"
"database/sql/driver"
"errors"
"fmt"
"math/big"

Expand All @@ -14,6 +15,13 @@ import (
"github.com/iden3/go-iden3-crypto/v2/utils"
)

var (
// ErrVerifyPoseidonFailed BJJ EdDSA (with Poseidon digest) signature verification failed
ErrVerifyPoseidonFailed = errors.New("verifyPoseidon failed")
// ErrVerifyMimc7Failed BJJ EdDSA (with Mimc7 digest) signature verification failed
ErrVerifyMimc7Failed = errors.New("verifyMimc7 failed")
)

// pruneBuffer prunes the buffer during key generation according to RFC 8032.
// https://tools.ietf.org/html/rfc8032#page-13
func pruneBuffer(buf *[32]byte) *[32]byte {
Expand Down Expand Up @@ -285,7 +293,7 @@ func (pk *PublicKey) VerifyMimc7(msg *big.Int, sig *Signature) error {
if (left.X.Cmp(right.X) == 0) && (left.Y.Cmp(right.Y) == 0) {
return nil
}
return fmt.Errorf("verifyMimc7 failed")
return ErrVerifyMimc7Failed
}

// SignPoseidon signs a message encoded as a big.Int in Zq using blake-512 hash
Expand Down Expand Up @@ -334,7 +342,7 @@ func (pk *PublicKey) VerifyPoseidon(msg *big.Int, sig *Signature) error {
if (left.X.Cmp(right.X) == 0) && (left.Y.Cmp(right.Y) == 0) {
return nil
}
return fmt.Errorf("verifyPoseidon failed")
return ErrVerifyPoseidonFailed
}

// Scan implements Scanner for database/sql.
Expand Down
4 changes: 2 additions & 2 deletions babyjub/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func Blake512(m []byte) []byte {
}

// DecompressSig decompresses a compressed signature.
func DecompressSig(commpresedSig []byte) (*Signature, error) {
func DecompressSig(compressedSig []byte) (*Signature, error) {
poseidonComSig := &SignatureComp{}
if err := poseidonComSig.UnmarshalText(commpresedSig); err != nil {
if err := poseidonComSig.UnmarshalText(compressedSig); err != nil {
return nil, err
}
poseidonDecSig, err := poseidonComSig.Decompress()
Expand Down
2 changes: 1 addition & 1 deletion goldenposeidon/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ var (
M [][]*ffg.Element
// P is a matrix
P [][]*ffg.Element
// S is a array of element
// S is an array of element
S []*ffg.Element
)

Expand Down

0 comments on commit 0fae577

Please sign in to comment.