Giter Club home page Giter Club logo

inspector-facet's Introduction

Inspector Facet

A tool that allows you to inspect deployed EIP-2535 Diamond proxy contracts from your command line.

Inspector Facet was inspired by Louper.dev (GitHub).

Inspector Facet uses side information about facet ABIs to match the selectors that a Diamond proxy is serving to human-understandable information about the facets and the functions.

We support side information obtained from:

  • brownie build artifacts
  • hardhat build artifacts
  • Etherscan/Polygonscan/etc.

Inspector Facet can build a complete audit log of all Diamond-related operations on an EIP2535 proxy contract. Use this functionality with the --timeline argument.

Installation

Inspector Facet is written in Python 3 and is distributed using PyPI: https://pypi.org/project/inspector-facet/

To install Inspector Facet, run:

pip install inspector-facet

Usage

inspector-facet --help

To use Inspector Facet:

With a brownie project

The following command produces human-readable output:

inspector-facet \
    --network <brownie network name for blockchain> \
    --address <address of diamond contract> \
    --project <path to brownie project> \
    --format human

The following command produces JSON output and can be used to inspect a Diamond contract programatically (e.g. as part of a CI/CD pipeline):

inspector-facet \
    --network <brownie network name for blockchain> \
    --address <address of diamond contract> \
    --project <path to brownie project> \
    --format json

With a foundry project

The following command produces human-readable output:

inspector-facet \
    --network <brownie network name for blockchain> \
    --address <address of diamond contract> \
    --project <path to foundry project> \
    --foundry \
    --format human

The following command produces JSON output and can be used to inspect a Diamond contract programatically (e.g. as part of a CI/CD pipeline):

inspector-facet \
    --network <brownie network name for blockchain> \
    --address <address of diamond contract> \
    --project <path to foundry project> \
    --foundry \
    --format json

Non-standard build directories

The --build-dir command allows you to specify the name of the build directory in your brownie or foundry project in case you aren't using the standard directories (build/ for brownie and out/ for foundry).

To build an audit log of Diamond operations on an EIP2535 proxy contract

To build an audit log, you will need to crawl DiamondCut events from the blockchain. You can do this using moonworm.

First, you will need to install moonworm:

pip install moonworm

This should be done in a separate Python environment from inspector-facet because brownie pins its dependencies and doesn't play nice with other libraries (GitHub issue).

Once moonworm is installed, you can find the deployment block for your contract:

moonworm find-deployment -w <JSON RPC URL for blockchain node> -c <contract address> -t 0.5

Save the output of this command as START_BLOCK.

Then crawl the DiamondCut event data:

moonworm watch \
  -i inspector_facet/abis/DiamondCutFacetABI.json \
  -w <JSON RPC URL for blockchain node> \
  -c <contract address> \
  --start $START_BLOCK \
  --end <current block number> \
  --only-events \
  -o <output filename> \
  --min-blocks-batch 1000 \
  --max-blocks-batch 1000000

If you are crawling data from a POA chain (like Polygon), add --poa to the command above.

Then, invoke inspector-facet as:

inspector-facet \
  --crawldata <output filename> \
  --project <path to brownie project (should contain build artifacts in build/contracts)> \
  --format human \
  --timeline

Connecting to a blockchain

Internally, Inspector Facet uses brownie to work with any Ethereum-based blockchain. When you use inspector-facet, even with a hardhat project, inspector-facet will still use brownie to interact with any blockchain.

Any inspector-facet command that calls out to a blockchain will take a -n/--network argument. The value of this argument must be the name of a brownie network configured in your Python environment.

brownie is a dependency of inspector-facet and is automatically installed when you install inspector-facet.

To see a list of available brownie networks, activate the Python environment in which you installed inspector-facet and run:

brownie networks list

The output will look like this (truncated for brevity):

$ brownie networks list

Brownie v1.17.2 - Python development framework for Ethereum

The following networks are declared:

Ethereum
  ├─Mainnet (Infura): mainnet
  ├─Ropsten (Infura): ropsten
  ├─Rinkeby (Infura): rinkeby
  ├─Goerli (Infura): goerli
  └─Kovan (Infura): kovan

