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

Update bignum_pure.go - Minor edit -> handling zero division in InvModFr #37

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion bls/bignum_pure.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package bls
import (
"crypto/rand"
"math/big"
"errors"
)

var _modulus big.Int
Expand Down Expand Up @@ -107,8 +108,12 @@ func PowModFr(dst *Fr, a, b *Fr) {
(*big.Int)(dst).Exp((*big.Int)(a), (*big.Int)(b), &_modulus)
}

func InvModFr(dst *Fr, v *Fr) {
func InvModFr(dst *Fr, v *Fr) error {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is that this function signature matches InvModFr in:

With build tags the performance of different implementations of field-element operations can be compared in benchmarks etc. since a big part of this repository is FFT related code for data-availability-sampling.

And since native divide by zero behaves the same with a panic, and this error return is a breaking API change, I'm a bit hesitant to merge this. What do you use go-kzg for, and what is the motivation for this PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just exploring your repo for the sake of learning. This PR is for error handling - might be helpful if used at scale

if EqualZero(v) {
return errors.New("division by zero")
}
(*big.Int)(dst).ModInverse((*big.Int)(v), &_modulus)
return nil
}

// BatchInvModFr computes the inverse for each input.
Expand Down