23 security rules for Solidity and Anchor
These are the quick checks Chain Preflight runs everywhere: in the pre-deploy hook, the CLI, the GitHub Action and the in-browser checker. Each page explains why the pattern is dangerous, shows vulnerable and fixed code, and lists the matching detectors in Slither, Aderyn, Solhint and the Sealevel attacks catalogue. The analyzers add many more checks on top of these.
Solidity (EVM)
- high tx.origin used for authorization
Checking tx.origin lets any contract the owner interacts with act as the owner.
- high State written after an external call (reentrancy)
A function sends ETH or calls another contract before updating its own state, so the callee can re-enter and act on stale state.
- high Return value of a low-level call is ignored
call, send and delegatecall return false instead of reverting; ignoring it loses failures silently.
- high delegatecall to an address the caller controls
delegatecall runs foreign code with this contract's storage and balance; a caller-chosen target can take it over.
- high Initializer anyone can call
An initialize function without the initializer modifier or an access check can be called again, or first, by an attacker.
- high Privileged function without access control
A function that mints, withdraws, upgrades, pauses or changes ownership is public with no modifier or sender check.
- medium selfdestruct in contract code
selfdestruct is deprecated and, since EIP-6780, no longer deletes code except in the deploying transaction; if reachable by the wrong caller it still sends away all ETH.
- medium Randomness from block values
block.timestamp, blockhash and block.prevrandao are known or influenced by validators; they can't decide winners.
- medium ERC-20 transfer result ignored
Some tokens return false instead of reverting; use SafeERC20 or check the returned bool.
- medium ecrecover result not checked for address(0)
ecrecover returns the zero address for invalid signatures; comparing it to an unset signer accepts garbage.
- medium Price read from AMM reserves
getReserves() spot prices can be moved inside one transaction with a flash loan; use a TWAP or an oracle.
- medium Compiler older than 0.8 (no overflow checks)
Before Solidity 0.8, arithmetic wraps silently unless every operation uses SafeMath.
- low Floating pragma
pragma solidity ^0.8.0 lets a deployment use a compiler you didn't test with; pin the version you audited.
- info unchecked { } arithmetic
Overflow checks are off inside unchecked; make sure every operation there is provably bounded.
Anchor and Solana (Rust)
- high Unchecked account without a /// CHECK: note
AccountInfo and UncheckedAccount skip Anchor's owner and type checks; each needs an explicit reason and manual checks.
- high Authority account that isn't a Signer
An authority, admin or owner account that isn't Signer<'info> (or signer constrained) lets anyone pass someone else's key.
- high CPI to a program the caller chooses
invoke/invoke_signed with a program account that isn't Program<'info, T> or checked against a known id runs whatever program the caller passes.
- high Account data deserialized without an owner check
try_from_slice on raw account data trusts bytes that any program could have written.
- medium init_if_needed (reinitialization risk)
init_if_needed accepts accounts that already exist; without checks an attacker can reset or reuse state.
- medium Account closed by draining lamports by hand
Zeroing lamports without clearing data and owner lets the account be revived in the same transaction; use close = target.
- medium overflow-checks not enabled for release builds
Release builds wrap on overflow unless overflow-checks = true is set in [profile.release].
- low Unchecked arithmetic on amounts
+, - and * on balances or amounts can overflow; prefer checked_add/checked_sub and return an error.
Any project
- high Private key or keypair in the source
A hex private key or a Solana keypair array is committed in the code; anyone with the repo controls that account.
Machine-readable: rules.json.