Fix Poseidon Hash check for inputs being in Finite Field (#42)

This commit is contained in:
Oleksandr Brezhniev
2021-11-21 02:58:03 +02:00
committed by GitHub
parent 64e757cc4a
commit f597e20569
2 changed files with 18 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
package poseidon
import (
"errors"
"fmt"
"math/big"
@@ -59,6 +60,9 @@ func Hash(inpBI []*big.Int) (*big.Int, error) {
if len(inpBI) == 0 || len(inpBI) > len(NROUNDSP) {
return nil, fmt.Errorf("invalid inputs length %d, max %d", len(inpBI), len(NROUNDSP)) //nolint:gomnd,lll
}
if !utils.CheckBigIntArrayInField(inpBI[:]) {
return nil, errors.New("inputs values not inside Finite Field")
}
inp := utils.BigIntArrayToElementArray(inpBI[:])
nRoundsF := NROUNDSF