Skip to content

joshrio/solidity-by-example.github.io

 
 

Repository files navigation

solidity-by-example.github.io

TODO: simplify bi directional payment channel

Solidity By Example

License

MIT License

Basic - 0

  • hello world
  • first application (counter app)
  • primitives (uint, bytes32, address...)
  • variables (local, state, global)
  • getters and setters (tx)
  • ether and wei
  • gas and gas price

Basic - 1

Flow control
  • if / else (TODO: ternary)
  • for loop

Data types

  • mapping
    • CRUD
    • nested
    • not iterable
  • array
    • fixed size / dynamic size
    • CRUD
    • delete element (compact)
  • TODO?: string and bytes
  • enum
  • structs
  • data locations - storage, memory, calldata

Function

  • function

  • view and pure functions

  • error

  • function modifiers

  • events

Inheritance

  • constructor
  • inheritance
  • shadowing state variables
  • calling parent contracts
  • visibility
  • interface

Sending and Receiving Ether

  • payable
  • send ether from contract
  • fallback

Contract Interaction

  • call
  • delegate call
  • calling other contracts
  • creating contract from a contract (pre: calling other contract)

Misc

  • import
  • library
  • TODO? assembly

Cryptography

  • hash function
  • signature verification

Application

  • multisig wallet
  • erc20
  • iterable mapping
  • merkle tree
  • create2
  • payment channels (uni, bidirectional)
  • TODO?: casper?
  • TODO?: minimal proxy contract?

Hacks

  • reentrancy
  • arithmetic overflow / underflow
  • unexpected ether (self destruct)
  • read private data
  • delegatecall (pre: storage layout)
  • default visibility (skip)
  • entropy illusion
  • external contract referencing
  • honeypot (pre: external call & reentrancy)
  • short address / param attack (skip)
  • unchecked call return value (skip)
  • front running
  • DOS
  • block timestamp manipulation
  • constructor with care (skip)
  • unintializsd storage pointers (skip)
  • floating points and precisions (skip)
  • tx.origin

Ethernaut

  • hello ethernaut
  • fallback
  • fallout (constructor with care)
  • coin flip (randomness guessing head / tail based on prev block hash)
  • telephone
  • token
  • delegation (delegatecall to change ownership)
  • force
  • vault (read private data)
  • king
  • re-entrancy
  • elevation
  • privacy (optimized storage)
  • gatekeeper one
  • gatekeeper two
  • naught coin
  • preservation (delegatecall to change address and then ownership)
  • recovery
  • magic number (contract creation)
  • alien codex (edit ABI)
  • denial (denial of service using assert and using up all gas)
  • shop (external contract call)

Patterns

  • push vs pull
  • commit reveal
  • factory

TODO

  • search
  • build pipeline (.gitignore index.html.js and rebuild it when deploy)
  • exercises
  • sidenav and or link to next topic
  • seo
  • submarine send

0.6 memo

  • script to generate routes

  • redirect to current page for 0.5 and 0.6

  • typescript

  • override and virtual

  • shadow disallowed

  • fallback and receive

  • 0.6 features

Memo

# deploy
npm run deploy

# find and compile sol
find src/pages/0.6 -name "*.sol" -exec docker run -v $PWD/src:/src ethereum/solc:0.6.0 {} \;

# compile single file
docker run -v $PWD/src:/src ethereum/solc:0.6.0 /src/pages/0.6/sol/HelloWorld/HelloWorld.sol

# md to react
npm run md-to-react -- path/to/folder/with/md

# md to react all pages
find src -type d -not -path "*/__snapshots__" -exec npm run md-to-react -- {} \;

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 64.9%
  • Solidity 34.0%
  • Other 1.1%