-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mimc hash implementation over bls12_377 ecc from gnark
- Loading branch information
1 parent
ffd61a9
commit 8e1cc94
Showing
15 changed files
with
217 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package arbo | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
) | ||
|
||
func TestBigToFF(t *testing.T) { | ||
baseField := BN254BaseField | ||
iv := new(big.Int).Sub(baseField, big.NewInt(1)) | ||
// test with iv < baseField (the result should be iv) | ||
z := BigToFF(baseField, iv) | ||
if z.Cmp(iv) != 0 { | ||
t.Fatalf("BigToFF failed: %v != %v", z, iv) | ||
} | ||
// test with iv > baseField (the result should be iv % baseField) | ||
iv = new(big.Int).Add(baseField, big.NewInt(1)) | ||
z = BigToFF(baseField, iv) | ||
if z.Cmp(big.NewInt(1)) != 0 { | ||
t.Fatalf("BigToFF failed: %v != 0", z) | ||
} | ||
// test with iv == baseField (the result should be 0) | ||
iv = baseField | ||
z = BigToFF(baseField, iv) | ||
if z.Cmp(big.NewInt(0)) != 0 { | ||
t.Fatalf("BigToFF failed: %v != 0", z) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.