Skip to content

Commit

Permalink
Fix bignumber convert to number overflow issue [NO-CHANGELOG] (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
carmen0208 committed Jul 31, 2023
1 parent 563079a commit 8f5bdf8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export interface ZkEvmTransactionData {
'metaTransactions': Array<MetaTransaction>;
/**
* The nonce value
* @type {number}
* @type {string}
* @memberof ZkEvmTransactionData
*/
'nonce': number;
'nonce': string;
}

2 changes: 1 addition & 1 deletion packages/passport/sdk/src/guardian/guardian.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('guardian', () => {
await expect(
guardianClient.validateEVMTransaction({
chainId: 'epi123',
nonce: 5,
nonce: '5',
user: mockUserZkEvm,
metaTransactions: [
{
Expand Down
8 changes: 4 additions & 4 deletions packages/passport/sdk/src/guardian/guardian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ export type GuardianValidateParams = {

type GuardianEVMValidationParams = {
chainId: string,
nonce: number,
nonce: string,
user: UserZkEvm,
metaTransactions: MetaTransaction[],
};

export const convertBigNumberishToNumber = (value: ethers.BigNumberish): number => BigNumber.from(value).toNumber();
export const convertBigNumberishToString = (value: ethers.BigNumberish): string => BigNumber.from(value).toString();

const transformGuardianTransactions = (txs: MetaTransaction[]): guardian.MetaTransaction[] => {
try {
return txs.map((t) => ({
delegateCall: t.delegateCall === true,
revertOnError: t.revertOnError === true,
gasLimit: t.gasLimit ? convertBigNumberishToNumber(t.gasLimit).toString() : '0',
gasLimit: t.gasLimit ? convertBigNumberishToString(t.gasLimit) : '0',
target: t.to ?? ethers.constants.AddressZero,
value: t.value ? convertBigNumberishToNumber(t.value).toString() : '0',
value: t.value ? convertBigNumberishToString(t.value) : '0',
data: t.data ? t.data.toString() : '0x00',
}));
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/passport/sdk/src/zkEvm/sendTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('sendTransaction', () => {
loading: jest.fn(),
};

const nonce = 5;
const nonce = '5';
const config: Partial<PassportConfiguration> = {
zkEvmChainId: 'eip155:13392',
};
Expand Down
4 changes: 2 additions & 2 deletions packages/passport/sdk/src/zkEvm/sendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { retryWithDelay } from '../network/retry';
import { PassportConfiguration } from '../config';
import { RelayerClient } from './relayerClient';
import { UserZkEvm } from '../types';
import GuardianClient, { convertBigNumberishToNumber } from '../guardian/guardian';
import GuardianClient, { convertBigNumberishToString } from '../guardian/guardian';

const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
Expand Down Expand Up @@ -87,7 +87,7 @@ export const sendTransaction = async ({

await guardianClient.validateEVMTransaction({
chainId: config.zkEvmChainId,
nonce: convertBigNumberishToNumber(nonce),
nonce: convertBigNumberishToString(nonce),
user,
metaTransactions: [metaTransaction, feeMetaTransaction],
});
Expand Down

0 comments on commit 8f5bdf8

Please sign in to comment.