From 1779ed30139fc4a2ffd96ab89d9d367ea4e782ee Mon Sep 17 00:00:00 2001 From: Sasha Mitchell Date: Fri, 25 Sep 2026 16:27:08 +0700 Subject: [PATCH] Reject non-integer EIP-7702 chainId and nonce. NaN passed the number check and still hashed. Number.isInteger rejects it before the authorization is signed or recovered. --- src/sign-eip7702-authorization.test.ts | 20 ++++++++++++++++++++ src/sign-eip7702-authorization.ts | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/sign-eip7702-authorization.test.ts b/src/sign-eip7702-authorization.test.ts index f44fe5c9..68e547cc 100644 --- a/src/sign-eip7702-authorization.test.ts +++ b/src/sign-eip7702-authorization.test.ts @@ -118,6 +118,17 @@ describe('signAuthorization', () => { ); }); + it('should throw if chainId is NaN', () => { + expect(() => + signEIP7702Authorization({ + privateKey: TEST_PRIVATE_KEY, + authorization: [NaN, TEST_AUTHORIZATION[1], TEST_AUTHORIZATION[2]], + }), + ).toThrow( + 'Invalid chainId: must be a non-negative number less than 2^256', + ); + }); + it('should throw if chainId is negative', () => { expect(() => signEIP7702Authorization({ @@ -155,6 +166,15 @@ describe('signAuthorization', () => { ).toThrow('Invalid nonce: must be a non-negative number less than 2^64'); }); + it('should throw if nonce is NaN', () => { + expect(() => + signEIP7702Authorization({ + privateKey: TEST_PRIVATE_KEY, + authorization: [TEST_AUTHORIZATION[0], TEST_AUTHORIZATION[1], NaN], + }), + ).toThrow('Invalid nonce: must be a non-negative number less than 2^64'); + }); + it('should throw if nonce is negative', () => { expect(() => signEIP7702Authorization({ diff --git a/src/sign-eip7702-authorization.ts b/src/sign-eip7702-authorization.ts index 52ce75ed..ccf7030b 100644 --- a/src/sign-eip7702-authorization.ts +++ b/src/sign-eip7702-authorization.ts @@ -133,6 +133,7 @@ function validateEIP7702Authorization(authorization: EIP7702Authorization) { if ( typeof chainId !== 'number' || + !Number.isInteger(chainId) || chainId >= 2 ** CHAIN_ID_MAX_BITLENGTH || chainId < 0 ) { @@ -143,6 +144,7 @@ function validateEIP7702Authorization(authorization: EIP7702Authorization) { if ( typeof nonce !== 'number' || + !Number.isInteger(nonce) || nonce >= 2 ** NONCE_MAX_BITLENGTH || nonce < 0 ) {