
Solidity Security
FreeEnhance your smart contract security practices.
Free · Opens the source repo
What Solidity Security does
The Solidity Security skill is designed to help developers master best practices in smart contract security. It provides comprehensive guidance on preventing common vulnerabilities and implementing secure patterns in Solidity development. This skill is particularly useful for those who are writing new smart contracts, auditing existing ones, or looking to implement security measures in blockchain applications. By understanding and applying these principles, developers can significantly reduce the risk of security breaches in their contracts.
This skill covers a range of topics essential for secure smart contract development, including reentrancy, integer overflow, and access control issues. It also emphasizes the importance of optimizing gas usage without compromising security, which is crucial for DeFi protocols. The skill serves as a resource for preparing contracts for professional audits, ensuring that developers are well-equipped to handle security assessments. With detailed patterns and worked examples provided in the accompanying documentation, users can reference specific scenarios and learn from practical implementations.
Included in the skill are testing examples using Hardhat, which demonstrate how to effectively test smart contracts against common attack vectors. These examples help reinforce the principles of security by allowing developers to see firsthand how to prevent vulnerabilities through code. Additionally, the skill emphasizes the significance of proper documentation, which is vital for both audits and ongoing maintenance of smart contracts. Overall, this skill is an essential tool for any developer looking to enhance their knowledge and practices in Solidity security.
When to use it
Use this skill when developing or auditing smart contracts to ensure they adhere to security best practices.
When not to use it
This skill may not be necessary for developers working on non-blockchain applications or those not focused on smart contract security.
What you can build with it
Developing a New Smart Contract
When creating a new smart contract, use this skill to integrate security best practices from the start.
Auditing Existing Contracts
Utilize the skill to identify and rectify vulnerabilities in existing smart contracts before deployment.
Preparing for Professional Audits
Leverage the skill's guidelines to ensure your contracts are well-documented and secure for third-party audits.
How to install Solidity Security
View source1. Install with the skills CLI
npx skills add wshobson/agents/solidity-security --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by wshobsonSolidity 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");
}
}
Frequently asked questions about Solidity Security
Similar skills
GitHub Actions Hardening
Enhance the security of your GitHub Actions workflows.
Sensitive Logging Audit
Audit and fix sensitive data exposure in Python logging.
Android App Static Analysis
Automate security assessments of Android apps with MobSF.
Integrating DAST with OWASP ZAP
Seamlessly integrate dynamic security testing into CI/CD pipelines.
Implementing Runtime Security with Tetragon
Enhance Kubernetes security with eBPF-based observability.
Implementing Mobile Application Management
Secure enterprise data on mobile devices with app-level controls.
