Skip to main content

Library and command line tool for auditing smart contract permissions

Project description

Project generated with PyScaffold

Eth permissions audit library

This project defines a simple library for obtaining smart contract permissions and building a graph.

It's aimed at contracts using Openzeppelin's AccessControl module.

Installation

You'll need to have graphviz installed: apt-get install graphviz.

Then simply install with pip or your preferred package manager:

pip install eth-permissions

Usage as a library

We use eth-prototype's wrappers for accessing the blockchain information. The simplest way to use it is to export the following environment variables:

export DEFAULT_PROVIDER=w3

# You can use any json-rpc node supported by web3py.
export WEB3_PROVIDER_URI=https://polygon-mainnet.g.alchemy.com/v2/<YOUR KEY>

Use the chaindata module to get the full permissions detail:

from eth_permissions.chaindata import EventStream

stream = EventStream("IAccessControl", "0x47E2aFB074487682Db5Db6c7e41B43f913026544")

stream.snapshot

# [
#  {'role': Role('DEFAULT_ADMIN_ROLE'),
#   'members': ['0xCfcd29CD20B6c64A4C0EB56e29E5ce3CD69336D2']},
#  {'role': Role('UNKNOWN ROLE: 0x2582...a559'),
#   'members': ['0x9dA2192C820C5cC37d26A3F97d7BcF1Bc04232A3']},
#  ...
#  {'role': Role('UNKNOWN ROLE: 0xf17c...fd8a'),
#   'members': ['0x76B349e14a5B5FAF8090313Aa393e1b37aC5E126']},
# ]

You can register your roles to get the actual names in the result. See main.py for an example of how to do that.

Usage as a command line tool

First set up some env vars:

# Env vars for eth-prototype
export DEFAULT_PROVIDER=w3
export WEB3_PROVIDER_URI=https://polygon-mainnet.g.alchemy.com/v2/<YOUR KEY>

# Values for ensuro v2 on mainnet as of dec 2023, change accordingly for other contracts
export KNOWN_ROLES=GUARDIAN_ROLE,LEVEL1_ROLE,LEVEL2_ROLE,LEVEL3_ROLE,RESOLVER_ROLE,POLICY_CREATOR_ROLE,PRICER_ROLE,...
export KNOWN_COMPONENTS=0xa65c9dE776d1f30c095EFF9C775E001a1d366df8,0x37fE456EFF897CB5dDF040A5e95f399EaBc162ca
export KNOWN_COMPONENT_NAMES="KoalaV2,Koala Partner B"

Then run eth-permissions:

python -m eth_permissions --view --output test.png 0x47E2aFB074487682Db5Db6c7e41B43f913026544

This will create the file test.png and open it with the default viewer. It will look like this:

Run python -m eth_permissions --help to see all available flags and options.

App

Check app/Readme for a simple app that exposes this API over http for use on a frontend app.

TODO

  • Add support for Ownable contracts
  • Address book
  • Add multisig intelligence (detect when a role member is a multisig and obtain its members)
  • Timelock detection

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eth_permissions-0.4.0b1.tar.gz (121.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eth_permissions-0.4.0b1-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file eth_permissions-0.4.0b1.tar.gz.

File metadata

  • Download URL: eth_permissions-0.4.0b1.tar.gz
  • Upload date:
  • Size: 121.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for eth_permissions-0.4.0b1.tar.gz
Algorithm Hash digest
SHA256 5f20b9cfefe93efb956ff0d6f6ca181b51c2a5f19613a50dc5d1850aca755982
MD5 4f37d72de65cd5f74806f51c981fe486
BLAKE2b-256 a7a8f1cab705f096a5e7971303f49cfc99ebfdfbc39481ba54a24bbdc2b72cd3

See more details on using hashes here.

File details

Details for the file eth_permissions-0.4.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for eth_permissions-0.4.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 994815b771df65c9535bf8855dea43b880da6dae53dd96620bcc5f2f23d5935d
MD5 69adb4947b99568c932cfcba24ae437b
BLAKE2b-256 2cd6590da8609edb3c0d6814c2ef9d730cf66b83ea5b3a7b92703ac95095ca3f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page