Skip to content

Commit

Permalink
fix(poll): joiningCircuitInputs with correct siblings, indices and ac…
Browse files Browse the repository at this point in the history
…tualStateTreeDepth
  • Loading branch information
djanluka committed Aug 20, 2024
1 parent 5fd48d2 commit 8abe1ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 7 additions & 5 deletions cli/ts/commands/joinPoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const joiningCircuitInputs = (

// calculate the path elements for the state tree given the original state tree
const { siblings, index } = stateTree.generateProof(Number(stateLeafIndex));
const depth = siblings.length;
const siblingsLength = siblings.length;

// The index must be converted to a list of indices, 1 for each tree level.
// The circuit tree depth is this.stateTreeDepth, so the number of siblings must be this.stateTreeDepth,
Expand All @@ -58,20 +58,22 @@ const joiningCircuitInputs = (
// eslint-disable-next-line no-bitwise
indices.push(BigInt((index >> i) & 1));

if (i >= depth) {
if (i >= siblingsLength) {
siblings[i] = BigInt(0);
}
}

const siblingsArray = siblings.map((sibling) => [sibling]);

// Create nullifier from private key
const inputNullifier = BigInt(maciPrivKey.asCircuitInputs());
const nullifier = poseidon([inputNullifier]);

// Get pll state tree's root
const stateRoot = stateTree.root;

// Convert actualStateTreeDepth to BigInt
const actualStateTreeDepth = BigInt(stateTree.depth);
// Set actualStateTreeDepth as number of initial siblings length
const actualStateTreeDepth = BigInt(siblingsLength);

// Calculate public input hash from nullifier, credits and current root
const inputHash = sha256Hash([nullifier, credits, stateRoot, pollPubKeyArray[0], pollPubKeyArray[1]]);
Expand All @@ -81,7 +83,7 @@ const joiningCircuitInputs = (
pollPrivKey: pollPrivKey.asCircuitInputs(),
pollPubKey: pollPubKey.asCircuitInputs(),
stateLeaf: stateLeafArray,
siblings,
siblings: siblingsArray,
indices,
nullifier,
credits,
Expand Down
11 changes: 6 additions & 5 deletions core/ts/Poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ export class Poll implements IPoll {

// calculate the path elements for the state tree given the original state tree
const { siblings, index } = this.stateTree!.generateProof(Number(stateLeafIndex));
const depth = siblings.length;
const siblingsLength = siblings.length;

// The index must be converted to a list of indices, 1 for each tree level.
// The circuit tree depth is this.stateTreeDepth, so the number of siblings must be this.stateTreeDepth,
Expand All @@ -468,10 +468,11 @@ export class Poll implements IPoll {
// eslint-disable-next-line no-bitwise
indices.push(BigInt((index >> i) & 1));

if (i >= depth) {
if (i >= siblingsLength) {
siblings[i] = BigInt(0);
}
}
const siblingsArray = siblings.map((sibling) => [sibling]);

// Create nullifier from private key
const inputNullifier = BigInt(maciPrivKey.asCircuitInputs());
Expand All @@ -480,8 +481,8 @@ export class Poll implements IPoll {
// Get pll state tree's root
const stateRoot = this.stateTree!.root;

// Convert actualStateTreeDepth to BigInt
const actualStateTreeDepth = BigInt(this.actualStateTreeDepth);
// Set actualStateTreeDepth as number of initial siblings length
const actualStateTreeDepth = BigInt(siblingsLength);

// Calculate public input hash from nullifier, credits and current root
const inputHash = sha256Hash([nullifier, credits, stateRoot, pollPubKeyArray[0], pollPubKeyArray[1]]);
Expand All @@ -491,7 +492,7 @@ export class Poll implements IPoll {
pollPrivKey: pollPrivKey.asCircuitInputs(),
pollPubKey: pollPubKey.asCircuitInputs(),
stateLeaf: stateLeafArray,
siblings,
siblings: siblingsArray,
indices,
nullifier,
credits,
Expand Down

0 comments on commit 8abe1ee

Please sign in to comment.