security-building-secure-contracts
Building Secure Smart Contracts
When to Use
- Writing new smart contracts and need security-first patterns
- Reviewing contract code for common vulnerability classes
- Hardening existing contracts before audit or deployment
- Implementing access control, upgrade patterns, or token standards securely
- Evaluating contract architecture for systemic risks
When NOT to Use
- General web application security (use other security skills)
- Off-chain backend code review
- Non-blockchain cryptographic protocol design
Key Vulnerability Classes
Solidity / EVM
| Vulnerability | Description | Mitigation |
|---|---|---|
| Reentrancy | External calls allow recursive entry | Checks-Effects-Interactions pattern; ReentrancyGuard |
| Integer overflow/underflow | Arithmetic wraps silently (pre-0.8) | Use Solidity >=0.8 or SafeMath |
| Access control | Missing or incorrect permission checks | OpenZeppelin Ownable/AccessControl; multi-sig for admin |
| Flash loan manipulation | Price or governance manipulation via atomic loans | Time-weighted oracles; commit-reveal schemes |
| Front-running | Mempool observation enables MEV extraction | Commit-reveal; private mempools; batch auctions |
| Delegatecall injection | Arbitrary code execution via delegatecall | Restrict delegatecall targets; avoid user-controlled addresses |
| Storage collision | Proxy upgrade storage layout conflicts | Use EIP-1967 storage slots; OpenZeppelin upgradeable contracts |
Solana / Rust
| Vulnerability | Description | Mitigation |
|---|---|---|
| Missing signer check | Instructions accept unsigned accounts | Verify account.is_signer |
| Missing owner check | Accounts owned by wrong program | Verify account.owner == program_id |
| Account confusion | Wrong account type passed | Use discriminators; Anchor account validation |
| Arithmetic overflow | Unchecked math in native Rust | Use checked_add, checked_mul; saturating math |
Secure Development Checklist
- Use established, audited libraries (OpenZeppelin, Anchor)
- Follow Checks-Effects-Interactions pattern
- Implement comprehensive access control
- Use time-weighted average prices for oracles
- Add emergency pause mechanisms
- Write invariant tests and fuzz tests
- Get independent audit before mainnet deployment
- Use formal verification where practical
Testing Approach
- Unit tests for all state transitions
- Invariant/property-based tests for protocol invariants
- Fork tests against mainnet state
- Fuzz testing with Foundry or Echidna
- Symbolic execution with Halmos or Manticore
Resources
- Trail of Bits: Building Secure Contracts — https://secure-contracts.com/
- OpenZeppelin Contracts — https://docs.openzeppelin.com/contracts/
- Solidity Security Pitfalls — https://github.com/sigp/solidity-security-blog
- Anchor Book — https://book.anchor-lang.com/
More from elizaos/eliza
nano-pdf
Edits PDF files using natural-language instructions via the nano-pdf CLI. Supports modifying text, changing titles, fixing typos, and updating content on specific pages. Use when the user wants to edit a PDF, modify PDF content, update PDF text, fix a typo in a PDF, change a PDF title, or rewrite part of a PDF page.
30wacli
Send WhatsApp messages to other people or search/sync WhatsApp history via the wacli CLI (not for normal user chats). Use when the user asks to send a WhatsApp message, text someone on WhatsApp, search WhatsApp chat history, sync WhatsApp conversations, backfill message history, or forward a file via WhatsApp to a third party.
27session-logs
Search and analyze session logs (older/parent conversations) stored as JSONL files using jq and rg. Use when the user asks about prior chats, previous conversations, conversation history, what was said before, session costs, token usage, or tool usage breakdown across past sessions.
24openai-image-gen
Batch-generate images via the OpenAI Images API using DALL-E 2, DALL-E 3, or GPT image models. Produces random-but-structured prompts, renders them, and outputs a browsable `index.html` gallery. Use when the user asks to generate AI images, create pictures with DALL-E, batch-produce image assets, render AI art, or build an image gallery from text prompts.
21skill-creator
Creates, updates, and packages AgentSkills with proper SKILL.md frontmatter, bundled scripts, references, and assets. Provides guidance on skill naming, progressive disclosure, and context-efficient design. Use when building a new skill from scratch, restructuring an existing skill, writing or improving SKILL.md files, organizing skill resources into scripts/references/assets folders, packaging skills for distribution, or iterating on skill quality after testing.
21bird
X/Twitter CLI for reading, searching, posting, and engagement via cookies. Provides direct access to tweets, timelines, social media feeds, bookmarks, lists, and trending topics through GraphQL and cookie-based authentication. Use when the user wants to tweet, read a tweet, search Twitter, check their timeline, browse social media, view replies, follow or unfollow accounts, manage bookmarks, or interact with X/Twitter from the command line.
21