diff --git a/circuits/withdraw.circom b/circuits/withdraw.circom index 01fee0a..35f6fa5 100644 --- a/circuits/withdraw.circom +++ b/circuits/withdraw.circom @@ -10,16 +10,16 @@ template CommitmentHasher() { signal output commitment; signal output nullifierHash; - component commitmentHasher = Pedersen(512); - component nullifierHasher = Pedersen(256); - component nullifierBits = Num2Bits(256); - component secretBits = Num2Bits(256); + component commitmentHasher = Pedersen(496); + component nullifierHasher = Pedersen(248); + component nullifierBits = Num2Bits(248); + component secretBits = Num2Bits(248); nullifierBits.in <== nullifier; secretBits.in <== secret; - for (var i = 0; i < 256; i++) { + for (var i = 0; i < 248; i++) { nullifierHasher.in[i] <== nullifierBits.out[i]; commitmentHasher.in[i] <== nullifierBits.out[i]; - commitmentHasher.in[i + 256] <== secretBits.out[i]; + commitmentHasher.in[i + 248] <== secretBits.out[i]; } commitment <== commitmentHasher.out[0]; diff --git a/cli.js b/cli.js index 45e980e..96aeb6c 100755 --- a/cli.js +++ b/cli.js @@ -21,7 +21,7 @@ const pedersenHash = (data) => circomlib.babyJub.unpackPoint(circomlib.pedersenH function createDeposit(nullifier, secret) { let deposit = { nullifier, secret } - deposit.preimage = Buffer.concat([deposit.nullifier.leInt2Buff(32), deposit.secret.leInt2Buff(32)]) + deposit.preimage = Buffer.concat([deposit.nullifier.leInt2Buff(31), deposit.secret.leInt2Buff(31)]) deposit.commitment = pedersenHash(deposit.preimage) return deposit } @@ -61,7 +61,7 @@ async function withdraw(note, receiver) { }) const tree = new merkleTree(MERKLE_TREE_HEIGHT, EMPTY_ELEMENT, leaves) const validRoot = await mixer.methods.isKnownRoot(await tree.root()).call() - const nullifierHash = pedersenHash(deposit.nullifier.leInt2Buff(32)) + const nullifierHash = pedersenHash(deposit.nullifier.leInt2Buff(31)) const nullifierHashToCheck = nullifierHash.toString(16).padStart('66', '0x000000') const isSpent = await mixer.methods.isSpent(nullifierHashToCheck).call() assert(validRoot === true) diff --git a/test/Mixer.test.js b/test/Mixer.test.js index c8746ce..7b66669 100644 --- a/test/Mixer.test.js +++ b/test/Mixer.test.js @@ -29,7 +29,7 @@ function generateDeposit() { secret: rbigint(31), nullifier: rbigint(31), } - const preimage = Buffer.concat([deposit.nullifier.leInt2Buff(32), deposit.secret.leInt2Buff(32)]) + const preimage = Buffer.concat([deposit.nullifier.leInt2Buff(31), deposit.secret.leInt2Buff(31)]) deposit.commitment = pedersenHash(preimage) return deposit } @@ -138,7 +138,7 @@ contract('Mixer', accounts => { const input = stringifyBigInts({ root, - nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)), + nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(31)), nullifier: deposit.nullifier, receiver, fee, @@ -194,7 +194,7 @@ contract('Mixer', accounts => { const input = stringifyBigInts({ // public root, - nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)), + nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(31)), receiver, fee, @@ -245,7 +245,7 @@ contract('Mixer', accounts => { const input = stringifyBigInts({ root, - nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)), + nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(31)), nullifier: deposit.nullifier, receiver, fee, @@ -269,7 +269,7 @@ contract('Mixer', accounts => { const input = stringifyBigInts({ root, - nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)), + nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(31)), nullifier: deposit.nullifier, receiver, fee, @@ -293,7 +293,7 @@ contract('Mixer', accounts => { const oneEtherFee = bigInt(1e18) // 1 ether const input = stringifyBigInts({ root, - nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)), + nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(31)), nullifier: deposit.nullifier, receiver, fee: oneEtherFee, @@ -316,7 +316,7 @@ contract('Mixer', accounts => { const { root, path_elements, path_index } = await tree.path(0) const input = stringifyBigInts({ - nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)), + nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(31)), root, nullifier: deposit.nullifier, receiver, @@ -344,7 +344,7 @@ contract('Mixer', accounts => { const input = stringifyBigInts({ root, - nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)), + nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(31)), nullifier: deposit.nullifier, receiver, fee,