From e14c0ff81fa5cb3086d4b6e1fdb565b721b1f0ad Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Thu, 12 Sep 2024 03:27:49 +0200 Subject: [PATCH] Detect ERC-1167 Minimal Proxy contracts --- .changelog/1538.feature.md | 1 + .../Account/RuntimeAccountDetailsView.tsx | 10 ++++++++ .../extractMinimalProxyERC1167.ts | 23 +++++++++++++++++++ .../TokenDashboardPage/TokenDetailsCard.tsx | 10 ++++++++ src/locales/en/translation.json | 3 ++- 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 .changelog/1538.feature.md create mode 100644 src/app/components/ContractVerificationIcon/extractMinimalProxyERC1167.ts diff --git a/.changelog/1538.feature.md b/.changelog/1538.feature.md new file mode 100644 index 000000000..1ed1c8978 --- /dev/null +++ b/.changelog/1538.feature.md @@ -0,0 +1 @@ +Detect ERC-1167 Minimal Proxy contracts diff --git a/src/app/components/Account/RuntimeAccountDetailsView.tsx b/src/app/components/Account/RuntimeAccountDetailsView.tsx index 5b1ce1e48..3506a7bc3 100644 --- a/src/app/components/Account/RuntimeAccountDetailsView.tsx +++ b/src/app/components/Account/RuntimeAccountDetailsView.tsx @@ -22,6 +22,7 @@ import { calculateFiatValue } from '../Balance/hooks' import { FiatMoneyAmount } from '../Balance/FiatMoneyAmount' import { getFiatCurrencyForScope, showFiatValues } from '../../../config' import { CardEmptyState } from '../CardEmptyState' +import { extractMinimalProxyERC1167 } from '../ContractVerificationIcon/extractMinimalProxyERC1167' type RuntimeAccountDetailsViewProps = { isLoading?: boolean @@ -103,6 +104,15 @@ export const RuntimeAccountDetailsView: FC = ({ )} + {extractMinimalProxyERC1167(account) && ( + <> +
{t('contract.verification.proxyERC1167')}
+
+ +
+ + )} + {contract && ( <>
{t('contract.creator')}
diff --git a/src/app/components/ContractVerificationIcon/extractMinimalProxyERC1167.ts b/src/app/components/ContractVerificationIcon/extractMinimalProxyERC1167.ts new file mode 100644 index 000000000..99afe1ad5 --- /dev/null +++ b/src/app/components/ContractVerificationIcon/extractMinimalProxyERC1167.ts @@ -0,0 +1,23 @@ +import { RuntimeAccount } from '../../../oasis-nexus/api' +import { base64ToHex } from '../../utils/helpers' +import { toChecksumAddress } from '@ethereumjs/util' + +/** https://eips.ethereum.org/EIPS/eip-1167 */ +export function extractMinimalProxyERC1167(account: RuntimeAccount) { + if (!account?.evm_contract?.runtime_bytecode) return undefined + + const hexBytecode = base64ToHex(account.evm_contract.runtime_bytecode) + + const proxyToAddress1 = hexBytecode.match( + /^0x363d3d373d3d3d363d73([0-9a-fA-F]{40})5af43d82803e903d91602b57fd5bf3$/, + )?.[1] + if (proxyToAddress1) return toChecksumAddress(`0x${proxyToAddress1}`) + + // Optimized version + const proxyToAddress2 = hexBytecode.match( + /^0x363d3d373d3d3d363d6f([0-9a-fA-F]{32})5af43d82803e903d91602757fd5bf3$/, + )?.[1] + if (proxyToAddress2) return toChecksumAddress(`0x00000000${proxyToAddress2}`) + + return undefined +} diff --git a/src/app/pages/TokenDashboardPage/TokenDetailsCard.tsx b/src/app/pages/TokenDashboardPage/TokenDetailsCard.tsx index d586c7089..6cd050243 100644 --- a/src/app/pages/TokenDashboardPage/TokenDetailsCard.tsx +++ b/src/app/pages/TokenDashboardPage/TokenDetailsCard.tsx @@ -21,6 +21,7 @@ import { tokenHoldersContainerId } from '../../pages/TokenDashboardPage/TokenHol import { RoundedBalance } from 'app/components/RoundedBalance' import { HighlightedText } from '../../components/HighlightedText' import { RuntimeBalanceDisplay } from '../../components/Balance/RuntimeBalanceDisplay' +import { extractMinimalProxyERC1167 } from '../../components/ContractVerificationIcon/extractMinimalProxyERC1167' export const TokenDetailsCard: FC<{ scope: SearchScope; address: string; searchTerm: string }> = ({ scope, @@ -66,6 +67,15 @@ export const TokenDetailsCard: FC<{ scope: SearchScope; address: string; searchT /> + {extractMinimalProxyERC1167(account) && ( + <> +
{t('contract.verification.proxyERC1167')}
+
+ +
+ + )} +
{t('common.type')}
diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 2d733f2c5..edcaa860c 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -175,7 +175,8 @@ "openInAbiPlayground": "Interact in ABI Playground", "openInSourcify": "Open in Sourcify", "verifyInSourcify": "Verify through Sourcify", - "explainVerificationDelay": "If you have just verified a contract, it should take a few minutes to update here." + "explainVerificationDelay": "If you have just verified a contract, it should take a few minutes to update here.", + "proxyERC1167": "ERC-1167 proxy to" } }, "consensusSnapshot": {