Coinmonks
Published in

Coinmonks

Ethernaut Lvl 8 Vault Walkthrough — How to read “private” variables in contract storage (with Truffle)

This is a in-depth series around Zeppelin team’s smart contract security puzzles. We learn key Solidity concepts to solve the puzzles 100% on your own.

How Ethereum Storage works

  1. how Ethereum stores contract data on the blockchain, and
  2. how Solidity stores global and local variables.

Storage on Ethereum blockchain is 2²⁵⁶ slots, and each slot is 32 bytes.

How data is physically stored

Notice that bool and uint16 share slot 0, indicating this contract also costs less gas to instantiate!

Accessing storage

Detailed Walkthrough

Level Setup

  1. Notice you cannot step through the Remix debugger with live contracts. So let’s use a more powerful tool to interact with this contract. Follow this 8 minute Truffle & Ropsten tutorial to get acquainted with interacting with contracts using Truffle framework.

Solution

truffle deploy   // auto compiles and deploys to local network
truffle console --network Ropsten
web3.eth.getStorageAt(instance.address, 1, (err,res)=>{console.log(res)});

--

--

Coinmonks (http://coinmonks.io/) is a non-profit Crypto Educational Publication. Follow us on Twitter @coinmonks and Our other project —  https://coincodecap.com, Email  — gaurav@coincodecap.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store