smlxl / evm.codes

Source for evm.codes an Ethereum Virtual Machine Opcodes Interactive Reference
https://evm.codes/
MIT License
728 stars 134 forks source link

Fix import paths #334

Closed ilamanov closed 5 months ago

ilamanov commented 5 months ago

If you currently try to compile the flattened version of 0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD you get an error:

DeclarationError: Identifier already declared.
   --> contracts/test-flatten/UniversalRouter.sol:807:1:
    |
807 | abstract contract ERC20 {
    | ^ (Relevant source part starts here and spans across multiple lines).
Note: The previous declaration is here:
   --> contracts/test-flatten/UniversalRouter.sol:363:1:
    |
363 | abstract contract ERC20 {
    | ^ (Relevant source part starts here and spans across multiple lines).

This is because ERC20 is inserted twice into the flattened source code. Our current code tries to handle duplicate insertion but it doesn't take into account remappings.

In this particular contract ERC20 is import twice in two different files. Once as solmate/src/tokens/ERC20.sol and once as lib/solmate/src/tokens/ERC20.sol. These are essentially the same file but our code treats them as different files because it doesn't remap imports before checking for duplicates. This PR fixes this.

Test plan

• Flatten the code of 0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD in contract viewer • Copy paste the flattened code into Remix and try compile it. • You shouldn't get an error like above.

vercel[bot] commented 5 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
evm-codes ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2024 0:04am
ilamanov commented 5 months ago

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @ilamanov and the rest of your teammates on Graphite Graphite