Skip to content

Commit

Permalink
fix(suite): zero value phishing tokens (#13452)
Browse files Browse the repository at this point in the history
(cherry picked from commit 5086abb)
  • Loading branch information
AdamSchinzel authored and MiroslavProchazka committed Jul 25, 2024
1 parent 200462f commit 2236a35
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
120 changes: 120 additions & 0 deletions suite-common/wallet-utils/src/__fixtures__/antiFraud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,30 @@ export const getIsFakeTokenPhishingFixtures = [
} as TokenDefinitions,
result: true,
},
{
testName: 'only zero-value fake tokens tx',
transaction: {
symbol: 'matic',
amount: '0',
tokens: [
{ standard: 'ERC20', contract: '0xC', amount: '0' },
{ standard: 'ERC20', contract: '0xD', amount: '0' },
],
} as WalletAccountTransaction,
tokenDefinitions: {
coin: {
error: false,
isLoading: false,
data: ['0xa', '0xb'],
},
nft: {
error: false,
isLoading: false,
data: ['0xn', '0xf'],
},
} as TokenDefinitions,
result: true,
},
{
testName: 'one fake, one legit token tx',
transaction: {
Expand All @@ -127,6 +151,54 @@ export const getIsFakeTokenPhishingFixtures = [
} as TokenDefinitions,
result: false,
},
{
testName: 'one fake, one zero-value legit token tx',
transaction: {
symbol: 'matic',
amount: '0',
tokens: [
{ standard: 'ERC20', contract: '0xA', amount: '1' },
{ standard: 'ERC20', contract: '0xB', amount: '0' },
],
} as WalletAccountTransaction,
tokenDefinitions: {
coin: {
error: false,
isLoading: false,
data: ['0xb'],
},
nft: {
error: false,
isLoading: false,
data: ['0xn', '0xf'],
},
} as TokenDefinitions,
result: true,
},
{
testName: 'one zero-value fake, one legit token tx',
transaction: {
symbol: 'matic',
amount: '0',
tokens: [
{ standard: 'ERC20', contract: '0xA', amount: '0' },
{ standard: 'ERC20', contract: '0xB', amount: '1' },
],
} as WalletAccountTransaction,
tokenDefinitions: {
coin: {
error: false,
isLoading: false,
data: ['0xb'],
},
nft: {
error: false,
isLoading: false,
data: ['0xn', '0xf'],
},
} as TokenDefinitions,
result: false,
},
{
testName: 'only legit tokens tx',
transaction: {
Expand All @@ -151,6 +223,30 @@ export const getIsFakeTokenPhishingFixtures = [
} as TokenDefinitions,
result: false,
},
{
testName: 'only zero-value legit tokens tx',
transaction: {
symbol: 'matic',
amount: '0',
tokens: [
{ standard: 'ERC20', contract: '0xA', amount: '0' },
{ standard: 'ERC20', contract: '0xB', amount: '0' },
],
} as WalletAccountTransaction,
tokenDefinitions: {
coin: {
error: false,
isLoading: false,
data: ['0xa', '0xb'],
},
nft: {
error: false,
isLoading: false,
data: ['0xn', '0xf'],
},
} as TokenDefinitions,
result: true,
},
{
testName: 'no tokens tx',
transaction: {
Expand Down Expand Up @@ -220,6 +316,30 @@ export const getIsFakeTokenPhishingFixtures = [
} as TokenDefinitions,
result: false,
},
{
testName: 'fake NFT token with zero-value legit token tx',
transaction: {
symbol: 'matic',
amount: '0',
tokens: [
{ standard: 'ERC1155', contract: '0xT', amount: '1' },
{ standard: 'ERC20', contract: '0xA', amount: '0' },
],
} as WalletAccountTransaction,
tokenDefinitions: {
coin: {
error: false,
isLoading: false,
data: ['0xa', '0xb'],
},
nft: {
error: false,
isLoading: false,
data: ['0xn', '0xf'],
},
} as TokenDefinitions,
result: true,
},
{
testName: 'just legit NFT token tx',
transaction: {
Expand Down
4 changes: 4 additions & 0 deletions suite-common/wallet-utils/src/antiFraud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export const getIsFakeTokenPhishing = (
new BigNumber(transaction.amount).isEqualTo(0) && // native currency is zero
D.isNotEmpty(transaction.tokens) && // there are tokens in tx
!transaction.tokens.some(tokenTx => {
if (new BigNumber(tokenTx.amount).isEqualTo(0)) {
return false;
}

const isNftTx = isNftTokenTransfer(tokenTx);
const definitions = isNftTx ? tokenDefinitions?.nft?.data : tokenDefinitions?.coin?.data;

Expand Down

0 comments on commit 2236a35

Please sign in to comment.