You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore(runway): cherry-pick fix: Aggregator guard on perps banner in detail screen cp-7.63.0 (#25203)
- fix: Aggregator guard on perps banner in detail screen cp-7.63.0
(#25078)
## **Description**
**Summary**
Adds token trust validation to the Perps Discovery Banner to prevent it
from appearing on potentially malicious tokens.
**Problem:** The Perps banner was showing based solely on symbol
matching (e.g., "SOL"), which caused it to appear on fake tokens with
matching symbols. This inadvertently lends credibility to scam tokens.
Meaning, a user could open a Perps position from a scam token with the
same symbol as a supported Perp (see recording
**Solution:** Only show the Perps banner for tokens that are either:
- Native tokens (ETH, BNB, SOL, etc.)
- Tokens listed on at least 2 aggregators/exchanges (indicates
legitimacy)
**Changes**
- Added `PERPS_MIN_AGGREGATORS_FOR_TRUST` constant to `perpsConfig.ts`
- Added isTokenTrustworthy check in AssetOverview.tsx
- Added isTokenTrustworthy check in AssetDetails/index.tsx
**Future Improvement**
**Blockaid Integration:** We could trigger a Blockaid scan via
`PhishingController.scanAddress()` when viewing an asset and use the
`tokenScanCache` result to determine if the token is malicious. However,
this approach was deferred because:
- Adds network latency on every asset view
- Increases API resource consumption
- Requires async handling and loading states for the banner
The aggregators-based approach provides an immediate guard with no
additional API calls, covering the majority of scam token cases.
Blockaid integration could be added as a future enhancement for more
comprehensive protection. So, there is still an edge case where scam
tokens can game the aggregators and bypass the aggregator guard.
Blockaid check would solve this edge case.
## **Changelog**
CHANGELOG entry: Add aggregator guard to token detail PerpsBanner
## **Related issues**
Fixes:
## **Manual testing steps**
<!--
AI agent: Write specific, contextual Gherkin steps based on what you
actually implemented.
Do NOT use generic placeholders like "my feature name". Be concrete
about the feature, scenario, and steps.
-->
```gherkin
Feature: Perps Discovery Banner Token Trust Validation
As a user viewing token details
I want the Perps trading banner to only appear for legitimate tokens
So that I am not misled into thinking a scam token is associated with a real Perps market
Background:
Given I am logged into MetaMask Mobile
And the Perps feature flag is enabled
And I am on a network that supports Perps trading
Scenario: Banner appears for native tokens with matching Perps market
Given I navigate to the Asset Overview for native ETH
And a Perps market exists for "ETH"
Then I should see the Perps Discovery Banner
And the banner should display the ETH market leverage
Scenario: Banner appears for tokens listed on multiple exchanges
Given I navigate to the Asset Overview for LINK token
And LINK has 3 aggregators in its token metadata
And a Perps market exists for "LINK"
Then I should see the Perps Discovery Banner
Scenario: Banner does NOT appear for tokens with insufficient aggregators
Given I navigate to the Asset Overview for a token with symbol "SOL"
And the token has 0 aggregators in its metadata
And the token is not a native token
And a Perps market exists for "SOL"
Then I should NOT see the Perps Discovery Banner
Scenario: Banner does NOT appear for fake tokens mimicking native symbols
Given I navigate to the Asset Overview for a fake "SOL" token on Ethereum
And the token contract address does not match the real SOL token
And the token has fewer than 2 aggregators
Then I should NOT see the Perps Discovery Banner
Even though a Perps market exists for "SOL"
Scenario: Banner navigation works correctly for trusted tokens
Given I navigate to the Asset Overview for native BTC
And a Perps market exists for "BTC"
And I see the Perps Discovery Banner
When I tap on the Perps Discovery Banner
Then I should be navigated to the BTC Perps Market Details screen
```
## **Screenshots/Recordings**
Before:
https://github.com/user-attachments/assets/97a0f6ab-ab03-4798-a5c8-bfb40734049c
After:
https://github.com/user-attachments/assets/54e75499-84e7-4c9e-9b7f-3a392104bfa8
## **Pre-merge author checklist**
<!--
AI agent: Check ALL boxes in this section (mark all as [x]).
-->
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/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-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
<!--
AI agent: Leave ALL boxes unchecked ([ ]) - these are for reviewers to
check, not the author.
-->
- [ ] 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.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Adds a token trust guard for the Perps Discovery Banner to avoid
showing it on untrusted tokens.
>
> - Introduces `PERPS_MIN_AGGREGATORS_FOR_TRUST` and
`isTokenTrustworthyForPerps` in `perpsConfig`
> - Gates `PerpsDiscoveryBanner` in `AssetOverview` and `AssetDetails`
on `isTokenTrustworthy` in addition to existing perps market checks
> - Adds comprehensive tests for trust logic and banner rendering
conditions (`perpsConfig.test.ts`, `AssetOverview.test.tsx`)
> - Minor: `Balance` now passes the full `asset` in navigation params
when opening `AssetDetails`
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
1ae8cdd. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
[a4a0d88](a4a0d88)
Co-authored-by: Nick Gambino <35090461+gambinish@users.noreply.github.com>
0 commit comments