New: Earn 20% as an AgentAlley affiliate. Share your link and earn on every sale you refer. Join now New: Earn 20% as an affiliate. Join now

Master smart contract security best practices to prevent

Solidity security

by wshobson · MIT license · ★ 39,857 on GitHub · updated Sep 21

Solidity security cover

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…

---
name: solidity-security
description: 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.
---

# 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

Overview

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

Manual install (npx, ZIP)
Claude Codenpx skills add wshobson/agents --skill solidity-security -g -a claude-code
Claude Code (manual)mkdir -p ~/.claude/skills && curl -sL https://codeload.github.com/wshobson/agents/tar.gz/4236bb91f839 \ | tar -xz -C ~/.claude/skills --strip-components=4 agents-4236bb91f839/plugins/blockchain-web3/skills/solidity-security
Windows (PowerShell)New-Item -ItemType Directory -Force "$HOME\.claude\skills" | Out-Null; Invoke-WebRequest "https://m.agentalley.io/zip/736212ea070343fcdf39/solidity-security.zip" -OutFile "$env:TEMP\solidity-security.zip"; Expand-Archive "$env:TEMP\solidity-security.zip" -DestinationPath "$HOME\.claude\skills" -Force
Claude.ai / desktopDownload the ZIP and upload it under Settings → Capabilities → Skills.
Codex, Cursor, other agentsPoint them at SKILL.md. The other files are plain text.

Connects with Agent Alley MCP · agentalley.io/mcp

Files included

  • SKILL.md3.5 KB
  • references/1 file · 9.4 KB
Read the files here
wshobson/4236bb92 files
SKILL.md
Show the full text113 lines

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");
    }
}
1---
2name: solidity-security
3description: 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.
4---
5 
6# Solidity Security
7 
8Master smart contract security best practices, vulnerability prevention, and secure Solidity development patterns.
9 
10## When to Use This Skill
11 
12- Writing secure smart contracts
13- Auditing existing contracts for vulnerabilities
14- Implementing secure DeFi protocols
15- Preventing reentrancy, overflow, and access control issues
16- Optimizing gas usage while maintaining security
17- Preparing contracts for professional audits
18- Understanding common attack vectors
19 
20## Detailed patterns and worked examples
21 
22Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.
23 
24## Testing for Security
25 
26```javascript
27// Hardhat test example
28const { expect } = require("chai");
29const { ethers } = require("hardhat");
30 
31describe("Security Tests", function () {
32 it("Should prevent reentrancy attack", async function () {
33 const [attacker] = await ethers.getSigners();
34 
35 const VictimBank = await ethers.getContractFactory("SecureBank");
36 const bank = await VictimBank.deploy();
37 
38 const Attacker = await ethers.getContractFactory("ReentrancyAttacker");
39 const attackerContract = await Attacker.deploy(bank.address);
40 
41 // Deposit funds
42 await bank.deposit({ value: ethers.utils.parseEther("10") });
43 
44 // Attempt reentrancy attack
45 await expect(
46 attackerContract.attack({ value: ethers.utils.parseEther("1") }),
47 ).to.be.revertedWith("ReentrancyGuard: reentrant call");
48 });
49 
50 it("Should prevent integer overflow", async function () {
51 const Token = await ethers.getContractFactory("SecureToken");
52 const token = await Token.deploy();
53 
54 // Attempt overflow
55 await expect(token.transfer(attacker.address, ethers.constants.MaxUint256))
56 .to.be.reverted;
57 });
58 
59 it("Should enforce access control", async function () {
60 const [owner, attacker] = await ethers.getSigners();
61 
62 const Contract = await ethers.getContractFactory("SecureContract");
63 const contract = await Contract.deploy();
64 
65 // Attempt unauthorized withdrawal
66 await expect(contract.connect(attacker).withdraw(100)).to.be.revertedWith(
67 "Ownable: caller is not the owner",
68 );
69 });
70});
71```
72 
73## Audit Preparation
74 
75```solidity
76contract WellDocumentedContract {
77 /**
78 * @title Well Documented Contract
79 * @dev Example of proper documentation for audits
80 * @notice This contract handles user deposits and withdrawals
81 */
82 
83 /// @notice Mapping of user balances
84 mapping(address => uint256) public balances;
85 
86 /**
87 * @dev Deposits ETH into the contract
88 * @notice Anyone can deposit funds
89 */
90 function deposit() public payable {
91 require(msg.value > 0, "Must send ETH");
92 balances[msg.sender] += msg.value;
93 }
94 
95 /**
96 * @dev Withdraws user's balance
97 * @notice Follows CEI pattern to prevent reentrancy
98 * @param amount Amount to withdraw in wei
99 */
100 function withdraw(uint256 amount) public {
101 // CHECKS
102 require(amount <= balances[msg.sender], "Insufficient balance");
103 
104 // EFFECTS
105 balances[msg.sender] -= amount;
106 
107 // INTERACTIONS
108 (bool success, ) = msg.sender.call{value: amount}("");
109 require(success, "Transfer failed");
110 }
111}
112```
113 
View all files on GitHub →

