-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: rudimentary test vectors * rebase: develop * fix: text file permission * feat: multi-input * fix: remove randomizer
- Loading branch information
Showing
2 changed files
with
138 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/consensys/gnark-crypto/ecc/bn254/fr" | ||
"github.com/consensys/gnark-crypto/ecc/bn254/fr/mimc" | ||
"os" | ||
) | ||
|
||
type numericalMiMCTestCase struct { | ||
In []string `json:"in"` | ||
Out string `json:"out"` | ||
} | ||
|
||
func assertNoError(err error) { | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(-1) | ||
} | ||
} | ||
|
||
//go:generate go run main.go | ||
func main() { | ||
var tests []numericalMiMCTestCase | ||
|
||
bytes, err := os.ReadFile("./vectors.json") | ||
assertNoError(err) | ||
assertNoError(json.Unmarshal(bytes, &tests)) | ||
|
||
hsh := mimc.NewMiMC() | ||
|
||
for i := range tests { | ||
|
||
hsh.Reset() | ||
var x fr.Element | ||
for j := range tests[i].In { | ||
_, err = x.SetString(tests[i].In[j]) | ||
assertNoError(err) | ||
|
||
b := x.Bytes() | ||
_, err = hsh.Write(b[:]) | ||
assertNoError(err) | ||
} | ||
|
||
bytes = hsh.Sum(nil) | ||
|
||
x.SetBytes(bytes) | ||
tests[i].Out = "0x" + x.Text(16) | ||
} | ||
|
||
bytes, err = json.MarshalIndent(tests, "", "\t") | ||
assertNoError(err) | ||
err = os.WriteFile("./vectors.json", bytes, 0) | ||
assertNoError(err) | ||
} |
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,82 @@ | ||
[ | ||
{ | ||
"in": [ | ||
"0x105afe02a0f7648bee1669b05bf7ae69a37dbb6c86ebbee325dffe97ac1f8e64" | ||
], | ||
"out": "0x263b9e754e6c611d646e65b16c48f51ab7bc0abedfae9c6ea04e2814ed28daf4" | ||
}, | ||
{ | ||
"in": [ | ||
"0xbc35f0589078e34d9139a357175d0e74b843e3de2f56bb6a5f18032ff3f627" | ||
], | ||
"out": "0x103e2c8f50dec5248fd68f9778429252364ff239b123977a697356082f524f25" | ||
}, | ||
{ | ||
"in": [ | ||
"0x208f0b283064057cf912b65eaa51e2cb2b85fdbe2fd0b2841f4bca59321ef1bf", | ||
"0x226bee7671296d05c998a5b5b4b1d25f478696d5997ba4f4be1a682c56a69e11" | ||
], | ||
"out": "0x1476ada1433d73817a69e45c84c5d452ad858f2dfdb1f7e4da203d3c4fd42222" | ||
}, | ||
{ | ||
"in": [ | ||
"0x995d448ab1fc86dd4874ebcbc0a7eea41acbe2c76e300aa73a1a0e63d5bc1b", | ||
"0x2190a93f59d9f8cbb4f6236c5b7bf511aec80e88bec71dad4f5bbba9346ff5e4" | ||
], | ||
"out": "0xcd4ef5556a9413b6bb98d12aba6ed9b937f0adce41ba618a212fdcb1629737a" | ||
}, | ||
{ | ||
"in": [ | ||
"0x6680de43f6cf410d4a8ed2893e58a8b740bac14f9dbdadbc8623c06027418a1", | ||
"0x59323b0ab7043f559674eba263da812eae9e933b0c1bad55f8118d0caaa7479", | ||
"0x16b161c8de7184ccc6b1b6fcddb562789a68eeaec174376f1157dfb3db310787" | ||
], | ||
"out": "0x118e5255aabe7a3b6a5dde6ca28de461d36f802653885c665745fc4e6ca0f709" | ||
}, | ||
{ | ||
"in": [ | ||
"0x1ab45102976d9ec683b46e7e7b4163055d1ab768d6bbd56cf95f3bca15d58020", | ||
"0x18ff125903dc8352ca63c7a436f0425b4b7ddf7e487fb9ffd30f151993571b57", | ||
"0x2cbfaa412f4b612d611acaab79a9e1c06b7094d8754fdbc085db28f2e4dd09ab" | ||
], | ||
"out": "0x25fa55a9896d91d9617d9512e061d754336816f748bf07566591ec5cf4680dd" | ||
}, | ||
{ | ||
"in": [ | ||
"0x2eddc35df3778e61c6571bcad90ab41dbf3cb61f4fd203d1922eb4fafde99136", | ||
"0x905c2010ece23e26373b38b6fc8b3c932a59443af656fb164e22b2bcf940b5a", | ||
"0x22e63a3eb565d13c42c7d520c7b6112534b1c666653452f743b80bcc2d878455", | ||
"0x96dff377f354f792685a7e740e3024409c24a379425ff63e3ce320b1e9bc471" | ||
], | ||
"out": "0x18ea2fd58b4f3274193f3e73bded685426f114a8e7bc373c1aee3e6f0125787b" | ||
}, | ||
{ | ||
"in": [ | ||
"0x5f3e89a9418877cd586de7c5cb061e6701a1bd69074cc7bd97c7c39d8f955eb", | ||
"0x20cdf81f33b895b442d47357bd80e1eca03f410d808324f6d151dc68ab354a1f", | ||
"0x12f4c27e5a2e80dd67fb33928c4e6219a8bdc89b498ed32acb02d725cec90076", | ||
"0x1d6b52c237f0f74f0c50755627eed2610608488b54b0a3941a4623b1d435232a" | ||
], | ||
"out": "0x2f237dea4570779296e2866383740b8e9ccf59577f8ff729880dadb58ae34d47" | ||
}, | ||
{ | ||
"in": [ | ||
"0x262c77f7fdef59c80e0a9d4ece6d18fb6d64ebaacfc21921f44c5adc19698c6a", | ||
"0x87bb7a78b27d19c5a502fbb087e48785d2777cff15d7b493901a8e528b64ee0", | ||
"0x2a8a0e2a793fdd5bc340857b355f2b4c00c2723cefdf8515bda5beef458fca2b", | ||
"0x2d4232cb721888f71997377de5ca195a5ae03d3eb9c87d2c04ef3664759036da", | ||
"0x2f623ee75518430e291d42e7aaa75f5291a1bbfed125426d39270046a26be35a" | ||
], | ||
"out": "0x6246dee7e2d9560a074c50a06e6525e4a58395cea4a893c49d71e373f19b9d6" | ||
}, | ||
{ | ||
"in": [ | ||
"0x14b09f9af90cafa8a4e508f5289a6868804f98d3a724162999193e6c4bf752ea", | ||
"0x727359808271f360a6136389a9e2d5b1bb6ff3e8c4125ca03005892446ac17d", | ||
"0x2b4abbd9943b201c1f75754833684f9eb15728a2ba646c53c2614bea7c9b968b", | ||
"0x8e0ddb80366c4c6c7dcb9090f4862d64ef40677d324a76a82e06ca33ad29a09", | ||
"0x170e8c954ca7e6526b743e92f796488afe5083a9c549358f730659c3e1cdbafa" | ||
], | ||
"out": "0x1a2e7cffb5183898a8f4f6d4699bc272665ebffbb9d095576d2e21c45f012358" | ||
} | ||
] |