mirror of
https://github.com/semaphore-protocol/semaphore.git
synced 2026-01-09 14:48:12 -05:00
added require revert strings to contracts; modified semaphore contract test to check for said strings (#21)
upgraded snarkjs commit hash
added revert reason test for verifier-gte-snark-scalar-field
updated package-lock.json and circleci snark file cache
Former-commit-id: ca9dbb7f98
This commit is contained in:
@@ -19,14 +19,14 @@ jobs:
|
||||
- restore_cache:
|
||||
name: restore-npm-cache
|
||||
keys:
|
||||
- v1.6-dependencies-{{ checksum "package-lock.json" }}
|
||||
- v1.7-dependencies-{{ checksum "package-lock.json" }}
|
||||
|
||||
- run: npm install
|
||||
|
||||
- save_cache:
|
||||
paths:
|
||||
- node_modules
|
||||
key: v1.6-dependencies-{{ checksum "package-lock.json" }}
|
||||
key: v1.7-dependencies-{{ checksum "package-lock.json" }}
|
||||
|
||||
# checksum the snarks definitions
|
||||
- run:
|
||||
@@ -37,7 +37,7 @@ jobs:
|
||||
- restore_cache:
|
||||
name: restore-snark-cache
|
||||
keys:
|
||||
- v1.6-dependencies-{{ checksum "build/.snark_checksum" }}
|
||||
- v1.7-dependencies-{{ checksum "build/.snark_checksum" }}
|
||||
|
||||
# build snarks
|
||||
- run:
|
||||
@@ -47,7 +47,7 @@ jobs:
|
||||
|
||||
# cache generated snark circuit and keys
|
||||
- save_cache:
|
||||
key: v1.6-dependencies-{{ checksum "build/.snark_checksum" }}
|
||||
key: v1.7-dependencies-{{ checksum "build/.snark_checksum" }}
|
||||
paths:
|
||||
- build/circuit.json
|
||||
- build/proving_key.bin
|
||||
|
||||
@@ -129,7 +129,7 @@ contract MultipleMerkleTree {
|
||||
current_index /= 2;
|
||||
}
|
||||
|
||||
require(tree_roots[tree_index] == current_level_hash);
|
||||
require(tree_roots[tree_index] == current_level_hash, "MultipleMerkleTree: tree root / current level hash mismatch");
|
||||
|
||||
current_index = leaf_index;
|
||||
|
||||
|
||||
@@ -82,6 +82,20 @@ contract Semaphore is Verifier, MultipleMerkleTree, Ownable {
|
||||
verifyProof(a, b, c, input);
|
||||
}
|
||||
|
||||
function preBroadcastRequire (
|
||||
uint[2] memory a,
|
||||
uint[2][2] memory b,
|
||||
uint[2] memory c,
|
||||
uint[5] memory input,
|
||||
uint256 signal_hash
|
||||
) public {
|
||||
require(hasNullifier(input[1]) == false, "Semaphore: nullifier already seen");
|
||||
require(signal_hash == input[2], "Semaphore: signal hash mismatch");
|
||||
require(external_nullifier == input[3], "Semaphore: external nullifier mismatch");
|
||||
require(isInRootHistory(input[0]), "Semaphore: root not seen");
|
||||
require(verifyProof(a, b, c, input), "Semaphore: invalid proof");
|
||||
}
|
||||
|
||||
function broadcastSignal(
|
||||
bytes memory signal,
|
||||
uint[2] memory a,
|
||||
@@ -89,14 +103,15 @@ contract Semaphore is Verifier, MultipleMerkleTree, Ownable {
|
||||
uint[2] memory c,
|
||||
uint[5] memory input // (root, nullifiers_hash, signal_hash, external_nullifier, broadcaster_address)
|
||||
) public {
|
||||
// Hash the signal
|
||||
uint256 signal_hash = uint256(sha256(signal)) >> 8;
|
||||
|
||||
// Check the inputs
|
||||
require(preBroadcastCheck(a, b, c, input, signal_hash) == true);
|
||||
preBroadcastRequire(a, b, c, input, signal_hash);
|
||||
|
||||
// Verify the broadcaster's address
|
||||
address broadcaster = address(input[4]);
|
||||
require(broadcaster == msg.sender);
|
||||
require(broadcaster == msg.sender, "Semaphore: wrong broadcaster's address");
|
||||
|
||||
signals[current_signal_index++] = signal;
|
||||
nullifiers_set[input[1]] = true;
|
||||
|
||||
@@ -1 +1 @@
|
||||
39124ef55318abd5836f3deab4a24e5f8854c840
|
||||
6cc0f357770fdccb6bb3309b36820135fac84434
|
||||
@@ -33,7 +33,7 @@
|
||||
"node-fetch": "^2.3.0",
|
||||
"require-nocache": "^1.0.0",
|
||||
"semaphore-merkle-tree": "^1.0.4",
|
||||
"snarkjs": "git+https://github.com/iden3/snarkjs.git#f8ba7cbfa7d526e186fd3a706be00f63b65812d8",
|
||||
"snarkjs": "git+https://github.com/iden3/snarkjs.git#c428706ef69930e378c31199ff8d66ee13fada85",
|
||||
"truffle": "^5.0.10",
|
||||
"truffle-artifactor": "^4.0.10",
|
||||
"truffle-contract": "^4.0.11",
|
||||
|
||||
@@ -190,6 +190,8 @@ contract('Semaphore', function (accounts) {
|
||||
const publicSignals = w.slice(1, circuit.nPubInputs + circuit.nOutputs+1);
|
||||
const proof = await proof_util.prove(witness_bin.buffer, vk_proof.buffer);
|
||||
let failed = false;
|
||||
let reason = '';
|
||||
|
||||
try {
|
||||
await semaphore.broadcastSignal(
|
||||
signal_to_contract,
|
||||
@@ -200,8 +202,10 @@ contract('Semaphore', function (accounts) {
|
||||
);
|
||||
} catch(e) {
|
||||
failed = true;
|
||||
reason = e.reason
|
||||
}
|
||||
assert.equal(failed, true);
|
||||
assert.equal(reason, 'Semaphore: root not seen');
|
||||
|
||||
failed = false;
|
||||
try {
|
||||
@@ -214,8 +218,10 @@ contract('Semaphore', function (accounts) {
|
||||
);
|
||||
} catch(e) {
|
||||
failed = true;
|
||||
reason = e.reason
|
||||
}
|
||||
assert.equal(failed, true);
|
||||
assert.equal(reason, 'verifier-gte-snark-scalar-field');
|
||||
|
||||
const a = [ proof.pi_a[0].toString(), proof.pi_a[1].toString() ]
|
||||
const b = [ [ proof.pi_b[0][1].toString(), proof.pi_b[0][0].toString() ], [ proof.pi_b[1][1].toString(), proof.pi_b[1][0].toString() ] ]
|
||||
|
||||
Reference in New Issue
Block a user