-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect ERC-1167 Minimal Proxy contracts
- Loading branch information
Showing
5 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Detect ERC-1167 Minimal Proxy contracts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/app/components/ContractVerificationIcon/extractMinimalProxyERC1167.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters