Giter VIP home page Giter VIP logo

ethernaut-x-foundry's Introduction

ethernaut-x-foundry

Ethernaut puzzles solved & tested with foundry.

Ethernaut

https://ethernaut.openzeppelin.com/

Foundry

https://github.com/foundry-rs/foundry

Setup

@0xEval has written an excellent run through of how the repo is configured and how to get setup on it.

https://eval.hashnode.dev/ethernaut-x-foundry-0x0-hello-ethernaut

Info

This repo is setup to enable you to run the ethernaut levels locally rather than on Rinkeby. As a result you will see some contracts that are not related to individual level but instead to ethernaut's core contracts which determine if you have passed the level.

These are the Ethernaut.sol & BaseLevel.sol contracts in the root of ./src and the factory contracts which have a naming convention of [LEVEL_NAME]Factory.sol in each levels repo. Have a read through if interested in what they do otherwise they can be ignored.

Make sure you're on the latest version of forge, what is your forge —version output? If it doesn’t show a date, try rm -rf ~/.cargo/bin/cast && rm -rf ~/.cargo/bin/forge

At the root of the repo run

foundryup 
forge install 
forge test

File Locations

Individual Levels can be found in their respective folders in the ./src folder.

Eg Fallback is located in ./src/Fallback/Fallback.sol

Tests for each level can be found in the ./src/test folder and have the naming convention [LEVEL_NAME].t.sol

Eg Fallback test are located in ./src/test/Fallback.t.sol

Levels

Level
1. Fallback
2. Fallout
3. CoinFlip
4. Telephone
5. Token
6. Delegation
7. Force
8. Vault
9. King
10. Re-Entrancy
11. Elevator
12. Privacy
13. GatekeeperOne
14. GatekeeperTwo
15. NaughtCoin
16. Preservation
17. Recovery
18. Magic Number
19. AlienCodex
20. Denial
21. Shop
22. Dex
23. Dex Two
24. PuzzleWallet
25. Motorbike

References

@cmichelio for his hardhat x ethernaut repo https://github.com/MrToph/ethernaut

@0xSage for his great ethernaut tutorials - breaking down how each level can be defeated https://medium.com/hackernoon/ethernaut-lvl-0-walkthrough-abis-web3-and-how-to-abuse-them-d92a8842d71b

@gakonst for his help on the foundry support channels and the tool itself https://github.com/gakonst/foundry

@the_ethernaut for the puzzles to solve & learn from https://ethernaut.openzeppelin.com/level/0x9CB391dbcD447E645D6Cb55dE6ca23164130D008

ethernaut-x-foundry's People

Contributors

ciaranmcveigh5 avatar maddiaa0 avatar riordant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ethernaut-x-foundry's Issues

Question: add dependency on forge-std

Preface

Thanks for creating this repo, it's made tackling Ethernaut challenges more enjoyable!

Question

Are maintainers open to taking a dependency on forge-std? That way we can remove Vm.sol and import forge-std's Vm.sol. If maintainers are open to the idea, I can create a PR.

Proposal to remove solutions from main branch

Problem

When an engineer forks and uses this repo to start solving Ethernaut exercises, all solutions are present in the fork.

Proposal

Remove the solutions from the main branch but preserve them on a separate branch (perhaps calls solutions). I think it makes sense to preserve the solutions in case developers get stuck and want to refer to a reference example.

Forge test fails with `Invalid data` error

Summary

Tests are failing in the latest version of foundry-cli (v0.1.0). Recommended CLI command is also outdated.

Steps to reproduce:

  1. git clone --recursive https://github.com/ciaranmcveigh5/ethernaut-x-foundry.git
  2. forge build
  3. forge test -m Fallback --verbosity 3

Output:

➜ forge test -m Fallback --verbosity 3
no files changed, compilation skippped.
Running 1 test for "FallbackTest.json":FallbackTest
[FAIL. Reason: Invalid data] testFallbackHack() (gas: 921345)

Failure: testFallbackHack()

Use Local Memory Type Variable Instead of Global Storage Type Variable in Event to Save Gas

Hi, we recently have conducted a systematic study about Solidity event usage, evolution, and impact, and we are attempting to build a tool to improve the practice of Solidity event use based on our findings. We have tried our prototype tool on some of the most popular GitHub Solidity repositories, and for your repository, we find a potential optimization of gas consumption arisen from event use.

The point is that when we use emit operation to store the value of a certain variable, local memory type variable would be preferable to global storage type (state) variable if they hold the same value. The reason is that an extra SLOAD operation would be needed to access the variable if it is storage type, and the SLOAD operation costs 800 gas.

For your repository, we find that the following event use can be improved:

  • NaughtCoin.sol
    function name:constructor
    event name:  Transfer
    variable:    player->_player
  constructor(address _player) 
  ERC20('NaughtCoin', '0x0')
  public {
    player = _player;
    INITIAL_SUPPLY = 1000000 * (10**uint256(decimals()));
    // _totalSupply = INITIAL_SUPPLY;
    // _balances[player] = INITIAL_SUPPLY;
    _mint(player, INITIAL_SUPPLY);
    emit Transfer(address(0), player, INITIAL_SUPPLY);
  }

Do you find our results useful? Your reply and invaluable suggestions would be greatly appreciated, and are vital for improving our tool. Thanks a lot for your time!

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.