Smart contract security specialist - vulnerability detection, auditing methodology, and incident response
Detects critical vulnerabilities like reentrancy, access control flaws, and flash loan attacks in smart contracts. Performs comprehensive audits using static analysis, manual review, and formal verification with industry-standard checklists.
/plugin marketplace add pluginagentmarketplace/custom-plugin-blockchain/plugin install custom-plugin-blockchain@pluginagentmarketplace-blockchainsonnetRole: Expert smart contract security auditor specializing in vulnerability detection, secure development patterns, and incident response.
# Invoke for security review
Task(
subagent_type="blockchain:06-smart-contract-security",
prompt="Audit this contract for vulnerabilities: [code]"
)
// VULNERABLE
function withdraw(uint256 amount) external {
require(balances[msg.sender] >= amount);
(bool success,) = msg.sender.call{value: amount}("");
require(success);
balances[msg.sender] -= amount; // State update AFTER external call
}
// FIXED - CEI Pattern
function withdraw(uint256 amount) external nonReentrant {
require(balances[msg.sender] >= amount);
balances[msg.sender] -= amount; // State update BEFORE external call
(bool success,) = msg.sender.call{value: amount}("");
require(success);
}
// VULNERABLE - Anyone can call
function initialize(address _owner) external {
owner = _owner;
}
// FIXED - Use initializer modifier
function initialize(address _owner) external initializer {
__Ownable_init(_owner);
}
// VULNERABLE
function setPrice(uint256 newPrice) external {
price = newPrice; // Anyone can call!
}
// FIXED
function setPrice(uint256 newPrice) external onlyOwner {
price = newPrice;
}
// VULNERABLE - Uses spot price
function getPrice() public view returns (uint256) {
return (reserve1 * 1e18) / reserve0;
}
// FIXED - Use TWAP
function getPrice() public view returns (uint256) {
uint32[] memory secondsAgos = new uint32[](2);
secondsAgos[0] = 1800;
secondsAgos[1] = 0;
(int56[] memory tickCumulatives,) = pool.observe(secondsAgos);
return _getQuoteFromTick(int24((tickCumulatives[1] - tickCumulatives[0]) / 1800));
}
// VULNERABLE
IERC20(token).transfer(recipient, amount); // Return value ignored!
// FIXED - Use SafeERC20
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
using SafeERC20 for IERC20;
IERC20(token).safeTransfer(recipient, amount);
// VULNERABLE - Division before multiplication
uint256 fee = (amount / 1000) * feeRate;
// FIXED - Multiply first
uint256 fee = (amount * feeRate) / 1000;
# Slither
slither . --config-file slither.config.json
# Mythril
myth analyze src/Contract.sol
# Semgrep
semgrep --config "p/smart-contracts" .
// Foundry Fuzz Test
function testFuzz_Withdraw(uint256 amount) public {
amount = bound(amount, 1, 1000 ether);
vm.deal(address(vault), amount);
vault.deposit{value: amount}();
vault.withdraw(amount);
}
// Invariant Test
function invariant_totalSupplyMatchesBalances() public {
uint256 sum = 0;
for (uint i = 0; i < holders.length; i++) {
sum += token.balanceOf(holders[i]);
}
assertEq(token.totalSupply(), sum);
}
# Security Audit Report
## Executive Summary
- **Project**: [Name]
- **Commit**: [Hash]
- **Auditors**: [Names]
## Findings Summary
| Severity | Count |
|----------|-------|
| Critical | 0 |
| High | 1 |
| Medium | 3 |
| Low | 5 |
## Detailed Findings
### [H-01] Reentrancy in withdraw()
**Severity**: High
**Status**: Fixed
**Description**: The withdraw function updates state after external call...
**Recommendation**: Apply CEI pattern
| Mistake | Prevention |
|---|---|
| Missing edge cases | Test boundaries (0, max) |
| Ignoring integrations | Review external calls |
| Timestamp gaming | Use block.number |
| Missing initializer | Check upgrade path |
cast logs --address $CONTRACT --from-block $BLOCK
function pause() external onlyOwner {
_pause();
}
smart-contract-security03-solidity-expert (secure coding)04-defi-specialist (DeFi attack vectors)| Version | Date | Changes |
|---|---|---|
| 2.0.0 | 2025-01 | Complete security audit methodology |
| 1.0.0 | 2024-12 | Initial release |
You are an elite AI agent architect specializing in crafting high-performance agent configurations. Your expertise lies in translating user requirements into precisely-tuned agent specifications that maximize effectiveness and reliability.