reduce nullifier bits to 31

This commit is contained in:
poma 2019-08-01 17:49:34 +03:00
parent e387025992
commit c7953ae2c6
No known key found for this signature in database
GPG Key ID: 530BBEE4AE8C3604
3 changed files with 16 additions and 16 deletions

View File

@ -10,16 +10,16 @@ template CommitmentHasher() {
signal output commitment; signal output commitment;
signal output nullifierHash; signal output nullifierHash;
component commitmentHasher = Pedersen(512); component commitmentHasher = Pedersen(496);
component nullifierHasher = Pedersen(256); component nullifierHasher = Pedersen(248);
component nullifierBits = Num2Bits(256); component nullifierBits = Num2Bits(248);
component secretBits = Num2Bits(256); component secretBits = Num2Bits(248);
nullifierBits.in <== nullifier; nullifierBits.in <== nullifier;
secretBits.in <== secret; secretBits.in <== secret;
for (var i = 0; i < 256; i++) { for (var i = 0; i < 248; i++) {
nullifierHasher.in[i] <== nullifierBits.out[i]; nullifierHasher.in[i] <== nullifierBits.out[i];
commitmentHasher.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]; commitment <== commitmentHasher.out[0];

4
cli.js
View File

@ -21,7 +21,7 @@ const pedersenHash = (data) => circomlib.babyJub.unpackPoint(circomlib.pedersenH
function createDeposit(nullifier, secret) { function createDeposit(nullifier, secret) {
let deposit = { 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) deposit.commitment = pedersenHash(deposit.preimage)
return deposit return deposit
} }
@ -61,7 +61,7 @@ async function withdraw(note, receiver) {
}) })
const tree = new merkleTree(MERKLE_TREE_HEIGHT, EMPTY_ELEMENT, leaves) const tree = new merkleTree(MERKLE_TREE_HEIGHT, EMPTY_ELEMENT, leaves)
const validRoot = await mixer.methods.isKnownRoot(await tree.root()).call() 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 nullifierHashToCheck = nullifierHash.toString(16).padStart('66', '0x000000')
const isSpent = await mixer.methods.isSpent(nullifierHashToCheck).call() const isSpent = await mixer.methods.isSpent(nullifierHashToCheck).call()
assert(validRoot === true) assert(validRoot === true)

View File

@ -29,7 +29,7 @@ function generateDeposit() {
secret: rbigint(31), secret: rbigint(31),
nullifier: 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) deposit.commitment = pedersenHash(preimage)
return deposit return deposit
} }
@ -127,7 +127,7 @@ contract('Mixer', accounts => {
const input = stringifyBigInts({ const input = stringifyBigInts({
root, root,
nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)), nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(31)),
nullifier: deposit.nullifier, nullifier: deposit.nullifier,
receiver, receiver,
fee, fee,
@ -180,7 +180,7 @@ contract('Mixer', accounts => {
const input = stringifyBigInts({ const input = stringifyBigInts({
// public // public
root, root,
nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)), nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(31)),
receiver, receiver,
fee, fee,
@ -228,7 +228,7 @@ contract('Mixer', accounts => {
const input = stringifyBigInts({ const input = stringifyBigInts({
root, root,
nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)), nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(31)),
nullifier: deposit.nullifier, nullifier: deposit.nullifier,
receiver, receiver,
fee, fee,
@ -252,7 +252,7 @@ contract('Mixer', accounts => {
const input = stringifyBigInts({ const input = stringifyBigInts({
root, root,
nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)), nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(31)),
nullifier: deposit.nullifier, nullifier: deposit.nullifier,
receiver, receiver,
fee, fee,
@ -276,7 +276,7 @@ contract('Mixer', accounts => {
const oneEtherFee = bigInt(1e18) // 1 ether const oneEtherFee = bigInt(1e18) // 1 ether
const input = stringifyBigInts({ const input = stringifyBigInts({
root, root,
nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)), nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(31)),
nullifier: deposit.nullifier, nullifier: deposit.nullifier,
receiver, receiver,
fee: oneEtherFee, fee: oneEtherFee,
@ -299,7 +299,7 @@ contract('Mixer', accounts => {
const { root, path_elements, path_index } = await tree.path(0) const { root, path_elements, path_index } = await tree.path(0)
const input = stringifyBigInts({ const input = stringifyBigInts({
nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)), nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(31)),
root, root,
nullifier: deposit.nullifier, nullifier: deposit.nullifier,
receiver, receiver,
@ -327,7 +327,7 @@ contract('Mixer', accounts => {
const input = stringifyBigInts({ const input = stringifyBigInts({
root, root,
nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)), nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(31)),
nullifier: deposit.nullifier, nullifier: deposit.nullifier,
receiver, receiver,
fee, fee,