Expert Solidity Bootcamp – Week 3

Security and Auditing

Some Attacks

Not all hacks that happen are very sophisticated. Also some are general security problems.

  • Profanity Address: to create vanity addresses with leading 0’s. Brute force on certain keys and get control of the keys
  • Bridges are generally more vulnerable than normal contracts
  • Nomad Bridge Exploiter 1: etherscan named hacker addresses, so they were flagged and displayed like that
  • Optimizations cause quite several bugs too removing requires, flags etc to optimize gas
  • Poly Network hack
    • went across multiple chains (Ethereum, Polygon, Binance?)
    • low level call: call function signature – keccak hash of the ASCII form of the signature baz(uint32,bool)
    • attacker put messages into tx’s
    • 2 Contracts: Manager contract and Data contract. They had 1 address with several roles

Security

  • asserts: useful in formal verification
  • Locking pragmas: instead of using floating pragmas
  • Use events for all state changes and make sure you are watching them (i.e. tenderly)
  • Shadowing: variables names can shadow each other
  • tx.origin: never use it for access control. Only if your contract is being called by EOA or another contract
  • Timestamp Dependence: don’t use it for important logic, something very fine grain
  • Complex Inheritance: can change the way your contract behaves
  • Interface Types:
  • EXTCODESIZE checks: using this opcode to check the size of the code, and check if it’s a contract of an EOA. This doesn’t always work

Token Specific

  • Standardization
  • Check for the 0 address
  • Contract Address
  • NAT Spec

Attacks

  • Reentrancy
  • Oracle Manipulation
  • Insecure Arithmetic: data sizes (risk of overflows)
  • Denial of Services: the way you go through loops – pagination approach
  • Griefing:
  • Force Feeding: send funds to a contract

Auditing

  • The EVM is an unfamiliar platform, blockchain is an unfamiliar paradigm and Solidity is an unfamiliar language (source)
  • Importance of Code Freeze: no changes while going under an audit.
  • Specifying intended behaviour
  • Include in your report if client can rug pull
  • Assembly is harder to audit than solidity. Code is harder to read, several opcodes are not accessible via Solidity no usual safeguards
  • Code Smell

Auditing an ERC20 with the ERC20 checklist or this checklist

Resources

  • Slither: static analysis to find vulnerabilities / patterns
  • Echidna: fuzz tester
  • SWC Registry
  • Not so smart contracts
  • ZIION: virtual machine
  • Monitoring: Tenderly

Math Libraries

Libraries try to cover what basic language misses, but they are not standardized.

  • PRB Maths Library: beyond integer arithmetic. For advanced fixed-point math with signed and unsigned number
  • Uniswap Full Maths:

Stablecoins

  • An algorithmic stable coin (UST)

Wormholes

  • Does the 0 address have a private key?
  • why calldata cannot be copied?
  • Using constants is better because it means they are in the bytecode rather than being stored

Matter

  • Brute force a function selector to match another function, inspired by Poly Network hack
  • zkPoEX: zk proof of exploit

Leave a comment