GithubHelp home page GithubHelp logo

reticenceji / forge-poc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from immunefi-team/forge-poc-templates

0.0 0.0 0.0 208 KB

License: GNU Lesser General Public License v3.0

Solidity 100.00%

forge-poc's Introduction

GitHub issues LGPLv3 license

Immunefi Discord Twitter Medium YouTube

This is a collaborative repository that aims to provide reusable and easily modifiable PoC examples for a variety of EVM based vulnerabilities. This will increase the quality of bug reports and allow whitehats an easier, faster way to create PoCs and verify their claims. These templates are intended for testing proof of concepts in local forks for submission to bug bounty programs. Any other use is explicitly prohibited.

Overview

Installation

Foundry is required to use this repository. See: https://book.getfoundry.sh/getting-started/installation.

Getting Started ๐Ÿ“–

1๏ธโƒฃ First, set up the interfaces for the protocol you will be creating a PoC for. You can create your own interface contracts, create an interface automatically with Foundry's cast interface commandline tool, or download the full source code for contracts for the protocol using Foundry's cast etherscan-source command line tool. To use the cast commands, define the ETHERSCAN_API_KEY environment variable, then call cast with either of the following methods:

a. Download the interface (recommended)

Rather than copying the entire smart contract code itself, you can use the Interface feature introduced in Solidity version 0.6.x to define which functions a contract implements. To do so automatically, run the following command in the console:

cast interface [address] -o src/external/interfaces/IExample.sol -n IExample

Foundry automatically creates the interface based on the externally available functions according to the contracts ABI. Then import the newly created interface contract in your PoC:

import "./external/interfaces/IExample.sol";

see also: ABI to sol

b. Download the entire source code

Alternatively, you can download the entire source code from Etherscan like block explorers using the following command:

*๐Ÿšจ When downloading source code from deployed contracts, there may be remappings that need to be modified for the source files to compile. Add any necessary remappings to remappings.txt.
cast etherscan-source [address] -d src/external

This will download the contracts' entire source code to src/external, where you can import any contract interfaces by adding the following to the top of your PoC:

import "./external/ExampleProtocol/ExampleEtherscanContract.sol";

Optionally, append --chain [chain_name] to specify a chain other than the Ethereum mainnet to download contracts from. Note: you will have to update your Etherscan API key when switching between different chains.


2๏ธโƒฃ Pick a PoC template and modify the template file which extends* from the corresponding source contract. Within the template contract, there will be comments describing how you can modify the PoC to fit your vulnerability.

*๐Ÿšจ When extending from an abstract contract, there will be functions which must be defined. Implement any undefined functions with your attack.


3๏ธโƒฃ Once you have completed your attack contract, navigate to the corresponding test file, import your attack contract, and modify the setUp() to replicate any necessary attack preconditions, such as forking from a network, initializing accounts with certain balances, or creating any other conditions which are necessary for the attack. Try to keep your setup as close to mainnet state as possible. The more the setup differs from the mainnet state, the harder it is for projects to verify your claims. Now, you're ready to run your PoC!

Running a PoC ๐Ÿš€

To use a template, run the following in the console:

forge test -vv --match-path test/[test_name]

Environment Variables

Variable Example
ETHERSCAN_API_KEY [API_KEY]

Template Categories ๐Ÿชฒ

Categorisation Template Source Test Documentation
Reentrancy Template Source Test Readme
Token Balance Manipulation Template Source Test Readme
Flash Loan Template Source Test Readme
Price Manipulation Template Source Test Readme

Foundry Concepts

PoCs from our community โœจ

Contribute ๐Ÿ“

We sincerely appreciate contributions to Immunefi's templates. Please take the time to review the contribution guidelines and code of conduct to ensure your contributions are merged as soon as possible.

Contributors

All set!

If you have any questions, feel free to post them to https://github.com/immunefi-team/forge-poc-templates/issues.

Finally, if you're looking to collaborate and want to find easy tasks to start, look at the issues we marked as "Good first issue".

Thanks for your time and code!

forge-poc's People

Contributors

alejandro-immunefi avatar arbaz-immunefi avatar gibranakbaromil avatar goncalomagalhaes avatar iphelix avatar janbro avatar juliusbrain avatar pepin-immunefi 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.