Code Monkey home page Code Monkey logo

ethernaut-foundry's Introduction


Logo

ethernaut-foundry

This is an Ethernaut challenge solution written with Foundry

Test and verify as you wish!

Description

Product Name Screen Shot

This is a Foundry's forge-based Ethernaut challenge solution. The code is written using the Forge Standard Library and you can test and validate the attack transactions.

❗Notes

Since each challenge has a different solidity version, instead of deploying the ethernaut contract, implemented it by creating and validating challenge instances directly through each challenge factory contract. The following two challenges have exceptions:

  • Alien Codex
    Spoiler warning Since this challenge does not compile in solidity version 0.6 or later, loaded the bytecode compiled in version 0.5 directly into memory and created an instance using the create opcode.
  • Motorbike
    Spoiler warning The challenge is to verify that the contract instance is self-destructed, which is impossible to verify with a forge test because code deletion occurs after the transaction. Therefore, verified it by checking the balance.

Getting Started

Prerequisites

Before we get started, you'll need to install foundry.

curl -L https://foundry.paradigm.xyz | bash
foundryup

Then, run the following commands:

git clone https://github.com/beaverx00/ethernaut-foundry.git
cd ethernaut-foundry
forge install

Directory Structure

├── lib
│   ├── forge-std
│   ├── openzeppelin-contracts
│   └── openzeppelin-contracts-solc-0.6
├── src
│   ├── levels
│   │   ├── Reentrance.sol
│   │   └── ReentranceFactory.sol
│   └── attacks
│       └── ReentranceAttack.sol
└── test
    └── Reentrance.t.sol

Using the Reentrance challenge as an example, the src directory contains Reentrance.sol, the challenge contract, and ReentranceFactory.sol, which creates challenge instances and validates the results. The test directory contains the Reentrance.t.sol file, which contains the test code to perform the attack and request validation. Finally, if you need a separate contract deployment for challenge solving, it exists under the attacks directory.

Usage

All test contracts are named <Challenge>Test (for example, ReentranceTest) and the test function is named test_<Challenge>()(e.g. test_Reentrance())

If you want to test the Reentrance, you can do the following:

forge test --match-contract=Reentrance -vvvv

You can check emiited logs and stack traces during test. Further information, see Foundry Book

List of Challenges

  1. Fallback
  2. Fallout
  3. Coin Flip
  4. Telephone
  5. Token
  6. Delegation
  7. Force
  8. Vault
  9. King
  10. Re-entrancy
  11. Elevator
  12. Privacy
  13. Gatekeeper One
  14. Gatekeeper Two
  15. Naught Coin
  16. Preservation
  17. Recovery
  18. MagicNumber
  19. Alien Codex
  20. Denial
  21. Shop
  22. Dex
  23. Dex Two
  24. Puzzle Wallet
  25. Motorbike
  26. DoubleEntryPoint
  27. Good Samaritan
  28. Gatekeeper Three

Acknowledgments

ethernaut-foundry's People

Contributors

beaverx00 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.