Skip to content

Commit

Permalink
fixing endianess issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Nov 18, 2024
1 parent 8b237b4 commit 5c73e59
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions ff.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package arbo

import "math/big"

var (
// BN254BaseField is the base field for the BN254 curve.
BN254BaseField, _ = new(big.Int).SetString("21888242871839275222246405745257275088548364400416034343698204186575808495617", 10)
// BLS12377BaseField is the base field for the BLS12377 curve.
BLS12377BaseField, _ = new(big.Int).SetString("25825498262808887005865186224201665565126143020923472090132963926938185026661", 10)
)

// BigToFF function returns the finite field representation of the big.Int
// provided. It uses the curve scalar field to represent the provided number.
func BigToFF(baseField, iv *big.Int) *big.Int {
z := big.NewInt(0)
if c := iv.Cmp(baseField); c == 0 {
return z
} else if c != 1 && iv.Cmp(z) != -1 {
return iv
}
return z.Mod(iv, baseField)
}
4 changes: 2 additions & 2 deletions hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ func (f HashMiMC_BLS12_377) Len() int {
func (f HashMiMC_BLS12_377) Hash(b ...[]byte) ([]byte, error) {
h := mimc.NewMiMC()
for i := 0; i < len(b); i++ {
if _, err := h.Write(b[i]); err != nil {
if _, err := h.Write(SwapEndianness(b[i])); err != nil {
return nil, err
}
}
return h.Sum(nil), nil
return SwapEndianness(h.Sum(nil)), nil
}

0 comments on commit 5c73e59

Please sign in to comment.