Ethereum Classic
  ├─Mainnet: etc
  └─Kotti: kotti

Arbitrum
  └─Mainnet: arbitrum-main
...

To view the details for any particular network, use:

brownie networks modify $NETWORK

For example:

$ brownie networks modify mainnet

$ brownie networks modify mainnet
Brownie v1.17.2 - Python development framework for Ethereum

SUCCESS: Network 'Mainnet (Infura)' has been modified
  └─Mainnet (Infura)
    ├─id: mainnet
    ├─chainid: 1
    ├─explorer: https://api.etherscan.io/api
    ├─host: https://mainnet.infura.io/v3/$WEB3_INFURA_PROJECT_ID
    └─multicall2: 0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696

If you want to connect to this network, using Infura, all you have to do is set your WEB3_INFURA_PROJECT_ID environment variable (get this information from your project dashboard on Infura) and set --network mainnet when you invoke inspector-facet.

For networks which have publicly available nodes, it's even more straightforward:

$ brownie networks modify etc
Brownie v1.17.2 - Python development framework for Ethereum

SUCCESS: Network 'Mainnet' has been modified
  └─Mainnet
    ├─id: etc
    ├─chainid: 61
    ├─explorer: https://blockscout.com/etc/mainnet/api
    └─host: https://www.ethercluster.com/etc

You don't need any additional environment variables.

Adding a custom network

To add your own network, use the brownie networks add command.

The signature for this command is:

brownie networks add <label> <network-name> chainid=<chain ID for network> host=<JSON RPC endpoint> explorer=<API URL for blockchain explorer>

The <label> is purely for organizational purposes and can be set to whatever string you want.

For example, if you wanted to add the public Polygon RPC service as a network, you would do:

brownie networks add Polygon matic chainid=137 host=https://polygon-rpc.com explorer=https://api.polygonscan.com/api

Support

You can get help in any of the following ways:

  1. File an issue
  2. Ask for help on Moonstream Discord

inspector-facet's People

Contributors

zomglings avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

inspector-facet's Issues

Inspector Facet docker image

Have heard from people that they would like to use it but setting up a Python environment is too difficult. It's a reasonable criticism and one that we could mitigate by packaging up Inspector Facet in a docker image and releasing on Docker Hub or GitHub's artifact repository.

Add Hardhat support

Hardhat build artifacts differ from Brownie build artifacts as follows:

  1. Build artifacts are put into the artifacts/ directory instead of the build/ directory. artifacts/contracts/ contains the contract ABIs.
  2. Brownie build/contracts/ has a flat structure. Hardhat artifacts/contracts/ reflects the directory structure of the contracts/ directory containing solidity files.
  3. Hardhat contract JSON files have a contractName field that defines the name of the contract in question. They also have a sourceName question that contains the path to the source (solidity) file from the hardhat project root.

Inspector Facet should support getting ABI side-information from hardhat project directories in addition to brownie project directories.

TODO:

  • Implement hardhat support.
  • Open question: Should there be a flag on inspector-facet that the invoker uses to specify whether they want to get ABI information from a brownie project vs. a hardhat project? Or should it be auto-detected?
  • README should be updated explaining how to use inspector-facet with Hardhat projects. One potential area of confusion is that inspector-facet uses brownie to pull smart contract information and so requires brownie networks setup correctly. This has no bearing on whether it gets side information from a brownie project vs. a hardhat project. We should clarify this in README.

Audit log of diamond operations

It should be possible for users to build an audit log of all cut operations that were performed on a Diamond contract. This will require crawling of DiamondCut events from the blockchain.

As such, this issue is related to #2 .

Add support for Diamond contracts which do not mount the DiamondLoupeFacet

If a diamond contract does not mount the DiamondLoupeFacet (which allows for on-chain inspection of attached functionality), then we need to crawl blockchain events to understand what functionality is mounted on that contract.

It should be possible for a user to provide us with a file of diamond-related events for a diamond contract and get all the benefits of Inspector Facet for the inspection of those events.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.