Skip to content

Commit

Permalink
fix(eddsa-poseidon): handles the negative case
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahredler committed Oct 25, 2024
1 parent 8e67348 commit 5ea90de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/eddsa-poseidon/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ export function checkMessage(message: BigNumberish): bigint {
? bigNumberishToBigInt(message)
: bufferToBigInt(Buffer.from(message as string))

const maxLength = 2n ** 256n / 2n - 1n
if (bigIntMessage > maxLength) throw new Error(`Message length is larger than 32 bytes`)
const maxLength = 2n ** 256n / 2n
if (bigIntMessage < maxLength * -1n || bigIntMessage >= maxLength)
throw new Error(`Message length is larger than 32 bytes`)
return bigIntMessage
}

Expand Down
10 changes: 9 additions & 1 deletion packages/eddsa-poseidon/tests/eddsa-poseidon-blake1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@ describe("EdDSAPoseidon", () => {
})

it("Should throw an error if the message is larger than 32 Bytes [number]", async () => {
const message = 2 ** 256 / 2
const message = 2 ** 255

const fun = () => signMessage(privateKey, message)

expect(fun).toThrow(`Message length is larger than 32 bytes`)
})

it("Should throw an error if the message is larger than 32 Bytes [-number]", async () => {
const message = -(2n ** 255n + 1n)

const fun = () => signMessage(privateKey, message)

Expand Down

0 comments on commit 5ea90de

Please sign in to comment.