All skills
wshobson avatar

/solidity-security

@be57c0b
by Seth Hobsonwshobson/agents40k stars
4,281

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.

Use this Skill: https://skilld.dev/gh/wshobson/agents/solidity-security

This session only. Nothing lands on disk.

SKILL.md

≈66 tokens always: the name and description. ≈818 when used: this file. ≈2.4k more on demand in 1 file.

Solidity Security

Master smart contract security best practices, vulnerability prevention, and secure Solidity development patterns.

When to Use This Skill

  • Writing secure smart contracts
  • Auditing existing contracts for vulnerabilities
  • Implementing secure DeFi protocols
  • Preventing reentrancy, overflow, and access control issues
  • Optimizing gas usage while maintaining security
  • Preparing contracts for professional audits
  • Understanding common attack vectors

Detailed patterns and worked examples

Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.

Testing for Security

// Hardhat test example
const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("Security Tests", function () {
  it("Should prevent reentrancy attack", async function () {
    const [attacker] = await ethers.getSigners();

    const VictimBank = await ethers.getContractFactory("SecureBank");
    const bank = await VictimBank.deploy();

    const Attacker = await ethers.getContractFactory("ReentrancyAttacker");
    const attackerContract = await Attacker.deploy(bank.address);

    // Deposit funds
    await bank.deposit({ value: ethers.utils.parseEther("10") });

    // Attempt reentrancy attack
    await expect(
      attackerContract.attack({ value: ethers.utils.parseEther("1") }),
    ).to.be.revertedWith("ReentrancyGuard: reentrant call");
  });

  it("Should prevent integer overflow", async function () {
    const Token = await ethers.getContractFactory("SecureToken");
    const token = await Token.deploy();

    // Attempt overflow
    await expect(token.transfer(attacker.address, ethers.constants.MaxUint256))
      .to.be.reverted;
  });

  it("Should enforce access control", async function () {
    const [owner, attacker] = await ethers.getSigners();

    const Contract = await ethers.getContractFactory("SecureContract");
    const contract = await Contract.deploy();

    // Attempt unauthorized withdrawal
    await expect(contract.connect(attacker).withdraw(100)).to.be.revertedWith(
      "Ownable: caller is not the owner",
    );
  });
});

Audit Preparation

contract WellDocumentedContract {
    /**
     * @title Well Documented Contract
     * @dev Example of proper documentation for audits
     * @notice This contract handles user deposits and withdrawals
     */

    /// @notice Mapping of user balances
    mapping(address => uint256) public balances;

    /**
     * @dev Deposits ETH into the contract
     * @notice Anyone can deposit funds
     */
    function deposit() public payable {
        require(msg.value > 0, "Must send ETH");
        balances[msg.sender] += msg.value;
    }

    /**
     * @dev Withdraws user's balance
     * @notice Follows CEI pattern to prevent reentrancy
     * @param amount Amount to withdraw in wei
     */
    function withdraw(uint256 amount) public {
        // CHECKS
        require(amount <= balances[msg.sender], "Insufficient balance");

        // EFFECTS
        balances[msg.sender] -= amount;

        // INTERACTIONS
        (bool success, ) = msg.sender.call{value: amount}("");
        require(success, "Transfer failed");
    }
}

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill provides educational documentation and code templates focused on smart contract security best practices for Solidity development. No security risks or malicious behaviors were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    1 file scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at be57c0b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 days ago.

Activeupdated 4 months ago
  • Security
  • solidity
  • smart-contracts
  • reentrancy
  • access-control
  • hardhat
  • auditing
  • vulnerabilities

README badge

README badge for wshobson/agents/solidity-security

Teaches smart contract security patterns including reentrancy prevention, integer overflow protection, and access control for Solidity development. Covers vulnerability auditing, the checks-effects-interactions pattern, and Hardhat test examples for securing DeFi protocols and contracts before professional audit.

Generated from the current SKILL.md.

Does this skill cover specific vulnerabilities like reentrancy and integer overflow?
Yes. The skill includes patterns and test examples for reentrancy attacks, integer overflow prevention, and access control vulnerabilities using Hardhat tests and Solidity examples.
What testing framework does this skill assume?
The skill uses Hardhat with ethers.js and Chai for testing smart contract security patterns.
Does this skill help prepare contracts for professional audits?
Yes. It includes audit preparation guidance, documentation standards (NatSpec comments), and the Checks-Effects-Interactions (CEI) pattern for secure contract design.
What blockchain or EVM version does this target?
The skill does not specify a particular blockchain or EVM version. It covers general Solidity security best practices applicable across EVM-compatible chains.

Generated from the current SKILL.md. These answers refresh after source changes.