Smart Contract Security

Automated auditing, reentrancy guards, and flashloan attack prevention.

j4flmao Updated

File contents

Smart Contract Security

Reentrancy Guards

Use the Checks-Effects-Interactions pattern and OpenZeppelin's ReentrancyGuard.

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

contract Vault is ReentrancyGuard {
    mapping(address => uint) public balances;

    function withdraw() external nonReentrant {
        uint bal = balances[msg.sender];
        require(bal > 0, "No balance");
        balances[msg.sender] = 0; // Effect
        (bool success, ) = msg.sender.call{value: bal}(""); // Interaction
        require(success, "Transfer failed");
    }
}

Flashloan Attack Prevention

Use decentralized oracles (Chainlink) or TWAP (Uniswap V3) to prevent price manipulation.

Security Audit Workflow

%%{init: {"theme": "default", "flowchart": {"useMaxWidth": true}}}%%
flowchart TD
    A[Source Code] --> B[Static Analysis (Slither)]
    B --> C[Fuzzing (Echidna)]
    C --> D[Formal Verification]
    D --> E[Manual Code Review]
    E --> F[Audit Report]

j4flmao/agent-skills/tree/main/skills/blockchain/smart-contract-security commit fbb560cde8

Frequently asked questions

npx skillmds@latest add j4flmao/smart-contract-security