[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7BW8AMA74RHTXX9KP5KR4BC":3,"skill-same:01M7BW8AMA74RHTXX9KP5KR4BC":47},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":6,"ownerDescription":31,"updatedAt":32,"install":33,"resources":46},"01M7BW8AMA74RHTXX9KP5KR4BC","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.","YYC-Cube\u002FYYC3-Knowledge-Base","YYC-Cube","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F235006543?v=4","01M79J2PH4SWD2X0825X6PN748","yyc3","01M79J2PHVK3F6ZBYT8K2SCZCW",1,"MIT","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-Plugin-插件协议\u002FYYC3-Plugin-插件协议-plugins-claude\u002Fblockchain-web3\u002Fskills\u002Fsolidity-security\u002FSKILL.md",[],[],"2026-11-15 14:19:17",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","87afe6ce96220accf50a345dea46784c8c9f210e","YYC3-Plugin-插件协议\u002FYYC3-Plugin-插件协议-plugins-claude\u002Fblockchain-web3\u002Fskills\u002Fsolidity-security",0,"https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base","https:\u002F\u002Fkb.yyc3.top\u002F","https:\u002F\u002Fgithub.com\u002FYYC-Cube","万象归元于云枢 | 深栈智启新纪元","2026-11-10 10:37:32",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill solidity-security",{"tool":39,"command":40},"bunx","bunx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill solidity-security",{"tool":42,"command":43},"pnpm","pnpm dlx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill solidity-security","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-Plugin-插件协议\u002FYYC3-Plugin-插件协议-plugins-claude\u002Fblockchain-web3\u002Fskills\u002Fsolidity-security\u002FSKILL.md",true,[],[48,55,62,69,76,83],{"skillNo":49,"name":50,"nameZh":6,"description":51,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":52,"categories":53,"keywords":54,"publishedAt":19},"01M7CTDWHERCXPQCP0K03A86AS","vercel-sandbox","Run agent-browser + Chrome inside Vercel Sandbox microVMs for browser automation from any Vercel-deployed app. Use when the user needs browser automation in a Vercel app (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.), wants to run headless Chrome without binary size limits, needs persistent browser sessions across commands, or wants ephemeral isolated browser environments. Triggers include \"Vercel Sandbox browser\", \"microVM Chrome\", \"agent-browser in sandbox\", \"browser automation on Vercel\", or any task requiring Chrome in a Vercel Sandbox.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fvercel-sandbox\u002FSKILL.md",[],[],{"skillNo":56,"name":57,"nameZh":6,"description":58,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":19},"01M7CTD8D2BNJY54S65M47HEJA","slack","Interact with Slack workspaces using browser automation. Use when the user needs to check unread channels, navigate Slack, send messages, extract data, find information, search conversations, or automate any Slack task. Triggers include \"check my Slack\", \"what channels have unreads\", \"send a message to\", \"search Slack for\", \"extract from Slack\", \"find who said\", or any task requiring programmatic Slack interaction.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fslack\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M7CTCSSB8ZP3Q58C3YZDZK1W","electron","Automate Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify, etc.) using agent-browser via Chrome DevTools Protocol. Use when the user needs to interact with an Electron app, automate a desktop app, connect to a running app, control a native app, or test an Electron application. Triggers include \"automate Slack app\", \"control VS Code\", \"interact with Discord app\", \"test this Electron app\", \"connect to desktop app\", or any task requiring automation of a native Electron application.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Felectron\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M7CTCBJY76688V4DCZGWFHGQ","dogfood","Systematically explore and test a web application to find bugs, UX issues, and other problems. Use when asked to \"dogfood\", \"QA\", \"exploratory test\", \"find issues\", \"bug hunt\", \"test this app\u002Fsite\u002Fplatform\", or review the quality of a web application. Produces a structured report with full reproduction evidence -- step-by-step screenshots, repro videos, and detailed repro steps for every issue -- so findings can be handed directly to the responsible teams.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fdogfood\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M7CTC4H0FFGVEAQR9PA4GA1A","agent-browser","Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to \"open a website\", \"fill out a form\", \"click a button\", \"take a screenshot\", \"scrape data from a page\", \"test this web app\", \"login to a site\", \"automate browser actions\", or any task requiring programmatic web interaction.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fagent-browser\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M7CTBKVFYBG78FDSABSDJTTQ","shadcn","Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI, including chat interfaces. Provides project context, component docs, and usage examples. Applies when working with shadcn\u002Fui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for \"shadcn init\", \"create an app with --preset\", \"switch to --preset\", and for building a design system or applying a DESIGN.md or brand spec to shadcn\u002Fui.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-UI-界面组件\u002FYYC3-UI-界面组件-ui\u002Fskills\u002Fshadcn\u002FSKILL.md",[],[]]