Skip to content

Commit

Permalink
fix(group): add check for zero values in group constructor (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedoor authored May 2, 2024
1 parent f8deb64 commit 87f6345
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/group/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export class Group {
* @param members A list of identity commitments.
*/
constructor(members: BigNumber[] = []) {
for (const member of members) {
if (member === 0n || member === "0") {
throw new Error("Failed to add member: value cannot be 0")
}
}

this.leanIMT = new LeanIMT((a, b) => poseidon2([a, b]), members.map(BigInt))
}

Expand Down
6 changes: 6 additions & 0 deletions packages/group/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ describe("Group", () => {
expect(group.depth).toBe(2)
expect(group.size).toBe(3)
})

it("Should not create a group with a list of members if any value is 0", () => {
const fun = () => new Group([1n, 0n])

expect(fun).toThrow("Failed to add member: value cannot be 0")
})
})

describe("# addMember", () => {
Expand Down

0 comments on commit 87f6345

Please sign in to comment.