GithubHelp home page GithubHelp logo

vnmrtz / mastering-fuzzing Goto Github PK

View Code? Open in Web Editor NEW
107.0 3.0 21.0 82 KB

Practical fuzzing examples for the mastering fuzzing talk

Home Page: https://www.youtube.com/watch?v=83q14K-WNKM

Solidity 100.00%

mastering-fuzzing's Introduction

Mastering Fuzzing

This repo contains all the details to follow along with the "Mastering Fuzzing" workshop/talk.

⭐ The target audience includes both smart contract developers and security people looking to improve their testing practices and dive into the world of fuzzing.

👉 If you are already used to working with fuzzing the first part of this content may be a bit too basic for you 😃

Foundry setup

All the fuzzing tests will be done using foundry and echidna. It does not matter if you are not familiar with the tool as the tests and examples are already prepared, so you just have to follow the instructions. However, if you want to learn more about the tool, please check the foundry official documentation

First and foremost, install Foundry following these details. After the successful installation, please run the following to check that everything is in place:

foundryup # look for updates
forge init myTestProject # Create a foundry template project
cd myTestProject 
forge test # run the current tests

If the above tests were successful, your Foundry instance is ready for the workshop ✔️

Now install echidna following these details.

After the successful installation, you are ready to start the workshop ✔️

Workshop

First and foremost, clone this repo, and install run the following command to install the dependences:

forge install 

You will find the demo contracts inside the src/ folder. And the different tests/PoCs inside the test/ folder.

Echidna tests are located under echidna and foundry tests under test/. The echidna tests are already prepared to be run with the following command:

echidna --config echidna.yaml echidna/ERC20Test.sol --contract ERC20Test  

Fuzzing

Echidna

Echidna is a property-based fuzzer for Ethereum smart contracts. It is a tool that allows you to write tests in Solidity and then automatically generates inputs that trigger the tests to fail. It is a very powerful tool that can be used to find bugs.

The tests are written in Solidity and are very similar to the ones you may already be familiar with. The main difference is that you have to use the echidna_* functions to define the properties you want to test.

The file ERC20Test.sol contains a very simple example of internal testing with echidna. The test is very simple, it checks a few properties of the ERC20 token.

From the root of the repo, run the following command to run the test:

echidna --config echidna.yaml echidna/ERC20Test.sol --contract ERC20Test  

Prebuilt properties Echidna

Crytic has a set of prebuilt properties that can be used to test your contracts. You can find the list of properties here.

The file ERC20Harness.sol contains a very simple example of external testing with echidna. Using this set of prebuilt properties, we can test the ERC20 token.

Foundry

Foundry is a popular smart contract development framework that allows you to write tests in Sold¡ty. It comes with fuzzing and property-based testing support out of the box.

Run parametrized tests:

forge test --mp test/ClonesTest.t.sol

Run invariant tests:

forge test --mt invariant_poolBalanceAlwaysGtThanInitialBalance

Test with trace:

forge test --mt invariant_poolBalanceAlwaysGtThanInitialBalance -vvvv

mastering-fuzzing's People

Contributors

vnmrtz avatar josepbove avatar

Stargazers

 avatar Luigi avatar Harry Chen avatar Ishaq Nasir avatar aubrey avatar K3zy avatar Timuçin OSANMAZ avatar nikhil avatar Lev Menshchikov avatar  avatar  avatar Rudra Singh avatar Gr3yD0g avatar modprobe_daemon avatar Mr.X avatar AADII avatar gerald childs avatar Paul Birnbaum  avatar Seb avatar Ivan Kapranov avatar miguelmtz avatar  avatar  avatar Tuan avatar Xinyang avatar Elyx0 avatar Aan avatar  avatar Hazard Cookie avatar Nazgul avatar Gabriel Rosa avatar Joydeep Singha avatar GOWTHAM NAIDU PONNANA avatar Eugenio avatar Spark avatar Dheeraj avatar Bot Mechanic avatar  avatar Zero Ekkusu avatar  avatar Ononogbu Ebenezer avatar C H A L K avatar Archil avatar エヴァンゲリオン avatar 0xfave avatar Hawre avatar H@rsh avatar BAICE avatar Kavita B avatar panda cheeks avatar Aya KHEDDA avatar xiaodao avatar Isaac Almanza avatar  avatar Juan Ignacio Ubeira avatar Haythem Sellami avatar clandestine.eth avatar Hilliam T. avatar  avatar Owen Lee avatar Hajime  avatar  avatar  avatar  avatar Siosci avatar  avatar  avatar nap avatar N4NU avatar  avatar Sean Ng avatar Huy Doan avatar Tomas Rzepka avatar Haji avatar  avatar Ðavid avatar Rafael Nicolau avatar Omar Espino avatar Smith Noorah  avatar Eloi Manuel avatar Sithari avatar niluke avatar Tuna avatar Dijkstra Dev avatar Etch avatar Ilchovski avatar Temirzhan Yussupov avatar Vlad Toie avatar Sandalots avatar sudo rm -rf --no-preserve-root / avatar Shebin John avatar Kong' avatar  avatar Roshan Kumar avatar Lê Quốc Huy avatar aweMinchoo avatar 0x0918 avatar Samater avatar Kaiziron avatar Oba avatar

Watchers

 avatar  avatar 0x0918 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.