Skip to content

Commit b5f4f0f

Browse files
authored
fix: remove supported chains check (#29773)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29773?quickstart=1) ## **Related issues** Fixes: MetaMask/MetaMask-planning#3940 ## **Manual testing steps** 1. Go to the test dapp 2. Perform transactions and signatures in the section `PPOM - Malicious Transactions and Signatures` 3. Test one previous supported chain and another chain outside the list below: ``` // previous supported chains ARBITRUM = '0xa4b1' AVALANCHE = '0xa86a' BASE = '0x2105' BERACHAIN = '0x138d4' BSC = '0x38' LINEA_MAINNET = '0xe708' MAINNET = '0x1' METACHAIN_ONE = '0x1b6e6' OPBNB = '0xcc' OPTIMISM = '0xa' POLYGON = '0x89' SCROLL = '0x82750' SEPOLIA = '0xaa36a7' ZKSYNC_ERA = '0x144' ``` ## **Screenshots/Recordings** [Screencast from 2025-01-28 14-56-38.webm](https://github.com/user-attachments/assets/a7fdf9ca-d34d-407b-93b9-5191e6279ca1) <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent de15960 commit b5f4f0f

File tree

13 files changed

+44
-185
lines changed

13 files changed

+44
-185
lines changed

app/scripts/lib/ppom/ppom-middleware.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { createPPOMMiddleware, PPOMMiddlewareRequest } from './ppom-middleware';
1212
import {
1313
generateSecurityAlertId,
1414
handlePPOMError,
15-
isChainSupported,
1615
validateRequestWithPPOM,
1716
} from './ppom-util';
1817
import { SecurityAlertResponse } from './types';
@@ -106,15 +105,13 @@ const createMiddleware = (
106105
describe('PPOMMiddleware', () => {
107106
const generateSecurityAlertIdMock = jest.mocked(generateSecurityAlertId);
108107
const handlePPOMErrorMock = jest.mocked(handlePPOMError);
109-
const isChainSupportedMock = jest.mocked(isChainSupported);
110108
const detectSIWEMock = jest.mocked(detectSIWE);
111109

112110
beforeEach(() => {
113111
jest.resetAllMocks();
114112

115113
generateSecurityAlertIdMock.mockReturnValue(SECURITY_ALERT_ID_MOCK);
116114
handlePPOMErrorMock.mockReturnValue(SECURITY_ALERT_RESPONSE_MOCK);
117-
isChainSupportedMock.mockResolvedValue(true);
118115
detectSIWEMock.mockReturnValue({ isSIWEMessage: false } as SIWEMessage);
119116

120117
globalThis.sentry = {
@@ -145,9 +142,7 @@ describe('PPOMMiddleware', () => {
145142
() => undefined,
146143
);
147144

148-
expect(req.securityAlertResponse?.reason).toBe(
149-
BlockaidReason.checkingChain,
150-
);
145+
expect(req.securityAlertResponse?.reason).toBe(BlockaidReason.inProgress);
151146
expect(req.securityAlertResponse?.result_type).toBe(
152147
BlockaidResultType.Loading,
153148
);

app/scripts/lib/ppom/ppom-middleware.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import { MESSAGE_TYPE } from '../../../../shared/constants/app';
1313
import { SIGNING_METHODS } from '../../../../shared/constants/transaction';
1414
import { PreferencesController } from '../../controllers/preferences-controller';
1515
import { AppStateController } from '../../controllers/app-state-controller';
16-
import { SECURITY_ALERT_RESPONSE_CHECKING_CHAIN } from '../../../../shared/constants/security-provider';
1716
import { getProviderConfig } from '../../../../shared/modules/selectors/networks';
1817
import { trace, TraceContext, TraceName } from '../../../../shared/lib/trace';
18+
import { LOADING_SECURITY_ALERT_RESPONSE } from '../../../../shared/constants/security-provider';
1919
import {
2020
generateSecurityAlertId,
2121
handlePPOMError,
@@ -118,18 +118,18 @@ export function createPPOMMiddleware<
118118
}),
119119
);
120120

121-
const securityAlertResponseCheckingChain: SecurityAlertResponse = {
122-
...SECURITY_ALERT_RESPONSE_CHECKING_CHAIN,
121+
const securityAlertResponseLoading: SecurityAlertResponse = {
122+
...LOADING_SECURITY_ALERT_RESPONSE,
123123
securityAlertId,
124124
};
125125

126126
if (SIGNING_METHODS.includes(req.method)) {
127127
appStateController.addSignatureSecurityAlertResponse(
128-
securityAlertResponseCheckingChain,
128+
securityAlertResponseLoading,
129129
);
130130
}
131131

132-
req.securityAlertResponse = securityAlertResponseCheckingChain;
132+
req.securityAlertResponse = securityAlertResponseLoading;
133133
} catch (error) {
134134
req.securityAlertResponse = handlePPOMError(
135135
error,

app/scripts/lib/ppom/ppom-util.test.ts

-55
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ import {
1515
BlockaidReason,
1616
BlockaidResultType,
1717
LOADING_SECURITY_ALERT_RESPONSE,
18-
SECURITY_ALERT_RESPONSE_CHAIN_NOT_SUPPORTED,
1918
SecurityAlertSource,
2019
} from '../../../../shared/constants/security-provider';
2120
import { AppStateController } from '../../controllers/app-state-controller';
2221
import {
2322
generateSecurityAlertId,
24-
isChainSupported,
2523
METHOD_SIGN_TYPED_DATA_V3,
2624
METHOD_SIGN_TYPED_DATA_V4,
2725
updateSecurityAlertResponse,
@@ -114,10 +112,6 @@ describe('PPOM Utils', () => {
114112
const normalizeTransactionParamsMock = jest.mocked(
115113
normalizeTransactionParams,
116114
);
117-
const getSupportedChainIdsMock = jest.spyOn(
118-
securityAlertAPI,
119-
'getSecurityAlertsAPISupportedChainIds',
120-
);
121115
let isSecurityAlertsEnabledMock: jest.SpyInstance;
122116

123117
const updateSecurityAlertResponseMock = jest.fn();
@@ -308,23 +302,6 @@ describe('PPOM Utils', () => {
308302
});
309303
},
310304
);
311-
312-
it('updates response indicating chain is not supported', async () => {
313-
const ppomController = {} as PPOMController;
314-
const CHAIN_ID_UNSUPPORTED_MOCK = '0x2';
315-
316-
await validateRequestWithPPOM({
317-
...validateRequestWithPPOMOptionsBase,
318-
ppomController,
319-
chainId: CHAIN_ID_UNSUPPORTED_MOCK,
320-
});
321-
322-
expect(updateSecurityAlertResponseMock).toHaveBeenCalledWith(
323-
validateRequestWithPPOMOptionsBase.request.method,
324-
SECURITY_ALERT_ID_MOCK,
325-
SECURITY_ALERT_RESPONSE_CHAIN_NOT_SUPPORTED,
326-
);
327-
});
328305
});
329306

330307
describe('generateSecurityAlertId', () => {
@@ -457,36 +434,4 @@ describe('PPOM Utils', () => {
457434
);
458435
});
459436
});
460-
461-
describe('isChainSupported', () => {
462-
describe('when security alerts API is enabled', () => {
463-
beforeEach(async () => {
464-
isSecurityAlertsEnabledMock.mockReturnValue(true);
465-
getSupportedChainIdsMock.mockResolvedValue([CHAIN_ID_MOCK]);
466-
});
467-
468-
it('returns true if chain is supported', async () => {
469-
expect(await isChainSupported(CHAIN_ID_MOCK)).toStrictEqual(true);
470-
});
471-
472-
it('returns false if chain is not supported', async () => {
473-
expect(await isChainSupported('0x2')).toStrictEqual(false);
474-
});
475-
476-
it('returns correctly if security alerts API throws', async () => {
477-
getSupportedChainIdsMock.mockRejectedValue(new Error('Test Error'));
478-
expect(await isChainSupported(CHAIN_ID_MOCK)).toStrictEqual(true);
479-
});
480-
});
481-
482-
describe('when security alerts API is disabled', () => {
483-
it('returns true if chain is supported', async () => {
484-
expect(await isChainSupported(CHAIN_ID_MOCK)).toStrictEqual(true);
485-
});
486-
487-
it('returns false if chain is not supported', async () => {
488-
expect(await isChainSupported('0x2')).toStrictEqual(false);
489-
});
490-
});
491-
});
492437
});

app/scripts/lib/ppom/ppom-util.ts

-28
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ import {
1212
BlockaidReason,
1313
BlockaidResultType,
1414
LOADING_SECURITY_ALERT_RESPONSE,
15-
SECURITY_ALERT_RESPONSE_CHAIN_NOT_SUPPORTED,
16-
SECURITY_PROVIDER_SUPPORTED_CHAIN_IDS_FALLBACK_LIST,
1715
SecurityAlertSource,
1816
} from '../../../../shared/constants/security-provider';
1917
import { SIGNING_METHODS } from '../../../../shared/constants/transaction';
2018
import { AppStateController } from '../../controllers/app-state-controller';
2119
import { SecurityAlertResponse, UpdateSecurityAlertResponse } from './types';
2220
import {
23-
getSecurityAlertsAPISupportedChainIds,
2421
isSecurityAlertsAPIEnabled,
2522
SecurityAlertsAPIRequest,
2623
validateWithSecurityAlertsAPI,
@@ -56,15 +53,6 @@ export async function validateRequestWithPPOM({
5653
updateSecurityAlertResponse: UpdateSecurityAlertResponse;
5754
}) {
5855
try {
59-
if (!(await isChainSupported(chainId))) {
60-
await updateSecurityResponse(
61-
request.method,
62-
securityAlertId,
63-
SECURITY_ALERT_RESPONSE_CHAIN_NOT_SUPPORTED,
64-
);
65-
return;
66-
}
67-
6856
await updateSecurityResponse(
6957
request.method,
7058
securityAlertId,
@@ -151,22 +139,6 @@ export function handlePPOMError(
151139
};
152140
}
153141

154-
export async function isChainSupported(chainId: Hex): Promise<boolean> {
155-
let supportedChainIds = SECURITY_PROVIDER_SUPPORTED_CHAIN_IDS_FALLBACK_LIST;
156-
157-
try {
158-
if (isSecurityAlertsAPIEnabled()) {
159-
supportedChainIds = await getSecurityAlertsAPISupportedChainIds();
160-
}
161-
} catch (error: unknown) {
162-
handlePPOMError(
163-
error,
164-
`Error fetching supported chains from security alerts API`,
165-
);
166-
}
167-
return supportedChainIds.includes(chainId as Hex);
168-
}
169-
170142
function normalizePPOMRequest(
171143
request: PPOMRequest | JsonRpcRequest,
172144
): PPOMRequest | JsonRpcRequest {

app/scripts/lib/ppom/security-alerts-api.test.ts

-28
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
BlockaidResultType,
44
} from '../../../../shared/constants/security-provider';
55
import {
6-
getSecurityAlertsAPISupportedChainIds,
76
isSecurityAlertsAPIEnabled,
87
validateWithSecurityAlertsAPI,
98
} from './security-alerts-api';
@@ -95,31 +94,4 @@ describe('Security Alerts API', () => {
9594
expect(isEnabled).toBe(false);
9695
});
9796
});
98-
99-
describe('getSecurityAlertsAPISupportedChainIds', () => {
100-
it('sends GET request', async () => {
101-
const SUPPORTED_CHAIN_IDS_MOCK = ['0x1', '0x2'];
102-
fetchMock.mockResolvedValue({
103-
ok: true,
104-
json: async () => SUPPORTED_CHAIN_IDS_MOCK,
105-
});
106-
const response = await getSecurityAlertsAPISupportedChainIds();
107-
108-
expect(response).toEqual(SUPPORTED_CHAIN_IDS_MOCK);
109-
110-
expect(fetchMock).toHaveBeenCalledTimes(1);
111-
expect(fetchMock).toHaveBeenCalledWith(
112-
`${BASE_URL}/supportedChains`,
113-
undefined,
114-
);
115-
});
116-
117-
it('throws an error if response is not ok', async () => {
118-
fetchMock.mockResolvedValue({ ok: false, status: 404 });
119-
120-
await expect(getSecurityAlertsAPISupportedChainIds()).rejects.toThrow(
121-
'Security alerts API request failed with status: 404',
122-
);
123-
});
124-
});
12597
});

app/scripts/lib/ppom/security-alerts-api.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { Hex, JsonRpcRequest } from '@metamask/utils';
1+
import { JsonRpcRequest } from '@metamask/utils';
22
import { SecurityAlertResponse } from './types';
33

44
const ENDPOINT_VALIDATE = 'validate';
5-
const ENDPOINT_SUPPORTED_CHAINS = 'supportedChains';
65

76
type SecurityAlertsAPIRequestBody = {
87
method: string;
@@ -36,10 +35,6 @@ export async function validateWithSecurityAlertsAPI(
3635
});
3736
}
3837

39-
export async function getSecurityAlertsAPISupportedChainIds(): Promise<Hex[]> {
40-
return request(ENDPOINT_SUPPORTED_CHAINS);
41-
}
42-
4338
async function request(endpoint: string, options?: RequestInit) {
4439
const url = getUrl(endpoint);
4540

app/scripts/lib/transaction/util.test.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { UserOperationController } from '@metamask/user-operation-controller';
99
import { cloneDeep } from 'lodash';
1010
import {
1111
generateSecurityAlertId,
12-
isChainSupported,
1312
validateRequestWithPPOM,
1413
} from '../ppom/ppom-util';
1514
import {
@@ -100,7 +99,6 @@ describe('Transaction Utils', () => {
10099
let userOperationController: jest.Mocked<UserOperationController>;
101100
const validateRequestWithPPOMMock = jest.mocked(validateRequestWithPPOM);
102101
const generateSecurityAlertIdMock = jest.mocked(generateSecurityAlertId);
103-
const isChainSupportedMock = jest.mocked(isChainSupported);
104102

105103
beforeEach(() => {
106104
jest.resetAllMocks();
@@ -125,7 +123,6 @@ describe('Transaction Utils', () => {
125123
});
126124

127125
generateSecurityAlertIdMock.mockReturnValue(SECURITY_ALERT_ID_MOCK);
128-
isChainSupportedMock.mockResolvedValue(true);
129126

130127
request.transactionController = transactionController;
131128
request.userOperationController = userOperationController;
@@ -399,7 +396,7 @@ describe('Transaction Utils', () => {
399396
).toHaveBeenCalledWith(TRANSACTION_PARAMS_MOCK, {
400397
...TRANSACTION_OPTIONS_MOCK,
401398
securityAlertResponse: {
402-
reason: BlockaidReason.checkingChain,
399+
reason: BlockaidReason.inProgress,
403400
result_type: BlockaidResultType.Loading,
404401
securityAlertId: SECURITY_ALERT_ID_MOCK,
405402
},

app/scripts/lib/transaction/util.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
UpdateSecurityAlertResponse,
2525
} from '../ppom/types';
2626
import {
27-
SECURITY_ALERT_RESPONSE_CHECKING_CHAIN,
27+
LOADING_SECURITY_ALERT_RESPONSE,
2828
SECURITY_PROVIDER_EXCLUDED_TRANSACTION_TYPES,
2929
} from '../../../../shared/constants/security-provider';
3030
import { endTrace, TraceName } from '../../../../shared/lib/trace';
@@ -287,13 +287,13 @@ async function validateSecurity(request: AddTransactionRequest) {
287287
updateSecurityAlertResponse,
288288
});
289289

290-
const securityAlertResponseCheckingChain: SecurityAlertResponse = {
291-
...SECURITY_ALERT_RESPONSE_CHECKING_CHAIN,
290+
const securityAlertResponseLoading: SecurityAlertResponse = {
291+
...LOADING_SECURITY_ALERT_RESPONSE,
292292
securityAlertId,
293293
};
294294

295295
request.transactionOptions.securityAlertResponse =
296-
securityAlertResponseCheckingChain;
296+
securityAlertResponseLoading;
297297
} catch (error) {
298298
handlePPOMError(error, 'Error validating JSON RPC using PPOM: ');
299299
}

shared/constants/security-provider.ts

-32
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { Hex } from '@metamask/utils';
21
import {
32
SecurityAlertResponse,
43
TransactionType,
54
} from '@metamask/transaction-controller';
6-
import { CHAIN_IDS } from './network';
75

86
export enum SecurityProvider {
97
Blockaid = 'blockaid',
@@ -57,8 +55,6 @@ export enum BlockaidReason {
5755
errored = 'Error',
5856
notApplicable = 'NotApplicable',
5957
inProgress = 'validation_in_progress',
60-
checkingChain = 'CheckingChain',
61-
chainNotSupported = 'ChainNotSupported',
6258
}
6359

6460
export enum BlockaidResultType {
@@ -77,23 +73,6 @@ export const FALSE_POSITIVE_REPORT_BASE_URL =
7773

7874
export const SECURITY_PROVIDER_UTM_SOURCE = 'metamask-ppom';
7975

80-
export const SECURITY_PROVIDER_SUPPORTED_CHAIN_IDS_FALLBACK_LIST: Hex[] = [
81-
CHAIN_IDS.ARBITRUM,
82-
CHAIN_IDS.AVALANCHE,
83-
CHAIN_IDS.BASE,
84-
CHAIN_IDS.BSC,
85-
CHAIN_IDS.LINEA_MAINNET,
86-
CHAIN_IDS.MAINNET,
87-
CHAIN_IDS.OPBNB,
88-
CHAIN_IDS.OPTIMISM,
89-
CHAIN_IDS.POLYGON,
90-
CHAIN_IDS.SEPOLIA,
91-
CHAIN_IDS.ZKSYNC_ERA,
92-
CHAIN_IDS.SCROLL,
93-
CHAIN_IDS.BERACHAIN,
94-
CHAIN_IDS.METACHAIN_ONE,
95-
];
96-
9776
export const SECURITY_PROVIDER_EXCLUDED_TRANSACTION_TYPES = [
9877
TransactionType.swap,
9978
TransactionType.swapApproval,
@@ -107,17 +86,6 @@ export const LOADING_SECURITY_ALERT_RESPONSE: SecurityAlertResponse = {
10786
reason: BlockaidReason.inProgress,
10887
};
10988

110-
export const SECURITY_ALERT_RESPONSE_CHECKING_CHAIN: SecurityAlertResponse = {
111-
result_type: BlockaidResultType.Loading,
112-
reason: BlockaidReason.checkingChain,
113-
};
114-
115-
export const SECURITY_ALERT_RESPONSE_CHAIN_NOT_SUPPORTED: SecurityAlertResponse =
116-
{
117-
result_type: BlockaidResultType.Benign,
118-
reason: BlockaidReason.chainNotSupported,
119-
};
120-
12189
export enum SecurityAlertSource {
12290
/** Validation performed remotely using the Security Alerts API. */
12391
API = 'api',

test/data/confirmations/typed_sign.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export const seaportSignatureMsg = {
203203
networkClientId: 'mainnet',
204204
securityAlertResponse: {
205205
result_type: 'loading',
206-
reason: 'CheckingChain',
206+
reason: 'validation_in_progress',
207207
securityAlertId: 'def3b0ef-c96b-4c87-b1b1-c69cc02a0f78',
208208
},
209209
status: 'unapproved',

0 commit comments

Comments
 (0)