GithubHelp home page GithubHelp logo

catherinee24 / fondry-patrick-security Goto Github PK

View Code? Open in Web Editor NEW

This project forked from patrickalphac/denver-security

0.0 1.0 0.0 11 KB

๐ŸŽ† Full Foundry Course with Patrick Collins. Security Tools

Solidity 100.00%

fondry-patrick-security's Introduction

About

โญ๏ธ (7:21:12) | Lesson 15 | Security & Auditing

Learning how to use security tooling to find bugs!

Getting Started

Requirements

Please install the following:

  • Git
    • You'll know you've done it right if you can run git --version
  • Foundry / Foundryup
    • This will install forge, cast, and anvil
    • You can test you've installed them right by running forge --version and get an output like: forge 0.2.0 (f016135 2022-07-04T00:15:02.930499Z)
    • To get the latest of each, just run foundryup

Quickstart

git clone https://github.com/PatrickAlphaC/denver-security
cd denver-security
forge install

Then, run our test suite, lots of stuff fails!!

forge test

Let's use tools to find bugs!

Manul Review

In CaughtWithManualReview.sol we see doMath should add 2 instead of one! We were only able to know this because we read the documentation associated with the function.

Test Suite

CaughtWithTest.sol's setNumber should set number to the input parameter, but it doesn't!

To catch this, we write a test for our expected output, and run:

forge test -m testSetNumber -vv

Static Analysis

Prerequisites

  • Python
    • You'll know you've installed python right if you can run:
      • python --version or python3 --version and get an output like: Python x.x.x
  • pipx
    • pipx is different from pip
    • You may have to close and re-open your terminal
    • You'll know you've installed it right if you can run:
      • pipx --version and see something like x.x.x.x

We recommend installing slither with pipx instead of pip. Feel free to use the slither documentation if you prefer.

pipx install slither-analyzer

To run slither, run:

slither . --exclude-dependencies

See what it outputs!

Fuzzing

CaughtWithFuzz.sol's doMoreMath should never return 0... but how can we make sure of this? We can pass random data to it!

To catch this, we write a test for our expected output, and run:

forge test -m testFuzz -vv

Stateful fuzzing (invariants)

Our CaughtWithStatefulFuzz contract's doMoreMathAgain should never return 0... and looking at it, a regular fuzz test wouldn't work!

You can run:

forge test -m testFuzzPasses

And no matter what, it'll always pass! We need to call setValue first, and then we can get it to revert! Invariant/Stateful Fuzzing tests do random data input combined with random function calls.

Run:

forge test -m invariant_testMathDoesntReturnZero -vv

And you'll see the 2 calls made to fail!

Formal Verification (SMT Checker)

In foundry.toml uncomment the profile.default.model_checker section.

Then, just run: forge build

Our solidity modeled our functionOneSymbolic to be a math equation, and then, solved for the math!

fondry-patrick-security's People

Contributors

patrickalphac avatar robocrypter avatar

Watchers

 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.