Blockchain Security
Smart contract vulnerabilities, attack vectors, audit practices, and security tools.
Overview
Blockchain security protects against attacks and vulnerabilities.
Common Vulnerabilities
| Vulnerability | Impact |
|---|---|
| Reentrancy | Fund theft |
| Flash Loan Attack | Price manipulation |
| Front-running | MEV extraction |
| Oracle Manipulation | Wrong prices |
Reentrancy Attack
// Vulnerable contract
contract Vulnerable {
mapping(address => uint256) public balances;
function withdraw() public {
uint256 balance = balances[msg.sender];
require(balance > 0);
(bool success, ) = msg.sender.call{value: balance}("");
require(success);
balances[msg.sender] = 0;
}
}
// Secure contract
contract Secure {
mapping(address => uint256) public balances;
function withdraw() public nonReentrant {
uint256 balance = balances[msg.sender];
require(balance > 0);
balances[msg.sender] = 0;
(bool success, ) = msg.sender.call{value: balance}("");
require(success);
}
}
Security Tools
| Tool | Purpose |
|---|---|
| Slither | Static analysis |
| Mythril | Symbolic execution |
| Echidna | Fuzzing |
| Certora | Formal verification |
Practice
Audit a smart contract and fix vulnerabilities.