Consensys / gnark-crypto

gnark-crypto provides elliptic curve and pairing-based cryptography on BN, BLS12, BLS24 and BW6 curves. It also provides various algorithms (algebra, crypto) of particular interest to zero knowledge proof systems.
Apache License 2.0
505 stars 163 forks source link

Bug SetString for frElement #388

Closed ThomasPiellard closed 1 year ago

ThomasPiellard commented 1 year ago

SetString() doesn't erase the previous value of a frElement if a small number of bits is changed. This example (r = BN254 scalar field) outputs the same result:

        var y fr.Element
    y.SetString("16406754891999554747479650379038048271643900448173543122927661446988296543616")
    fmt.Println(y.String())
    y.SetString("06406754891999554747479650379038048271643900448173543122927661446988296543616")
    fmt.Println(y.String())
gbotrel commented 1 year ago
func TestString(t *testing.T) {
    var y Element
    y.SetString("16406754891999554747479650379038048271643900448173543122927661446988296543616")
    fmt.Println(y.String())
    if _, err := y.SetString("06406754891999554747479650379038048271643900448173543122927661446988296543616"); err != nil {
        fmt.Println(err)
    }
    fmt.Println(y.String())
}

-->

Element.SetString failed -> can't parse number into a big.Int 06406754891999554747479650379038048271643900448173543122927661446988296543616
gbotrel commented 1 year ago

SetString relies on big.Int underneath, which errors with this input