Giter Site home page Giter Site logo

contract-bots-gang's Introduction

โœจ Contract Bots Gang โœจ

A collection of Forta detection bots ๐Ÿค– to automatically analyze, inspect, and detect bugs on newly deployed contracts. The repo contains subdirectories, one for each bot. The entire design is meant to be in three layers:

Live bots

bots that scan newly deployed contracts, run inspections on the bytecode and spit out organized info to be processed later (function signatures, events, etc..). A first attempt is the ContractDeconstruct bot that you can find LIVE here. Take a look at alerts metadata to get an idea of what it spits out. Otherwise you can read the README. The bot uses 4byte.directory database as a lookup table. There are some scripts to run manually to sync up with latest database updates. If you want to know how to sync latest signatures, read here.

  • ๐Ÿ•ต๏ธโ€โ™‚๏ธ Detector bots:

bots that use ContractDeconstruct to run automatic detection of the type of contract, interfaces supported or patterns used. A first attempt I've done is an InterfaceDetector which is able to detect ERC20 and ERC721 tokens, TransparentUpgradeable or UUPS proxies, Ownable or AccessControl contracts and even ProxyAdmin contracts. You can find the bot LIVE here and you can read the README on the repo. You want to add your own interface or contract type detection ? read here how to do it.

  • ๐Ÿ’ฅ [WIP] Hunter bots:

bots that will be using output from detectors and deconstructors to run simulations in a mainnet fork of potential attacks and vulnerabilities exploit. If positive bots will raise alerts.

โš’๏ธ Deconstructors

ContractDeconstruct bot

This is the main bot that detects new contract deployments and spits out the following output into the fired alert's data.

{
    name: `CI-XXX`, // XXX Is the Unix timestamp.
    description: `Contract inspection ${contractAddressFromReceipt}`, // Here we put the contract address
    alertId: `CI-XXX`, // XXX Is the Unix timestamp.
    severity: FindingSeverity.Info,
    type: FindingType.Info,
    metadata: {
        transaction: // transaction.hash,
        contractAddress: // Contract address provided by the transaction receipt.
        functions: // list of functions signatures that matched with 4byte directory. Their text string is provided.
        unknownFunctions: //list of functions signatures that didn't match with 4byte directory.
        events: // list of event signatures that matched with 4byte directory. Their text string is provided.
        unknownEvents: // list of event signatures that didn't match with 4byte directory.
        bytecode: // The deployed bytecode (without init code).
        disassembled: // List of opcodes and their eventual values.
        //analysis: // [CURRENTLY COMMMENTED OUT] Output of Yasold tool.
    }
}

๐Ÿ•ต๏ธโ€โ™‚๏ธ Detectors

InterfaceDetector bot

This bot takes contract-deconstruct bot output (it reads fired alerts) and uses them to automatically detect if the newly deployed contract adheres to some known interfaces.

About the new contract deployed it detects:

  • If it is an Ownable contract
  • If it adheres to ERC20 interface
  • If it adheres to ERC721 interface
  • If it is an AccessControl contract
  • If it has upgradebility contract by exposing upgradeTo and upgradeToAndCall functions. This can be either a proxy (either ERC1967 or not) or an UUPS implementation contract.
  • If it is an UUPS implementation logic contract
  • If it adheres to ERC1967 interface
  • If it is a TransparentUpgradeableProxy contract
  • If it is a ProxyAdmin contract

Read here on how to add more supported interfaces.

The current output is an alert of the form

{
  "name": "XXX interface detected", // XXX is the interface name detected
  "description": "Contract XXX adheres YYY interface", // XXX is contract address, YYY the detected interface
  "alertId": "XXX interface detected", // XXX is the interface name detected
  "protocol": "ethereum",
  "severity": "Info",
  "type": "Info",
  "metadata": {
    "contractAddress": , // the contract address
    "overallConfidence": , // confidence level, many function signatures can correspond to different actual functions
    "extras": "{}" // extra fields
  }
}

๐Ÿ’ฅ Hunters

contract-bots-gang's People

Contributors

xaler5 avatar josepchetrit12 avatar

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.