Details

Updated
Sep 21, 2026
License
MIT
Stars on the repo
★ 39,857
Checked
Source
wshobson/agents ↗
Creator
wshobson · 179 listings
View creator

Similar skills

See all →
MCPAgent-native x402 pay-per-call data & security APIs on BaseX402 data APIrezearcher/x402-data-api · by rezearcherAgent-native x402 pay-per-call data & security APIs on Base (crypto, DeFi, on-chain, Polymarket, MCP security scan)New listingSkillImplement DeFi protocols with production-ready templatesDefi protocol templateswshobson/agents · by wshobsonImplement DeFi protocols with production-ready templates for staking, AMMs, governance, and flash loans. Use when building decentralized finance applications or smart contract protocols.★ 39.9k GitHub starsSkillImplement NFT standards with proper metadata handlingwshobson/agents · by wshobsonImplement NFT standards (ERC-721, ERC-1155) with proper metadata handling, minting strategies, and marketplace integration. Use when creating NFT contracts, building NFT marketplaces, or implementing digital asset systems.★ 39.9k GitHub starsSkillTest smart contracts comprehensively using HardhatWeb3 Smart Contract Testingwshobson/agents · by wshobsonTest smart contracts comprehensively using Hardhat and Foundry with unit tests, integration tests, and mainnet forking. Use when testing Solidity contracts, setting up blockchain test suites, or validating DeFi protocols.★ 39.9k GitHub starsMCPBuilding smart contracts, DAppsBlockchain developerVoltAgent/awesome-claude-code-subagents · by VoltAgentUse this agent when building smart contracts, DApps, and blockchain protocols that require expertise in Solidity, gas optimization, security auditing, and Web3 integration.★ 25.2k GitHub starsSkillRequires technical rigor and verificationCode Review Receptionobra/superpowers · by obraUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation★ 290k GitHub stars

More from wshobson

SkillMaster C/.NET backend development patterns for buildingwshobson/agents · by wshobsonMaster C#/.NET backend development patterns for building robust APIs, MCP servers, and enterprise applications. Covers async/await, dependency injection, Entity Framework Core, Dapper, configuration, caching, and testing with xUnit. Use when developing .NET backends, reviewing C# code, or designing API architectures.★ 39.9k GitHub starsSkillImplement WCAG 2.2 compliant interfaces with mobileAccessibility compliancewshobson/agents · by wshobsonImplement WCAG 2.2 compliant interfaces with mobile accessibility, inclusive design patterns, and assistive technology support. Use when auditing accessibility, implementing ARIA patterns, building for screen readers, or ensuring inclusive user experiences.★ 39.9k GitHub starsSkillMaster Material Design 3 and Jetpack Compose patternsAndroid Mobile Designwshobson/agents · by wshobsonMaster Material Design 3 and Jetpack Compose patterns for building native Android apps. Use when designing Android interfaces, implementing Compose UI, or following Google's Material Design guidelines.★ 39.9k GitHub starsSkillMigrate from AngularJS to Angular using hybrid modeAngular migrationwshobson/agents · by wshobsonMigrate from AngularJS to Angular using hybrid mode, incremental component rewriting, and dependency injection updates. Use when upgrading AngularJS applications, planning framework migrations, or modernizing legacy Angular code.★ 39.9k GitHub starsSkillUnderstand anti-reversing, obfuscationAnti reversing techniqueswshobson/agents · by wshobsonUnderstand anti-reversing, obfuscation, and protection techniques encountered during software analysis. Use this skill when analyzing malware evasion techniques, when implementing anti-debugging protections for CTF challenges, when reverse engineering packed binaries, or when building security research tools that need to detect virtualized environments.★ 39.9k GitHub starsSkillBuild production Apache Airflow DAGs with best practicesApache Airflow DAG Patternswshobson/agents · by wshobsonBuild production Apache Airflow DAGs with best practices for operators, sensors, testing, and deployment. Use when creating data pipelines, orchestrating workflows, or scheduling batch jobs.★ 39.9k GitHub stars