Skip to content

Commit

Permalink
Merge pull request #255 from privacy-scaling-explorations/fix/inv
Browse files Browse the repository at this point in the history
Add check for F1Field `inv(0n)`
  • Loading branch information
cedoor authored Apr 22, 2024
2 parents 39b1a51 + dbc7c70 commit 7843c51
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/utils/src/f1-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export default class F1Field {
* @throws if 'a' is zero.
*/
inv(a: bigint): bigint {
if (a === this.zero) {
throw new Error("Zero has no inverse")
}

let t = this.zero
let r = this._order
let newt = this.one
Expand Down
4 changes: 3 additions & 1 deletion packages/utils/tests/f1-field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ describe("F1Field", () => {

expect(field.inv(a)).toBe(7n)
expect(field.inv(b)).toBe(6n)
})

expect(field.inv(0n)).toBe(0n)
it("Should throw an error if inv input is 0", () => {
expect(() => field.inv(0n)).toThrow("Zero has no inverse")
})

it("Should lt into the finite field", () => {
Expand Down

0 comments on commit 7843c51

Please sign in to comment.