Coder Social home page Coder Social logo

ethernaut's Introduction

The Ethernaut

ethernaut

The ethernaut is a Web3/Solidity based wargame inspired in overthewire.org and in the comic El Eternauta, to be played in the Ethereum Virtual Machine. Each level is a smart contract that needs to be 'hacked'.

The game acts both as a tool for those interested in learning ethereum, and as a way to catalogue historical hacks in levels. Levels can be infinite and the game does not require to be played in any particular order.

Level PR's are welcome!

Deployed Versions

You can find the current, official version at: ethernaut.zeppelin.solutions

You can find the DEVCON3 version (ctf contest) at: ethernaut-devcon3.zeppelin.solutions

Running locally (development)

  1. Install
git clone [email protected]:OpenZeppelin/ethernaut.git
npm install
  1. Start deterministic testrpc
npm run rpc
  1. You might want to import one of the private keys in scripts/rpc.sh to your Metamask wallet.
  2. Set target network ACTIVE_NETWORK in src/constants.js.
  3. Compile contracts
npx truffle compile
  1. Deploy contracts
npm run deploy:contracts
  1. Start react client
npm start
  1. Run solidity tests with
npx truffle test

Level development

  1. Develop level contract in contracts/levels. Levels must extend contracts/base/Level.sol for basic game compatibility. Levels emit instances whose state can be modified by players, and check such state to determine if the player has completed the level.
  2. Be nice and add a test xD
  3. Add an entry to gamedata/gamedata.json for the level. This will be used by the contract deployment script to automatically deploy and upload the contract to Ethernaut.sol.
  4. Create and edit gamedata/descriptions/levels/xxx.md and xxx_complete.md. One will be shown on the level's page and the other when the level is completed). Note that your entry in gamedata.json must point to these md files.

Example level development: King

Let's suppose that we are creating the level "King" (which is already created and available in the game of course).

  1. For this repo, clone and npm install.
  2. Use the other levels as a basis, eg. duplicate DummyFactory.sol and Dummy.sol.
  3. Rename and modify the contracts to KingFactory.sol and King.sol.
  4. Implement the desired instance and factory logic in solidity. See current levels and notes to understand how the game mechanics work.
  5. Edit test/LevelTests.js and add a test. In this case, look for the "King" section.
  6. Run truffle test and once all tests pass, register the level in gamedata/gamedata.json. This file is used by the app to display data, connect to contracts, etc. It is also used by the contract deployer script in scripts/deploy_contracts.
  7. The level should now show up in the ui. To start it, set src/constants.js' ACTIVE_NETWORK to DEVELOPMENT and run npm start.
  8. Add a description markdwon file, in this case gamedata/levels/king.md (make sure gamedata.json points to it). This content will now be displayed in the ui for the level.
  9. Verify that the level is playable and winnable.
  10. Add a completed description markdown file, in this case gamedata/levels/king_complete.md (make sure gamedata.json points to it). The level will display this as additional info once the level is solved, usually to include historical information related to the level.
  11. Make a PR request so that we can re-deploy the game with the new level!

Deployment

To deploy the react app use npm run deploy:ui. Of course, you will need ssh credentials for this.

To deploy the contracts on ropsten, first set the ACTIVE_NETWORK variable in constants.js and then edit gamedata.json. This file keeps a history of all level instances in each level data's deployed_ropsten array. To deploy a new instance, add an "x" entry to the array, like so:

"deployed_ropsten": [
  "x",
  "0x4b1d5eb6cd2849c7890bcacd63a6855d1c0e79d5",
  "0xdf51a9e8ce57e7787e4a27dd19880fd7106b9a5c"
],

Then run npm run deploy:contracts. This action will effectively deploy a new version of the level data item whose deployed_ropsten array was updated, and will point the ethernaut dapp to use this new deployed contract instance for the level.

ethernaut's People

Contributors

theethernaut avatar kylriley avatar martriay avatar 0age avatar come-maiz avatar spalladino avatar

Watchers

James Cloos 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.