Sub topic 7
Reading a Token Contract for Red Flags
This chapter assumes you know what an ERC-20 token is and how liquidity pools work (covered earlier). You do not need to write Solidity. You need to read short functions and ask one question of each: who can call this, and what does it let them do to me?
What a contract review can and cannot tell you
A token contract is the program that stores balances and enforces transfers. Whatever the contract allows, its controlling address can do at any time. A contract review looks for privileges that let one party take value from other holders. These are the mechanics behind the rug types from the previous chapter.
A review has limits:
- It tells you what is possible, not what will happen. An owner who can mint may never do so.
- It covers only the token contract. Liquidity ownership and holder distribution need separate checks, which later chapters cover.
- It cannot see logic hidden behind a proxy or an external contract unless you follow the references.
Start with verification
Open the token's page on a block explorer such as Etherscan and find the Contract tab. A green check means the deployer published the source code and the explorer confirmed it compiles to the deployed bytecode. An unverified contract shows only raw bytecode. That is a serious red flag on its own, because you cannot audit what you cannot read. Some automated tools can decompile bytecode, but they give approximate results.
Also check the compiler version and whether the code is a copy of a well-known template (for example OpenZeppelin's ERC-20). Standard templates are well tested. Custom additions around them deserve the most attention.
The owner-controlled functions to look for
Most red flags are functions guarded by a modifier such as onlyOwner, or by a check like require(msg.sender == owner). Search the source for these words and read each match.
| Pattern | What it enables | What to look for |
|---|---|---|
| Blacklist or block list | Stops chosen addresses from selling | A mapping checked inside `transfer` and a setter only the owner can call |
| Unrestricted `mint` | Creates new tokens and dilutes holders, who can then be sold against | `mint` with no cap, or callable by owner |
| `pause` or trading toggle | Freezes all transfers | `whenNotPaused` on transfers, plus an owner-only `pause` |
| Adjustable fee or tax | Raises the sell tax to near 100% after buyers enter | Setters like `setFee` or `setTaxes` with no upper bound |
| Transaction or wallet limits | Blocks sales above a size, or selectively | `maxTxAmount` or `maxWallet` that the owner can change |
| Upgradeable proxy | Replaces the whole logic with new code | A proxy pattern where the admin can change the implementation address |
| Arbitrary balance changes | Removes tokens from your wallet | Any function that writes `balanceOf[someone]` outside normal transfers |
A worked example: the blacklist
The contract below is simplified, and it is not a full ERC-20. It shows the most common transfer restriction.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
// Simplified, not a full ERC-20. It shows a red-flag pattern to recognize:
// one address can stop any holder from transferring.
contract RedFlagToken {
address public owner;
mapping(address => bool) public blocked;
mapping(address => uint256) public balanceOf;
constructor() {
owner = msg.sender;
}
function setBlocked(address account, bool value) external {
require(msg.sender == owner, "not owner");
blocked[account] = value;
}
function transfer(address to, uint256 amount) external returns (bool) {
require(!blocked[msg.sender], "blocked");
balanceOf[msg.sender] -= amount;
balanceOf[to] += amount;
return true;
}
}Read it in three steps.
- Find the restriction.
transferreverts whenblocked[msg.sender]is true. - Find who controls it.
setBlockedcan be called only byowner, andowneris whoever deployed the contract. - Work out the consequence. The owner can let everyone buy, then block every other holder and sell alone. Buyers see a price chart that looks healthy, and their own sells fail. This is the honeypot pattern.
Notice that nothing here is hidden. The risk is visible in about ten lines, which is why reading is worth the effort.
Hidden and indirect versions
Scam authors know people search for blacklist, so the same power often appears under other names.
- A mapping called
bots,isBot,_isExcluded, orantiWhalethat is checked during transfers. - A fee that depends on the sender, such as a higher tax for any address not on an allowlist.
- A trading switch like
tradingOpenthat the owner can flip back to false. - A transfer function that calls another contract (a "helper" or "manager") whose code you must also read.
- Mint-like behavior in functions with innocent names, such as
rebase,reward, orairdrop, that increase balances.
For this reason, read the transfer, transferFrom, and internal _transfer functions line by line first. Every restriction on selling has to pass through them.
Ownership: renounced, transferred, or still held
Check the owner() value on the Read Contract tab. Three cases are common.
- Owner is the zero address (
0x000...0). Ownership was renounced andonlyOwnerfunctions can no longer be called. This removes the privileges, but only if no other role exists. Some contracts have a second admin variable, a separateoperator, or a proxy admin that renouncing the owner role does not affect. - Owner is an externally owned account. One private key controls everything. Treat every
onlyOwnerfunction as live. - Owner is a multisig or a timelock. A multisig needs several signers. A timelock delays changes so holders can react. Both reduce risk but do not remove it. Look up who the signers are and what the delay is.
Upgradeable proxies
A proxy contract forwards calls to an implementation contract. The admin can point the proxy at new code, so the code you read today may not be the code that runs tomorrow. On Etherscan, a proxy usually shows a "Read as Proxy" option. Find the admin, and check whether it is a timelock or multisig. An upgradeable token held by a single key is equivalent to having every red flag in the table available at once.
A review workflow
A quick keyword scan
A script cannot replace reading, but it gives a first pass that tells you where to look. This Python example counts nothing and judges nothing. It lists which risky categories appear in pasted source code.
import re
PATTERNS = {
"blacklist": r"\b(blacklist\w*|blocked|isBot\w*)\b",
"mint": r"\bmint\w*\(",
"pause": r"\b(pause|paused|whenNotPaused)\b",
"fee_setter": r"function\s+set\w*(fee|tax)\w*\(",
"owner_only": r"\bonlyOwner\b",
}
def scan(source):
"""Return the sorted names of red-flag categories found in the source."""
return sorted(
name for name, pattern in PATTERNS.items()
if re.search(pattern, source, re.IGNORECASE)
)
sample = """
mapping(address => bool) blocked;
function mint(address to, uint256 amount) external onlyOwner { }
function setFee(uint256 f) external onlyOwner { }
"""
print(scan(sample))The output is ['blacklist', 'fee_setter', 'mint', 'owner_only'].
Common errors when reviewing
- Treating every owner power as a scam. Legitimate projects pause contracts during an exploit or cap fees. The question is whether the power is limited (a fee capped at 5%, a pause behind a timelock) and who holds the key.
- Trusting the name of a function. Read the body. A function called
claimRewardscan still change balances. - Relying on a "safe" label from a scanner. Automated tools miss custom logic. Use them as a hint and confirm in the code.
- Skipping the sell test. A honeypot can look clean in the code you skimmed. Many explorers and simulation tools can show whether a small sell succeeds. A tiny real test sale is the last check, and you should only try it with an amount you can afford to lose.
- Ignoring everything outside the token. Safe code does not help if the creator controls all the liquidity or most of the supply. Continue to the liquidity and holder checks in the next chapters.
Exercise
A token's verified source has function setTaxes(uint256 buy, uint256 sell) external onlyOwner with no upper limit check, and owner() returns a normal wallet address. Describe the risk and one change that would reduce it.
Show answer
The owner can raise the sell tax to nearly 100% after people buy, so a sale returns almost nothing. This works like a soft honeypot even though transfers still succeed. The risk drops if the setter enforces a hard cap in code (for example require(sell <= 5)), if ownership is renounced after fixing sensible values, or if the owner is a timelock so holders can exit before a change takes effect.
Exercise
A project announces "ownership renounced" and the owner() function returns the zero address. Name two things you still need to check before trusting the contract.
Show answer
First, whether another privileged role exists, such as an operator, a fee-exempt manager, or a proxy admin that can still upgrade or change the code. Second, whether values set before renouncing are harmful, such as an unbounded or very high tax, a blacklist that already contains addresses, or trading limits that cannot be removed. Liquidity ownership and holder concentration also need separate checks.