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

Add Ethereum Smart Contract binary bytecode matching #52

Merged
merged 112 commits into from
Oct 15, 2024

Conversation

Alexvozhak
Copy link
Contributor

@Alexvozhak Alexvozhak commented Jul 7, 2024

Description:

This PR enhances diffyscan by integrating Ethereum smart contract binary matching. It incorporates functionalities from verify-bytecode.ts and bytecode_verificator.sh.


Key Changes:

  • Showcases:

  • New Modules and Refactoring:

    • Binary Comparison Logic: Introduced binary_verifier.py to handle binary comparison of contracts.
    • Argument Encoding: Added encoder.py for encoding contract arguments, referencing the Solidity ABI specification.
    • Compiler Module: Moved all source compilation code to compiler.py.
    • Calldata Handling: Created calldata.py for calculating and parsing constructor arguments from configurations.
    • Type Definitions: Renamed and extended types.py to custom_types.py.
    • Node Interactions:
      • Encapsulated interactions with the local Hardhat node in hardhat.py.
      • Moved common node operations to node_handler.py.
    • Exception Handling: Added specific exceptions for new features in custom_exceptions.py.
  • Configurations and Documentation:

    • Configuration Updates:
      • Extended lido_dao_sepolia_config.json and lido_dao_holesky_config.json with a binary_comparison section.
      • Added specific Hardhat configurations for Sepolia and Holesky networks.
    • Documentation:
      • Updated the README to reflect new features and usage instructions.
      • Included support for user-defined Hardhat configurations as shown in the README example.
  • Improvements and Fixes:

    • Code Quality:
      • Fixed existing errors identified by the mypy linter.
      • Enhanced code readability and organization.
    • Backwards compatibility: Ensured that existing diffyscan usage remains unaffected.

Implemented Logic for Contract Code Matching:

  1. Source Retrieval: Obtain contract sources from Etherscan.
  2. Source Diffing: Perform source code diffing as previously implemented.
  3. Bytecode Matching: Compile the contracts and attempt to match the bytecode obtained from the RPC node.
  4. Matching Outcome:
    • Success: If the bytecode matches, proceed to the next contract.
    • Metadata Differences: If only the metadata differs, display a warning but continue processing.
  5. Error Handling:
    • No Immutables: If there are no immutables and the bytecode doesn't match, display an error.
    • With Immutables: If immutables are present and the configuration includes constructor calldata or parameters, attempt to deploy the contract and compare the resulting bytecode.

By integrating these enhancements, diffyscan has been enriched with the ability to verify smart contracts at the bytecode level, ensuring greater reliability and security in contract deployment and verification processes.

@TheDZhon TheDZhon self-requested a review July 7, 2024 15:07
@TheDZhon TheDZhon changed the title Added binary verificator Added binary verificator [WIP] Jul 8, 2024
@TheDZhon TheDZhon marked this pull request as draft July 8, 2024 07:12
@Alexvozhak Alexvozhak force-pushed the binary_verificator branch 2 times, most recently from 7595b7d to aa6733a Compare July 29, 2024 15:22
@Alexvozhak Alexvozhak force-pushed the binary_verificator branch from d3be3eb to f77bf50 Compare July 30, 2024 14:56
@TheDZhon TheDZhon requested a review from tamtamchik July 30, 2024 18:13
@Alexvozhak Alexvozhak marked this pull request as ready for review July 31, 2024 15:54
@Alexvozhak Alexvozhak marked this pull request as draft July 31, 2024 23:20
README.md Show resolved Hide resolved
@Alexvozhak Alexvozhak requested a review from tamtamchik August 1, 2024 15:53
@Alexvozhak Alexvozhak requested a review from TheDZhon September 12, 2024 22:59
Copy link
Contributor

@TheDZhon TheDZhon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
diffyscan/utils/binary_verifier.py Outdated Show resolved Hide resolved
diffyscan/utils/encoder.py Outdated Show resolved Hide resolved
diffyscan/utils/encoder.py Show resolved Hide resolved
@TheDZhon TheDZhon changed the title Added binary verificator [WIP] Added binary verificator Sep 18, 2024
@TheDZhon TheDZhon changed the title Added binary verificator Add Ethereum Smart Contract binary bytecode matching Sep 18, 2024
Copy link
Contributor

@TheDZhon TheDZhon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

README.md Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
diffyscan/utils/encoder.py Outdated Show resolved Hide resolved
@Alexvozhak Alexvozhak requested a review from TheDZhon September 24, 2024 22:05
@TheDZhon
Copy link
Contributor

Seems the PR is ready to merge 🌟 except only for two things:

  1. An outstanding branch conflict it has
  2. Metadata parsed as opcodes while it shouldn't, see https://docs.soliditylang.org/en/latest/metadata.html#encoding-of-the-metadata-hash-in-the-bytecode
image

see as a reference:

https://playground.sourcify.dev/
address: 0x76A50b8c7349cCDDb7578c6627e79b5d99D24138
network: #10 OP Mainnet
image

@TheDZhon
Copy link
Contributor

TheDZhon commented Oct 8, 2024

@TheDZhon TheDZhon changed the base branch from main to develop October 15, 2024 06:35
Copy link
Contributor

@TheDZhon TheDZhon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, accepting to upstream 🍏

@TheDZhon TheDZhon merged commit 7f6091d into lidofinance:develop Oct 15, 2024
@TheDZhon TheDZhon mentioned this pull request Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants