Key Takeaways

  • $3B+ stolen in Web3 hacks (2022)
  • Smart contracts are immutable once deployed
  • Reentrancy is still #1 vulnerability
  • Audits are essential but not sufficient

1. Web3 Security Landscape

Web3 security is a rapidly growing field due to the massive value at risk. Unlike traditional apps, blockchain exploits are often irreversible, and attackers can be anonymous.

2. Smart Contract Vulnerabilities

3. Reentrancy Attacks

Vulnerable Code
// VULNERABLE - Reentrancy
function withdraw() public {
    uint amount = balances[msg.sender];
    (bool success, ) = msg.sender.call{value: amount}("");
    require(success);
    balances[msg.sender] = 0;  // Updated AFTER external call!
}

// SECURE - Checks-Effects-Interactions
function withdraw() public {
    uint amount = balances[msg.sender];
    balances[msg.sender] = 0;  // Update BEFORE external call
    (bool success, ) = msg.sender.call{value: amount}("");
    require(success);
}

4. DeFi-Specific Risks

# Flash Loan Attack Pattern:
1. Borrow millions (no collateral needed)
2. Manipulate price oracle
3. Exploit vulnerable protocol at manipulated price
4. Repay loan
5. Keep profits

# Defense:
# - TWAP oracles (time-weighted average)
# - Multiple price sources
# - Flash loan guards

5. Smart Contract Auditing

# Audit checklist:
# - Reentrancy vulnerabilities
# - Access control issues
# - Arithmetic errors (use SafeMath or Solidity 0.8+)
# - Front-running potential
# - Oracle dependencies
# - Upgrade mechanism safety
# - Gas optimization

# Tools:
# Slither - Static analysis
slither ./contracts

# Mythril - Symbolic execution
myth analyze contracts/Contract.sol

# Echidna - Fuzzing
echidna-test contracts/Contract.sol

6. Wallet Security

7. Web3 Security Tools

ToolPurpose
SlitherStatic analysis
MythrilSymbolic execution
EchidnaFuzzing
FoundryTesting framework
TenderlyDebugging, simulation

8. Web3 Security Career

FAQ

How do I get started in Web3 security?
Learn Solidity and EVM basics, study past exploits (rekt.news), practice on CTFs (Ethernaut, Damn Vulnerable DeFi), start bug hunting on Immunefi.

Cryptography Bug Bounty Secure Coding