[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M72XJ367YKNGPA66Z3Z9MX2F":3,"skill-same:01M72XJ367YKNGPA66Z3Z9MX2F":45},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":26,"repositoryHtmlUrl":27,"repositoryHomepageUrl":28,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M72XJ367YKNGPA66Z3Z9MX2F","solidity-security",null,"Master smart contract security best practices to prevent common vulnerabilities and implement secure Solidity patterns. Use when writing smart contracts, auditing existing contracts, or implementing security measures for blockchain applications.","steph-frtech\u002Fclaude-code-up","steph-frtech","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F198466323?v=4","01M72XD213FVQA2QXRGTJFKHE1","01M72XD227AANJ993SQTNZB1CK",1,"MIT","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fmarketplaces\u002Fwshobson\u002Fplugins\u002Fblockchain-web3\u002Fskills\u002Fsolidity-security\u002FSKILL.md",[],[],"2026-11-10 22:39:42",false,"---\nname: solidity-security\ndescription: Master smart contract security best practices to prevent common vulnerabilities and implement secure Solidity patterns. Use when writing smart contracts, auditing existing contracts, or implementing security measures for blockchain applications.\n---\n\n# 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## Critical Vulnerabilities\n\n### 1. Reentrancy\n\nAttacker calls back into your contract before state is updated.\n\n**Vulnerable Code:**\n\n```solidity\n\u002F\u002F VULNERABLE TO REENTRANCY\ncontract VulnerableBank {\n    mapping(address => uint256) public balances;\n\n    function withdraw() public {\n        uint256 amount = balances[msg.sender];\n\n        \u002F\u002F DANGER: External call before state update\n        (bool success, ) = msg.sender.call{value: amount}(\"\");\n        require(success);\n\n        balances[msg.sender] = 0;  \u002F\u002F Too late!\n    }\n}\n```\n\n**Secure Pattern (Checks-Effects-Interactions):**\n\n```solidity\ncontract SecureBank {\n    mapping(address => uint256) public balances;\n\n    function withdraw() public {\n        uint256 amount = balances[msg.sender];\n        require(amount > 0, \"Insufficient balance\");\n\n        \u002F\u002F EFFECTS: Update state BEFORE external call\n        balances[msg.sender] = 0;\n\n        \u002F\u002F INTERACTIONS: External call last\n        (bool success, ) = msg.sender.call{value: amount}(\"\");\n        require(success, \"Transfer failed\");\n    }\n}\n```\n\n**Alternative: ReentrancyGuard**\n\n```solidity\nimport \"@openzeppelin\u002Fcontracts\u002Fsecurity\u002FReentrancyGuard.sol\";\n\ncontract SecureBank is ReentrancyGuard {\n    mapping(address => uint256) public balances;\n\n    function withdraw() public nonReentrant {\n        uint256 amount = balances[msg.sender];\n        require(amount > 0, \"Insufficient balance\");\n\n        balances[msg.sender] = 0;\n\n        (bool success, ) = msg.sender.call{value: amount}(\"\");\n        require(success, \"Transfer failed\");\n    }\n}\n```\n\n### 2. Integer Overflow\u002FUnderflow\n\n**Vulnerable Code (Solidity \u003C 0.8.0):**\n\n```solidity\n\u002F\u002F VULNERABLE\ncontract VulnerableToken {\n    mapping(address => uint256) public balances;\n\n    function transfer(address to, uint256 amount) public {\n        \u002F\u002F No overflow check - can wrap around\n        balances[msg.sender] -= amount;  \u002F\u002F Can underflow!\n        balances[to] += amount;          \u002F\u002F Can overflow!\n    }\n}\n```\n\n**Secure Pattern (Solidity >= 0.8.0):**\n\n```solidity\n\u002F\u002F Solidity 0.8+ has built-in overflow\u002Funderflow checks\ncontract SecureToken {\n    mapping(address => uint256) public balances;\n\n    function transfer(address to, uint256 amount) public {\n        \u002F\u002F Automatically reverts on overflow\u002Funderflow\n        balances[msg.sender] -= amount;\n        balances[to] += amount;\n    }\n}\n```\n\n**For Solidity \u003C 0.8.0, use SafeMath:**\n\n```solidity\nimport \"@openzeppelin\u002Fcontracts\u002Futils\u002Fmath\u002FSafeMath.sol\";\n\ncontract SecureToken {\n    using SafeMath for uint256;\n    mapping(address => uint256) public balances;\n\n    function transfer(address to, uint256 amount) public {\n        balances[msg.sender] = balances[msg.sender].sub(amount);\n        balances[to] = balances[to].add(amount);\n    }\n}\n```\n\n### 3. Access Control\n\n**Vulnerable Code:**\n\n```solidity\n\u002F\u002F VULNERABLE: Anyone can call critical functions\ncontract VulnerableContract {\n    address public owner;\n\n    function withdraw(uint256 amount) public {\n        \u002F\u002F No access control!\n        payable(msg.sender).transfer(amount);\n    }\n}\n```\n\n**Secure Pattern:**\n\n```solidity\nimport \"@openzeppelin\u002Fcontracts\u002Faccess\u002FOwnable.sol\";\n\ncontract SecureContract is Ownable {\n    function withdraw(uint256 amount) public onlyOwner {\n        payable(owner()).transfer(amount);\n    }\n}\n\n\u002F\u002F Or implement custom role-based access\ncontract RoleBasedContract {\n    mapping(address => bool) public admins;\n\n    modifier onlyAdmin() {\n        require(admins[msg.sender], \"Not an admin\");\n        _;\n    }\n\n    function criticalFunction() public onlyAdmin {\n        \u002F\u002F Protected function\n    }\n}\n```\n\n### 4. Front-Running\n\n**Vulnerable:**\n\n```solidity\n\u002F\u002F VULNERABLE TO FRONT-RUNNING\ncontract VulnerableDEX {\n    function swap(uint256 amount, uint256 minOutput) public {\n        \u002F\u002F Attacker sees this in mempool and front-runs\n        uint256 output = calculateOutput(amount);\n        require(output >= minOutput, \"Slippage too high\");\n        \u002F\u002F Perform swap\n    }\n}\n```\n\n**Mitigation:**\n\n```solidity\ncontract SecureDEX {\n    mapping(bytes32 => bool) public usedCommitments;\n\n    \u002F\u002F Step 1: Commit to trade\n    function commitTrade(bytes32 commitment) public {\n        usedCommitments[commitment] = true;\n    }\n\n    \u002F\u002F Step 2: Reveal trade (next block)\n    function revealTrade(\n        uint256 amount,\n        uint256 minOutput,\n        bytes32 secret\n    ) public {\n        bytes32 commitment = keccak256(abi.encodePacked(\n            msg.sender, amount, minOutput, secret\n        ));\n        require(usedCommitments[commitment], \"Invalid commitment\");\n        \u002F\u002F Perform swap\n    }\n}\n```\n\n## Security Best Practices\n\n### Checks-Effects-Interactions Pattern\n\n```solidity\ncontract SecurePattern {\n    mapping(address => uint256) public balances;\n\n    function withdraw(uint256 amount) public {\n        \u002F\u002F 1. CHECKS: Validate conditions\n        require(amount \u003C= balances[msg.sender], \"Insufficient balance\");\n        require(amount > 0, \"Amount must be positive\");\n\n        \u002F\u002F 2. EFFECTS: Update state\n        balances[msg.sender] -= amount;\n\n        \u002F\u002F 3. INTERACTIONS: External calls last\n        (bool success, ) = msg.sender.call{value: amount}(\"\");\n        require(success, \"Transfer failed\");\n    }\n}\n```\n\n### Pull Over Push Pattern\n\n```solidity\n\u002F\u002F Prefer this (pull)\ncontract SecurePayment {\n    mapping(address => uint256) public pendingWithdrawals;\n\n    function recordPayment(address recipient, uint256 amount) internal {\n        pendingWithdrawals[recipient] += amount;\n    }\n\n    function withdraw() public {\n        uint256 amount = pendingWithdrawals[msg.sender];\n        require(amount > 0, \"Nothing to withdraw\");\n\n        pendingWithdrawals[msg.sender] = 0;\n        payable(msg.sender).transfer(amount);\n    }\n}\n\n\u002F\u002F Over this (push)\ncontract RiskyPayment {\n    function distributePayments(address[] memory recipients, uint256[] memory amounts) public {\n        for (uint i = 0; i \u003C recipients.length; i++) {\n            \u002F\u002F If any transfer fails, entire batch fails\n            payable(recipients[i]).transfer(amounts[i]);\n        }\n    }\n}\n```\n\n### Input Validation\n\n```solidity\ncontract SecureContract {\n    function transfer(address to, uint256 amount) public {\n        \u002F\u002F Validate inputs\n        require(to != address(0), \"Invalid recipient\");\n        require(to != address(this), \"Cannot send to contract\");\n        require(amount > 0, \"Amount must be positive\");\n        require(amount \u003C= balances[msg.sender], \"Insufficient balance\");\n\n        \u002F\u002F Proceed with transfer\n        balances[msg.sender] -= amount;\n        balances[to] += amount;\n    }\n}\n```\n\n### Emergency Stop (Circuit Breaker)\n\n```solidity\nimport \"@openzeppelin\u002Fcontracts\u002Fsecurity\u002FPausable.sol\";\n\ncontract EmergencyStop is Pausable, Ownable {\n    function criticalFunction() public whenNotPaused {\n        \u002F\u002F Function logic\n    }\n\n    function emergencyStop() public onlyOwner {\n        _pause();\n    }\n\n    function resume() public onlyOwner {\n        _unpause();\n    }\n}\n```\n\n## Gas Optimization\n\n### Use `uint256` Instead of Smaller Types\n\n```solidity\n\u002F\u002F More gas efficient\ncontract GasEfficient {\n    uint256 public value;  \u002F\u002F Optimal\n\n    function set(uint256 _value) public {\n        value = _value;\n    }\n}\n\n\u002F\u002F Less efficient\ncontract GasInefficient {\n    uint8 public value;  \u002F\u002F Still uses 256-bit slot\n\n    function set(uint8 _value) public {\n        value = _value;  \u002F\u002F Extra gas for type conversion\n    }\n}\n```\n\n### Pack Storage Variables\n\n```solidity\n\u002F\u002F Gas efficient (3 variables in 1 slot)\ncontract PackedStorage {\n    uint128 public a;  \u002F\u002F Slot 0\n    uint64 public b;   \u002F\u002F Slot 0\n    uint64 public c;   \u002F\u002F Slot 0\n    uint256 public d;  \u002F\u002F Slot 1\n}\n\n\u002F\u002F Gas inefficient (each variable in separate slot)\ncontract UnpackedStorage {\n    uint256 public a;  \u002F\u002F Slot 0\n    uint256 public b;  \u002F\u002F Slot 1\n    uint256 public c;  \u002F\u002F Slot 2\n    uint256 public d;  \u002F\u002F Slot 3\n}\n```\n\n### Use `calldata` Instead of `memory` for Function Arguments\n\n```solidity\ncontract GasOptimized {\n    \u002F\u002F More gas efficient\n    function processData(uint256[] calldata data) public pure returns (uint256) {\n        return data[0];\n    }\n\n    \u002F\u002F Less efficient\n    function processDataMemory(uint256[] memory data) public pure returns (uint256) {\n        return data[0];\n    }\n}\n```\n\n### Use Events for Data Storage (When Appropriate)\n\n```solidity\ncontract EventStorage {\n    \u002F\u002F Emitting events is cheaper than storage\n    event DataStored(address indexed user, uint256 indexed id, bytes data);\n\n    function storeData(uint256 id, bytes calldata data) public {\n        emit DataStored(msg.sender, id, data);\n        \u002F\u002F Don't store in contract storage unless needed\n    }\n}\n```\n\n## Common Vulnerabilities Checklist\n\n```solidity\n\u002F\u002F Security Checklist Contract\ncontract SecurityChecklist {\n    \u002F**\n     * [ ] Reentrancy protection (ReentrancyGuard or CEI pattern)\n     * [ ] Integer overflow\u002Funderflow (Solidity 0.8+ or SafeMath)\n     * [ ] Access control (Ownable, roles, modifiers)\n     * [ ] Input validation (require statements)\n     * [ ] Front-running mitigation (commit-reveal if applicable)\n     * [ ] Gas optimization (packed storage, calldata)\n     * [ ] Emergency stop mechanism (Pausable)\n     * [ ] Pull over push pattern for payments\n     * [ ] No delegatecall to untrusted contracts\n     * [ ] No tx.origin for authentication (use msg.sender)\n     * [ ] Proper event emission\n     * [ ] External calls at end of function\n     * [ ] Check return values of external calls\n     * [ ] No hardcoded addresses\n     * [ ] Upgrade mechanism (if proxy pattern)\n     *\u002F\n}\n```\n\n## Testing for Security\n\n```javascript\n\u002F\u002F 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    \u002F\u002F Deposit funds\n    await bank.deposit({ value: ethers.utils.parseEther(\"10\") });\n\n    \u002F\u002F 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    \u002F\u002F 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    \u002F\u002F 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    \u002F**\n     * @title Well Documented Contract\n     * @dev Example of proper documentation for audits\n     * @notice This contract handles user deposits and withdrawals\n     *\u002F\n\n    \u002F\u002F\u002F @notice Mapping of user balances\n    mapping(address => uint256) public balances;\n\n    \u002F**\n     * @dev Deposits ETH into the contract\n     * @notice Anyone can deposit funds\n     *\u002F\n    function deposit() public payable {\n        require(msg.value > 0, \"Must send ETH\");\n        balances[msg.sender] += msg.value;\n    }\n\n    \u002F**\n     * @dev Withdraws user's balance\n     * @notice Follows CEI pattern to prevent reentrancy\n     * @param amount Amount to withdraw in wei\n     *\u002F\n    function withdraw(uint256 amount) public {\n        \u002F\u002F CHECKS\n        require(amount \u003C= balances[msg.sender], \"Insufficient balance\");\n\n        \u002F\u002F EFFECTS\n        balances[msg.sender] -= amount;\n\n        \u002F\u002F INTERACTIONS\n        (bool success, ) = msg.sender.call{value: amount}(\"\");\n        require(success, \"Transfer failed\");\n    }\n}\n```\n","# 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## Critical Vulnerabilities\n\n### 1. Reentrancy\n\nAttacker calls back into your contract before state is updated.\n\n**Vulnerable Code:**\n\n```solidity\n\u002F\u002F VULNERABLE TO REENTRANCY\ncontract VulnerableBank {\n    mapping(address => uint256) public balances;\n\n    function withdraw() public {\n        uint256 amount = balances[msg.sender];\n\n        \u002F\u002F DANGER: External call before state update\n        (bool success, ) = msg.sender.call{value: amount}(\"\");\n        require(success);\n\n        balances[msg.sender] = 0;  \u002F\u002F Too late!\n    }\n}\n```\n\n**Secure Pattern (Checks-Effects-Interactions):**\n\n```solidity\ncontract SecureBank {\n    mapping(address => uint256) public balances;\n\n    function withdraw() public {\n        uint256 amount = balances[msg.sender];\n        require(amount > 0, \"Insufficient balance\");\n\n        \u002F\u002F EFFECTS: Update state BEFORE external call\n        balances[msg.sender] = 0;\n\n        \u002F\u002F INTERACTIONS: External call last\n        (bool success, ) = msg.sender.call{value: amount}(\"\");\n        require(success, \"Transfer failed\");\n    }\n}\n```\n\n**Alternative: ReentrancyGuard**\n\n```solidity\nimport \"@openzeppelin\u002Fcontracts\u002Fsecurity\u002FReentrancyGuard.sol\";\n\ncontract SecureBank is ReentrancyGuard {\n    mapping(address => uint256) public balances;\n\n    function withdraw() public nonReentrant {\n        uint256 amount = balances[msg.sender];\n        require(amount > 0, \"Insufficient balance\");\n\n        balances[msg.sender] = 0;\n\n        (bool success, ) = msg.sender.call{value: amount}(\"\");\n        require(success, \"Transfer failed\");\n    }\n}\n```\n\n### 2. Integer Overflow\u002FUnderflow\n\n**Vulnerable Code (Solidity \u003C 0.8.0):**\n\n```solidity\n\u002F\u002F VULNERABLE\ncontract VulnerableToken {\n    mapping(address => uint256) public balances;\n\n    function transfer(address to, uint256 amount) public {\n        \u002F\u002F No overflow check - can wrap around\n        balances[msg.sender] -= amount;  \u002F\u002F Can underflow!\n        balances[to] += amount;          \u002F\u002F Can overflow!\n    }\n}\n```\n\n**Secure Pattern (Solidity >= 0.8.0):**\n\n```solidity\n\u002F\u002F Solidity 0.8+ has built-in overflow\u002Funderflow checks\ncontract SecureToken {\n    mapping(address => uint256) public balances;\n\n    function transfer(address to, uint256 amount) public {\n        \u002F\u002F Automatically reverts on overflow\u002Funderflow\n        balances[msg.sender] -= amount;\n        balances[to] += amount;\n    }\n}\n```\n\n**For Solidity \u003C 0.8.0, use SafeMath:**\n\n```solidity\nimport \"@openzeppelin\u002Fcontracts\u002Futils\u002Fmath\u002FSafeMath.sol\";\n\ncontract SecureToken {\n    using SafeMath for uint256;\n    mapping(address => uint256) public balances;\n\n    function transfer(address to, uint256 amount) public {\n        balances[msg.sender] = balances[msg.sender].sub(amount);\n        balances[to] = balances[to].add(amount);\n    }\n}\n```\n\n### 3. Access Control\n\n**Vulnerable Code:**\n\n```solidity\n\u002F\u002F VULNERABLE: Anyone can call critical functions\ncontract VulnerableContract {\n    address public owner;\n\n    function withdraw(uint256 amount) public {\n        \u002F\u002F No access control!\n        payable(msg.sender).transfer(amount);\n    }\n}\n```\n\n**Secure Pattern:**\n\n```solidity\nimport \"@openzeppelin\u002Fcontracts\u002Faccess\u002FOwnable.sol\";\n\ncontract SecureContract is Ownable {\n    function withdraw(uint256 amount) public onlyOwner {\n        payable(owner()).transfer(amount);\n    }\n}\n\n\u002F\u002F Or implement custom role-based access\ncontract RoleBasedContract {\n    mapping(address => bool) public admins;\n\n    modifier onlyAdmin() {\n        require(admins[msg.sender], \"Not an admin\");\n        _;\n    }\n\n    function criticalFunction() public onlyAdmin {\n        \u002F\u002F Protected function\n    }\n}\n```\n\n### 4. Front-Running\n\n**Vulnerable:**\n\n```solidity\n\u002F\u002F VULNERABLE TO FRONT-RUNNING\ncontract VulnerableDEX {\n    function swap(uint256 amount, uint256 minOutput) public {\n        \u002F\u002F Attacker sees this in mempool and front-runs\n        uint256 output = calculateOutput(amount);\n        require(output >= minOutput, \"Slippage too high\");\n        \u002F\u002F Perform swap\n    }\n}\n```\n\n**Mitigation:**\n\n```solidity\ncontract SecureDEX {\n    mapping(bytes32 => bool) public usedCommitments;\n\n    \u002F\u002F Step 1: Commit to trade\n    function commitTrade(bytes32 commitment) public {\n        usedCommitments[commitment] = true;\n    }\n\n    \u002F\u002F Step 2: Reveal trade (next block)\n    function revealTrade(\n        uint256 amount,\n        uint256 minOutput,\n        bytes32 secret\n    ) public {\n        bytes32 commitment = keccak256(abi.encodePacked(\n            msg.sender, amount, minOutput, secret\n        ));\n        require(usedCommitments[commitment], \"Invalid commitment\");\n        \u002F\u002F Perform swap\n    }\n}\n```\n\n## Security Best Practices\n\n### Checks-Effects-Interactions Pattern\n\n```solidity\ncontract SecurePattern {\n    mapping(address => uint256) public balances;\n\n    function withdraw(uint256 amount) public {\n        \u002F\u002F 1. CHECKS: Validate conditions\n        require(amount \u003C= balances[msg.sender], \"Insufficient balance\");\n        require(amount > 0, \"Amount must be positive\");\n\n        \u002F\u002F 2. EFFECTS: Update state\n        balances[msg.sender] -= amount;\n\n        \u002F\u002F 3. INTERACTIONS: External calls last\n        (bool success, ) = msg.sender.call{value: amount}(\"\");\n        require(success, \"Transfer failed\");\n    }\n}\n```\n\n### Pull Over Push Pattern\n\n```solidity\n\u002F\u002F Prefer this (pull)\ncontract SecurePayment {\n    mapping(address => uint256) public pendingWithdrawals;\n\n    function recordPayment(address recipient, uint256 amount) internal {\n        pendingWithdrawals[recipient] += amount;\n    }\n\n    function withdraw() public {\n        uint256 amount = pendingWithdrawals[msg.sender];\n        require(amount > 0, \"Nothing to withdraw\");\n\n        pendingWithdrawals[msg.sender] = 0;\n        payable(msg.sender).transfer(amount);\n    }\n}\n\n\u002F\u002F Over this (push)\ncontract RiskyPayment {\n    function distributePayments(address[] memory recipients, uint256[] memory amounts) public {\n        for (uint i = 0; i \u003C recipients.length; i++) {\n            \u002F\u002F If any transfer fails, entire batch fails\n            payable(recipients[i]).transfer(amounts[i]);\n        }\n    }\n}\n```\n\n### Input Validation\n\n```solidity\ncontract SecureContract {\n    function transfer(address to, uint256 amount) public {\n        \u002F\u002F Validate inputs\n        require(to != address(0), \"Invalid recipient\");\n        require(to != address(this), \"Cannot send to contract\");\n        require(amount > 0, \"Amount must be positive\");\n        require(amount \u003C= balances[msg.sender], \"Insufficient balance\");\n\n        \u002F\u002F Proceed with transfer\n        balances[msg.sender] -= amount;\n        balances[to] += amount;\n    }\n}\n```\n\n### Emergency Stop (Circuit Breaker)\n\n```solidity\nimport \"@openzeppelin\u002Fcontracts\u002Fsecurity\u002FPausable.sol\";\n\ncontract EmergencyStop is Pausable, Ownable {\n    function criticalFunction() public whenNotPaused {\n        \u002F\u002F Function logic\n    }\n\n    function emergencyStop() public onlyOwner {\n        _pause();\n    }\n\n    function resume() public onlyOwner {\n        _unpause();\n    }\n}\n```\n\n## Gas Optimization\n\n### Use `uint256` Instead of Smaller Types\n\n```solidity\n\u002F\u002F More gas efficient\ncontract GasEfficient {\n    uint256 public value;  \u002F\u002F Optimal\n\n    function set(uint256 _value) public {\n        value = _value;\n    }\n}\n\n\u002F\u002F Less efficient\ncontract GasInefficient {\n    uint8 public value;  \u002F\u002F Still uses 256-bit slot\n\n    function set(uint8 _value) public {\n        value = _value;  \u002F\u002F Extra gas for type conversion\n    }\n}\n```\n\n### Pack Storage Variables\n\n```solidity\n\u002F\u002F Gas efficient (3 variables in 1 slot)\ncontract PackedStorage {\n    uint128 public a;  \u002F\u002F Slot 0\n    uint64 public b;   \u002F\u002F Slot 0\n    uint64 public c;   \u002F\u002F Slot 0\n    uint256 public d;  \u002F\u002F Slot 1\n}\n\n\u002F\u002F Gas inefficient (each variable in separate slot)\ncontract UnpackedStorage {\n    uint256 public a;  \u002F\u002F Slot 0\n    uint256 public b;  \u002F\u002F Slot 1\n    uint256 public c;  \u002F\u002F Slot 2\n    uint256 public d;  \u002F\u002F Slot 3\n}\n```\n\n### Use `calldata` Instead of `memory` for Function Arguments\n\n```solidity\ncontract GasOptimized {\n    \u002F\u002F More gas efficient\n    function processData(uint256[] calldata data) public pure returns (uint256) {\n        return data[0];\n    }\n\n    \u002F\u002F Less efficient\n    function processDataMemory(uint256[] memory data) public pure returns (uint256) {\n        return data[0];\n    }\n}\n```\n\n### Use Events for Data Storage (When Appropriate)\n\n```solidity\ncontract EventStorage {\n    \u002F\u002F Emitting events is cheaper than storage\n    event DataStored(address indexed user, uint256 indexed id, bytes data);\n\n    function storeData(uint256 id, bytes calldata data) public {\n        emit DataStored(msg.sender, id, data);\n        \u002F\u002F Don't store in contract storage unless needed\n    }\n}\n```\n\n## Common Vulnerabilities Checklist\n\n```solidity\n\u002F\u002F Security Checklist Contract\ncontract SecurityChecklist {\n    \u002F**\n     * [ ] Reentrancy protection (ReentrancyGuard or CEI pattern)\n     * [ ] Integer overflow\u002Funderflow (Solidity 0.8+ or SafeMath)\n     * [ ] Access control (Ownable, roles, modifiers)\n     * [ ] Input validation (require statements)\n     * [ ] Front-running mitigation (commit-reveal if applicable)\n     * [ ] Gas optimization (packed storage, calldata)\n     * [ ] Emergency stop mechanism (Pausable)\n     * [ ] Pull over push pattern for payments\n     * [ ] No delegatecall to untrusted contracts\n     * [ ] No tx.origin for authentication (use msg.sender)\n     * [ ] Proper event emission\n     * [ ] External calls at end of function\n     * [ ] Check return values of external calls\n     * [ ] No hardcoded addresses\n     * [ ] Upgrade mechanism (if proxy pattern)\n     *\u002F\n}\n```\n\n## Testing for Security\n\n```javascript\n\u002F\u002F 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    \u002F\u002F Deposit funds\n    await bank.deposit({ value: ethers.utils.parseEther(\"10\") });\n\n    \u002F\u002F 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    \u002F\u002F 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    \u002F\u002F 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    \u002F**\n     * @title Well Documented Contract\n     * @dev Example of proper documentation for audits\n     * @notice This contract handles user deposits and withdrawals\n     *\u002F\n\n    \u002F\u002F\u002F @notice Mapping of user balances\n    mapping(address => uint256) public balances;\n\n    \u002F**\n     * @dev Deposits ETH into the contract\n     * @notice Anyone can deposit funds\n     *\u002F\n    function deposit() public payable {\n        require(msg.value > 0, \"Must send ETH\");\n        balances[msg.sender] += msg.value;\n    }\n\n    \u002F**\n     * @dev Withdraws user's balance\n     * @notice Follows CEI pattern to prevent reentrancy\n     * @param amount Amount to withdraw in wei\n     *\u002F\n    function withdraw(uint256 amount) public {\n        \u002F\u002F CHECKS\n        require(amount \u003C= balances[msg.sender], \"Insufficient balance\");\n\n        \u002F\u002F EFFECTS\n        balances[msg.sender] -= amount;\n\n        \u002F\u002F INTERACTIONS\n        (bool success, ) = msg.sender.call{value: amount}(\"\");\n        require(success, \"Transfer failed\");\n    }\n}\n```\n",{"name":5,"description":7},"main","900bb95bbe72cdb94af6f5a620aa5081264b7b6d",".claude\u002Fmarketplaces\u002Fwshobson\u002Fplugins\u002Fblockchain-web3\u002Fskills\u002Fsolidity-security",0,"https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up#readme","https:\u002F\u002Fgithub.com\u002Fsteph-frtech","2026-05-16 00:03:30",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add steph-frtech\u002Fclaude-code-up --skill solidity-security",{"tool":37,"command":38},"bunx","bunx skills add steph-frtech\u002Fclaude-code-up --skill solidity-security",{"tool":40,"command":41},"pnpm","pnpm dlx skills add steph-frtech\u002Fclaude-code-up --skill solidity-security","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fmarketplaces\u002Fwshobson\u002Fplugins\u002Fblockchain-web3\u002Fskills\u002Fsolidity-security\u002FSKILL.md",true,[],[46,53,60,67,74,81],{"skillNo":47,"name":48,"nameZh":6,"description":49,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":50,"categories":51,"keywords":52,"publishedAt":18},"01M72Y1BY6X8TX3DS19Y04NEBQ","example","One-line summary of what this skill does","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002Fskills\u002Fexample\u002FSKILL.md",[],[],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":18},"01M72Y1A38EYR8S9P1MBYDAQTW","writing-plans","Use when you have a spec or requirements for a multi-step task, before touching code","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__writing-plans\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":18},"01M72Y174QSV1B5NV1E4KWHQBR","using-git-worktrees","Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__using-git-worktrees\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":18},"01M72Y14SQRHHMKG316HGB2CGK","test-driven-development","Use when implementing any feature or bugfix, before writing implementation code","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__test-driven-development\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":18},"01M72Y127BCPRH3BRKPJC3Q3G2","systematic-debugging","Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__systematic-debugging\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":18},"01M72Y1090GJA6B67KPD60WPHH","subagent-driven-development","Use when executing implementation plans with independent tasks in the current session","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__subagent-driven-development\u002FSKILL.md",[],[]]