Master smart contract security best practices to prevent
Solidity security

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)
npx skills add wshobson/agents --skill solidity-security -g -a claude-codemkdir -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-securityNew-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" -ForceConnects with Agent Alley MCP · agentalley.io/mcp
Files included
SKILL.md3.5 KBreferences/1 file · 9.4 KB
Read the files here
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 | |
| 2 | name solidity-security |
| 3 | 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. |
| 4 | |
| 5 | |
| 6 | # Solidity Security |
| 7 | |
| 8 | Master 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 | |
| 22 | Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient. |
| 23 | |
| 24 | ## Testing for Security |
| 25 | |
| 26 | |
| 27 | // Hardhat test example |
| 28 | const { expect } = require("chai"); |
| 29 | const { ethers } = require("hardhat"); |
| 30 | |
| 31 | describe("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 | |
| 76 | contract 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 |
Details
- Updated
- Sep 21, 2026
- License
- MIT
- Stars on the repo
- ★ 39,857
- Checked
- Source
- wshobson/agents ↗
- Creator
- wshobson · 179 listings
Similar skills
See all →
MCPAgent-native x402 pay-per-call data & security APIs on BaseX402 data API
SkillImplement DeFi protocols with production-ready templatesDefi protocol templates
SkillImplement NFT standards with proper metadata handling
SkillTest smart contracts comprehensively using HardhatWeb3 Smart Contract Testing
MCPBuilding smart contracts, DAppsBlockchain developer
SkillRequires technical rigor and verificationCode Review ReceptionMore from wshobson
SkillMaster C/.NET backend development patterns for building
SkillImplement WCAG 2.2 compliant interfaces with mobileAccessibility compliance
SkillMaster Material Design 3 and Jetpack Compose patternsAndroid Mobile Design
SkillMigrate from AngularJS to Angular using hybrid modeAngular migration
SkillUnderstand anti-reversing, obfuscationAnti reversing techniques
SkillBuild production Apache Airflow DAGs with best practicesApache Airflow DAG Patterns