Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect ERC-1167 Minimal Proxy contracts #1538

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/1538.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Detect ERC-1167 Minimal Proxy contracts
18 changes: 16 additions & 2 deletions src/app/components/Account/RuntimeAccountDetailsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import Link from '@mui/material/Link'
import { DashboardLink } from '../../pages/ParatimeDashboardPage/DashboardLink'
import { AllTokenPrices } from '../../../coin-gecko/api'
import { ContractCreatorInfo } from './ContractCreatorInfo'
import { ContractVerificationIcon } from '../ContractVerificationIcon'
import { VerificationIcon } from '../ContractVerificationIcon'
import { TokenLink } from '../Tokens/TokenLink'
import { AccountAvatar } from '../AccountAvatar'
import { RuntimeBalanceDisplay } from '../Balance/RuntimeBalanceDisplay'
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
Expand Down Expand Up @@ -94,7 +95,20 @@ export const RuntimeAccountDetailsView: FC<RuntimeAccountDetailsViewProps> = ({
<>
<dt>{t('contract.verification.title')}</dt>
<dd>
<ContractVerificationIcon account={account} />
<VerificationIcon
address_eth={account.address_eth!}
scope={account}
verified={!!account.evm_contract?.verification}
/>
</dd>
</>
)}

{extractMinimalProxyERC1167(account) && (
<>
<dt>{t('contract.verification.proxyERC1167')}</dt>
<dd>
<AccountLink scope={account} address={extractMinimalProxyERC1167(account)!} />
</dd>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
26 changes: 1 addition & 25 deletions src/app/components/ContractVerificationIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { styled } from '@mui/material/styles'
import { COLORS } from '../../../styles/theme/colors'
import Link from '@mui/material/Link'
import Typography from '@mui/material/Typography'
import Skeleton from '@mui/material/Skeleton'
import { Layer, RuntimeAccount } from '../../../oasis-nexus/api'
import { Layer } from '../../../oasis-nexus/api'
import { SearchScope } from '../../../types/searchScope'
import { Network } from '../../../types/network'
import * as externalLinks from '../../utils/externalLinks'
Expand Down Expand Up @@ -54,29 +53,6 @@ const StyledPill = styled(Box, {
}
})

type ContractVerificationIconProps = {
account: Pick<RuntimeAccount, 'address_eth' | 'evm_contract' | 'network' | 'layer'> | undefined
noLink?: boolean
}

const Waiting: FC = () => (
<Skeleton
variant="text"
sx={{ display: 'inline-block', width: '100%', height: verificationIconBoxHeight }}
/>
)

export const ContractVerificationIcon: FC<ContractVerificationIconProps> = ({ account, noLink = false }) => {
if (!account) {
return <Waiting />
}

const verified = !!account.evm_contract?.verification
const address_eth = account.address_eth!

return <VerificationIcon address_eth={address_eth} scope={account} verified={verified} noLink={noLink} />
}

export const VerificationIcon: FC<{
address_eth: string
scope: SearchScope
Expand Down
10 changes: 10 additions & 0 deletions src/app/pages/TokenDashboardPage/TokenDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -66,6 +67,15 @@ export const TokenDetailsCard: FC<{ scope: SearchScope; address: string; searchT
/>
</dd>

{extractMinimalProxyERC1167(account) && (
<>
<dt>{t('contract.verification.proxyERC1167')}</dt>
<dd>
<AccountLink scope={account} address={extractMinimalProxyERC1167(account)!} />
</dd>
</>
)}

<dt>{t('common.type')} </dt>
<dd>
<TokenTypeTag tokenType={token.type} />
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@
"openInAbiPlayground": "Interact in <AbiPlaygroundLink>ABI Playground</AbiPlaygroundLink>",
"openInSourcify": "Open in <SourcifyLink>Sourcify</SourcifyLink>",
"verifyInSourcify": "Verify through <SourcifyLink>Sourcify</SourcifyLink>",
"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": {
Expand Down
Loading