Skip to content

Instantly share code, notes, and snippets.

@guidovranken
Last active June 19, 2023 16:59
Show Gist options
  • Save guidovranken/14f882f1b0af90398ceb39eeebdace27 to your computer and use it in GitHub Desktop.
Save guidovranken/14f882f1b0af90398ceb39eeebdace27 to your computer and use it in GitHub Desktop.
package main
import (
kilic "github.com/kilic/bls12-381"
"math/big"
"fmt"
)
func decodeBignum(s string) *big.Int {
if s == "" {
s = "0"
}
bn, ok := new(big.Int).SetString(s, 10)
if ok == false {
panic("Cannot decode bignum")
}
return bn
}
func main() {
var a, b kilic.Fr
a.FromBytes(decodeBignum("52435875175126190479447740508185965837690552500527637822603658699938581184513").Bytes())
b.FromBytes(decodeBignum("0").Bytes())
fmt.Println(a.Equal(&b))
}
@SetarehGhorshi
Copy link

The above test returns false which seems to be correct. Could you please give more details on what the exact bug is? Thank you!

@guidovranken
Copy link
Author

The first number was wrong. I've changed it to 52435875175126190479447740508185965837690552500527637822603658699938581184513.

N = 52435875175126190479447740508185965837690552500527637822603658699938581184513

Every number loaded with Fr.FromBytes should be reduced modulo N.
So if you load N, the effective value should be 0.

The program essentially computes 0 MOD N == N MOD N. Effectively this is 0 == 0. Hence it should print true, not false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment