-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
eb4bb91
commit d045591
Showing
9 changed files
with
353 additions
and
2 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,12 @@ | ||
{ | ||
"version": "2.1.4", | ||
"verbose": true, | ||
"prime": "bn128", | ||
"optimization": 1, | ||
"protocol": "groth16", | ||
"circuits": "./circuits.json", | ||
"dirPtau": "./circuit/ptau", | ||
"dirCircuits": "./circuit/circuits", | ||
"dirInputs": "./circuit/inputs", | ||
"dirBuild": "./circuit/build" | ||
} |
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,50 @@ | ||
pragma circom 2.0.0; | ||
|
||
// TODO Add Range Check | ||
|
||
include "../node_modules/circomlib/circuits/comparators.circom"; | ||
// include "../node_modules/circomlib/circuits/poseidon.circom"; | ||
|
||
template isCloser() { | ||
signal input treasureCoord[2]; | ||
signal input userPrevCoord[2]; | ||
signal input userCurrCoord[2]; | ||
// signal input hash; | ||
|
||
signal prevXDiffSquared; | ||
signal prevYDiffSquared; | ||
signal prevDist; | ||
|
||
signal currXDiffSquared; | ||
signal currYDiffSquared; | ||
signal currDist; | ||
|
||
signal output isCloser; | ||
|
||
component lt = LessThan(64); | ||
// component hasher = Poseidon(2); | ||
|
||
// hasher.in[0] <== treasureCoord[0]; | ||
// hasher.in[1] <== treasureCoord[1]; | ||
// hasher.out[0] === hash; | ||
|
||
prevXDiffSquared <== (treasureCoord[0] - userPrevCoord[0]) * (treasureCoord[0] - userPrevCoord[0]); | ||
prevYDiffSquared <== (treasureCoord[1] - userPrevCoord[1]) * (treasureCoord[1] - userPrevCoord[1]); | ||
prevDist <== prevXDiffSquared + prevYDiffSquared; | ||
|
||
currXDiffSquared <== (treasureCoord[0] - userCurrCoord[0]) * (treasureCoord[0] - userCurrCoord[0]); | ||
currYDiffSquared <== (treasureCoord[1] - userCurrCoord[1]) * (treasureCoord[1] - userCurrCoord[1]); | ||
currDist <== currXDiffSquared + currYDiffSquared; | ||
|
||
lt.in[0] <== currDist; | ||
lt.in[1] <== prevDist; | ||
isCloser <== lt.out; | ||
} | ||
|
||
// component main {public [userPrevCoord, userCurrCoord]} = isCloser(); | ||
|
||
/* INPUT = { | ||
"treasureCoord": ["12345", "12345"], | ||
"userPrevCoord": ["12343", "12343"], | ||
"userCurrCoord": ["12344", "123444"] | ||
}*/ |
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,43 @@ | ||
pragma circom 2.0.0; | ||
|
||
// TODO Add Range Check | ||
|
||
include "../node_modules/circomlib/circuits/comparators.circom"; | ||
|
||
template isFurther() { | ||
signal input treasureCoord[2]; | ||
signal input userPrevCoord[2]; | ||
signal input userCurrCoord[2]; | ||
|
||
signal prevXDiffSquared; | ||
signal prevYDiffSquared; | ||
signal prevDist; | ||
|
||
signal currXDiffSquared; | ||
signal currYDiffSquared; | ||
signal currDist; | ||
|
||
signal output isFurther; | ||
|
||
component gt = GreaterThan(64); | ||
|
||
prevXDiffSquared <== (treasureCoord[0] - userPrevCoord[0]) * (treasureCoord[0] - userPrevCoord[0]); | ||
prevYDiffSquared <== (treasureCoord[1] - userPrevCoord[1]) * (treasureCoord[1] - userPrevCoord[1]); | ||
prevDist <== prevXDiffSquared + prevYDiffSquared; | ||
|
||
currXDiffSquared <== (treasureCoord[0] - userCurrCoord[0]) * (treasureCoord[0] - userCurrCoord[0]); | ||
currYDiffSquared <== (treasureCoord[1] - userCurrCoord[1]) * (treasureCoord[1] - userCurrCoord[1]); | ||
currDist <== currXDiffSquared + currYDiffSquared; | ||
|
||
gt.in[0] <== currDist; | ||
gt.in[1] <== prevDist; | ||
isFurther <== gt.out; | ||
} | ||
|
||
component main {public [userPrevCoord, userCurrCoord]} = isFurther(); | ||
|
||
/* INPUT = { | ||
"treasureCoord": ["12345", "12345"], | ||
"userPrevCoord": ["12343", "12343"], | ||
"userCurrCoord": ["12344", "12344"] | ||
}*/ |
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,37 @@ | ||
pragma circom 2.0.0; | ||
|
||
// TODO Add Range Check | ||
|
||
include "../node_modules/circomlib/circuits/comparators.circom"; | ||
|
||
template isTreasure() { | ||
signal input treasureCoord[2]; | ||
signal input userCoord[2]; | ||
|
||
signal xDiffSquared; | ||
signal yDiffSquared; | ||
signal dist; | ||
|
||
signal output isTreasure; | ||
|
||
component iz = IsZero(); | ||
|
||
xDiffSquared <== (treasureCoord[0] - userCoord[0]) * (treasureCoord[0] - userCoord[0]); | ||
yDiffSquared <== (treasureCoord[1] - userCoord[1]) * (treasureCoord[1] - userCoord[1]); | ||
dist <== xDiffSquared + yDiffSquared; | ||
|
||
iz.in <== dist; | ||
isTreasure <== iz.out; | ||
} | ||
|
||
component main {public [userCoord]} = isTreasure(); | ||
|
||
/* INPUT = { | ||
"treasureCoord": ["12345", "12345"], | ||
"userCoord": ["12345", "12345"] | ||
}*/ | ||
|
||
/* INPUT = { | ||
"treasureCoord": ["12345", "12345"], | ||
"userCoord": ["12345", "12344"] | ||
}*/ |
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,14 @@ | ||
{ | ||
"treasureCoord": [ | ||
"12345", | ||
"12345" | ||
], | ||
"userPrevCoord": [ | ||
"12343", | ||
"12343" | ||
], | ||
"userCurrCoord": [ | ||
"12344", | ||
"123444" | ||
] | ||
} |
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,11 @@ | ||
{ | ||
"isCloser": { | ||
"file": "isCloser", | ||
"template": "isCloser", | ||
"pubs": [ | ||
"treasureCoord", | ||
"userPrevCoord", | ||
"userCurrCoord" | ||
] | ||
} | ||
} |
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.