-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
therealyingtong
committed
Jun 13, 2019
1 parent
eb66b77
commit d3fa26d
Showing
8 changed files
with
141 additions
and
27 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,19 @@ | ||
const fs = require("fs"); | ||
|
||
var a = [2,2,2,2]; | ||
var b = [4,4,4,4]; | ||
var c = [6,6,6,6]; | ||
var d = [24,24,24,24]; | ||
|
||
const inputs = { | ||
"a": a, | ||
"b": b, | ||
"c": c, | ||
"d": d | ||
} | ||
|
||
fs.writeFileSync( | ||
"./input.json", | ||
JSON.stringify(inputs), | ||
"utf-8" | ||
); |
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,23 @@ | ||
template SimpleChecks(k) { | ||
signal private input a[k]; | ||
signal private input b[k]; | ||
signal input c[k]; | ||
signal private input d[k]; | ||
signal output out; | ||
|
||
var sum = 0; | ||
for (var i = 0; i < k; i++){ | ||
// force a + b = c | ||
a[i] + b[i] === c[i]; | ||
|
||
// force b * c = d | ||
b[i] * c[i] === d[i]; | ||
|
||
// add up c and d arrays | ||
sum = sum + c[i] + d[i]; | ||
} | ||
// output sum of c and d arrays | ||
out <== sum; | ||
} | ||
|
||
component main = SimpleChecks(4); |
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 |
---|---|---|
@@ -1,23 +1,18 @@ | ||
template SimpleChecks(k) { | ||
signal private input a[k]; | ||
signal private input b[k]; | ||
signal input c[k]; | ||
signal private input d[k]; | ||
template SimpleChecks() { | ||
signal private input a; | ||
signal private input b; | ||
signal input c; | ||
signal private input d; | ||
signal output out; | ||
|
||
var sum = 0; | ||
for (var i = 0; i < k; i++){ | ||
// force a + b = c | ||
a[i] + b[i] === c[i]; | ||
// force a + b = c | ||
a + b === c; | ||
|
||
// force b * c = d | ||
b[i] * c[i] === d[i]; | ||
// force b * c = d | ||
b * c === d; | ||
|
||
// add up c and d arrays | ||
sum = sum + c[i] + d[i]; | ||
} | ||
// output sum of c and d arrays | ||
out <== sum; | ||
// output c + d | ||
out <== c + d; | ||
} | ||
|
||
component main = SimpleChecks(4); | ||
component main = SimpleChecks(); |
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,25 @@ | ||
const fs = require("fs"); | ||
const eddsa = require("../circomlib/src/eddsa.js"); | ||
const mimcjs = require("../circomlib/src/mimc7.js"); | ||
|
||
const preimage = [123,456,789]; | ||
const M = mimcjs.multiHash(preimage); | ||
const prvKey = Buffer.from('1'.toString().padStart(64,'0'), "hex"); | ||
const pubKey = eddsa.prv2pub(prvKey); | ||
|
||
const signature = eddsa.signMiMC(prvKey, M); | ||
|
||
const inputs = { | ||
"from_x": pubKey[0].toString(), | ||
"from_y": pubKey[1].toString(), | ||
"R8x": signature['R8'][0].toString(), | ||
"R8y": signature['R8'][1].toString(), | ||
"S": signature['S'].toString(), | ||
"preimage": preimage | ||
} | ||
|
||
fs.writeFileSync( | ||
"./input.json", | ||
JSON.stringify(inputs), | ||
"utf-8" | ||
); |
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,30 @@ | ||
include "../circomlib/circuits/eddsamimc.circom"; | ||
include "../circomlib/circuits/mimc.circom"; | ||
|
||
template VerifyEdDSAMiMC(k) { | ||
|
||
// k is length of preimage | ||
|
||
signal input from_x; | ||
signal input from_y; | ||
signal input R8x; | ||
signal input R8y; | ||
signal input S; | ||
signal private input preimage[k]; | ||
|
||
component M = MultiMiMC7(k,91); | ||
for (var i = 0; i < k; i++){ | ||
M.in[i] <== preimage[i]; | ||
} | ||
|
||
component verifier = EdDSAMiMCVerifier(); | ||
verifier.enabled <== 1; | ||
verifier.Ax <== from_x; | ||
verifier.Ay <== from_y; | ||
verifier.R8x <== R8x; | ||
verifier.R8y <== R8y; | ||
verifier.S <== S; | ||
verifier.M <== M.out; | ||
} | ||
|
||
component main = VerifyEdDSAMiMC(3); |
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,27 @@ | ||
const fs = require("fs"); | ||
const mimcjs = require("../circomlib/src/mimc7.js"); | ||
const mimcMerkle = require('./MiMCMerkle.js') | ||
|
||
const leaf1 = mimcjs.multiHash([1,2,3]) | ||
const leaf2 = mimcjs.multiHash([4,5,6]) | ||
const leaf3 = mimcjs.multiHash([7,8,9]) | ||
const leaf4 = mimcjs.multiHash([9,8,7]) | ||
const leafArray = [leaf1,leaf2,leaf3,leaf4] | ||
|
||
const tree = mimcMerkle.treeFromLeafArray(leafArray) | ||
const root = tree[0][0]; | ||
const leaf1Proof = mimcMerkle.getProof(0, tree, leafArray) | ||
const leaf1Pos = mimcMerkle.idxToBinaryPos(0, 2) | ||
|
||
const inputs = { | ||
"preimage": [1,2,3], | ||
"root": root, | ||
"paths2_root": [leaf1Proof[0].toString(),leaf1Proof[1].toString()], | ||
"paths2_root_pos": leaf1Pos | ||
} | ||
|
||
fs.writeFileSync( | ||
"./input.json", | ||
JSON.stringify(inputs), | ||
"utf-8" | ||
); |
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