-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Value Commitment operator #125
Open
OBrezhniev
wants to merge
4
commits into
develop
Choose a base branch
from
feature/valueCommitment
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 @@ | ||
pragma circom 2.1.1; | ||
|
||
include "../../../node_modules/circomlib/circuits/mux1.circom"; | ||
include "../../../node_modules/circomlib/circuits/comparators.circom"; | ||
include "../../../node_modules/circomlib/circuits/poseidon.circom"; | ||
|
||
/** | ||
Value commitment circuit allows to commit to a specific value and then | ||
reveal it later or use such a commitment in another circuits to prove that | ||
multiple circuits work with the same value without revealing it. | ||
*/ | ||
|
||
template ValueCommitment() { | ||
signal input value; | ||
signal input commitNonce; // private random nonce to make the commitment unique and secure | ||
|
||
signal output out; | ||
|
||
signal isNonceZero <== IsZero()(commitNonce); | ||
|
||
signal commit <== Poseidon(2)([value, commitNonce]); | ||
|
||
out <== Mux1()( | ||
[commit, 0], | ||
isNonceZero | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pragma circom 2.1.1; | ||
|
||
include "../../../circuits/lib/query/valueCommitment.circom"; | ||
|
||
component main = ValueCommitment(); |
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,31 @@ | ||
import {describe} from "mocha"; | ||
|
||
const path = require("path"); | ||
const wasm_tester = require("circom_tester").wasm; | ||
|
||
|
||
describe("ValueCommitment test", function () { | ||
let valueCommitmentCircuit; | ||
|
||
before(async function () { | ||
valueCommitmentCircuit = await wasm_tester(path.join(__dirname, "../circuits/query/", "valueCommitmentTest.circom")); | ||
}); | ||
|
||
it("should commit a value with a non-zero nonce", async () => { | ||
const inputs = { value: "5", commitNonce: "7" }; | ||
const expectedOut = { out: "21007229687521157814825902919006068496120320911167801732994749038798743998593" }; | ||
|
||
const witness = await valueCommitmentCircuit.calculateWitness(inputs, true); | ||
await valueCommitmentCircuit.assertOut(witness, expectedOut); | ||
await valueCommitmentCircuit.checkConstraints(witness); | ||
}); | ||
|
||
it("should return zero for a commit with zero nonce", async () => { | ||
const inputs = { value: "10", commitNonce: "0" }; | ||
const expectedOut = { out: "0" }; | ||
|
||
const witness = await valueCommitmentCircuit.calculateWitness(inputs, true); | ||
await valueCommitmentCircuit.assertOut(witness, expectedOut); | ||
await valueCommitmentCircuit.checkConstraints(witness); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I can receive the same commitment if I have another field with the same value and provide the same commitment outside. (I want to prove that I have the same date of birth in the different creds, but I can hack and prove that some another date that I have in other credential is equal to expected, but it is not the same meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a hack. Maybe user wants to prove to verifier that on his day of birth there was a sun eclipse. It's ok.
We don't have a way to check meaning of fields and we shouldn't. User needs to check what verifier asks from him - does it make sense.