{"id":"solidity-security","name":"solidity-security","summary":"スマートコントラクトのセキュリティベストプラクティスをマスターし、一般的な脆弱性を防ぎ、安全なSolidityパターンを実装しましょう。","body":"# Solidity Security\n\nMaster smart contract security best practices, vulnerability prevention, and secure Solidity development patterns.\n\n## When to Use This Skill\n\n- Writing secure smart contracts\n- Auditing existing contracts for vulnerabilities\n- Implementing secure DeFi protocols\n- Preventing reentrancy, overflow, and access control issues\n- Optimizing gas usage while maintaining security\n- Preparing contracts for professional audits\n- Understanding common attack vectors\n\n## Detailed patterns and worked examples\n\nDetailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.\n\n## Testing for Security\n\n```javascript\n// Hardhat test example\nconst { expect } = require(\"chai\");\nconst { ethers } = require(\"hardhat\");\n\ndescribe(\"Security Tests\", function () {\n  it(\"Should prevent reentrancy attack\", async function () {\n    const [attacker] = await ethers.getSigners();\n\n    const VictimBank = await ethers.getContractFactory(\"SecureBank\");\n    const bank = await VictimBank.deploy();\n\n    const Attacker = await ethers.getContractFactory(\"ReentrancyAttacker\");\n    const attackerContract = await Attacker.deploy(bank.address);\n\n    // Deposit funds\n    await bank.deposit({ value: ethers.utils.parseEther(\"10\") });\n\n    // Attempt reentrancy attack\n    await expect(\n      attackerContract.attack({ value: ethers.utils.parseEther(\"1\") }),\n    ).to.be.revertedWith(\"ReentrancyGuard: reentrant call\");\n  });\n\n  it(\"Should prevent integer overflow\", async function () {\n    const Token = await ethers.getContractFactory(\"SecureToken\");\n    const token = await Token.deploy();\n\n    // Attempt overflow\n    await expect(token.transfer(attacker.address, ethers.constants.MaxUint256))\n      .to.be.reverted;\n  });\n\n  it(\"Should enforce access control\", async function () {\n    const [owner, attacker] = await ethers.getSigners();\n\n    const Contract = await ethers.getContractFactory(\"SecureContract\");\n    const contract = await Contract.deploy();\n\n    // Attempt unauthorized withdrawal\n    await expect(contract.connect(attacker).withdraw(100)).to.be.revertedWith(\n      \"Ownable: caller is not the owner\",\n    );\n  });\n});\n```\n\n## Audit Preparation\n\n```solidity\ncontract WellDocumentedContract {\n    /**\n     * @title Well Documented Contract\n     * @dev Example of proper documentation for audits\n     * @notice This contract handles user deposits and withdrawals\n     */\n\n    /// @notice Mapping of user balances\n    mapping(address => uint256) public balances;\n\n    /**\n     * @dev Deposits ETH into the contract\n     * @notice Anyone can deposit funds\n     */\n    function deposit() public payable {\n        require(msg.value > 0, \"Must send ETH\");\n        balances[msg.sender] += msg.value;\n    }\n\n    /**\n     * @dev Withdraws user's balance\n     * @notice Follows CEI pattern to prevent reentrancy\n     * @param amount Amount to withdraw in wei\n     */\n    function withdraw(uint256 amount) public {\n        // CHECKS\n        require(amount <= balances[msg.sender], \"Insufficient balance\");\n\n        // EFFECTS\n        balances[msg.sender] -= amount;\n\n        // INTERACTIONS\n        (bool success, ) = msg.sender.call{value: amount}(\"\");\n        require(success, \"Transfer failed\");\n    }\n}\n```","author":"@wshobson","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/wshobson/agents/tree/main/plugins/blockchain-web3/skills/solidity-security","license":"MIT","category":"writing","lang":"en","tokens":690,"stars":0,"calls30d":2,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[{"path":"references/details.md","size":9611,"sha256":"298dbd7d916dfc14e8f8bd4307c16ed0001a48c0bf3ea5f55ad78da9246a72d4"}],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[],"scannedAt":"2026-08-22","hasScripts":false,"networkEndpoints":[]}}