I asked GPT-5 to draft tokenomics for an ERC-20: a billion max supply, a small burn fee on transfers, pausable transfers, and owner-only minting. It produced a clean-looking contract in seconds.
I didn’t ship it.
I tried to break it with Foundry tests first.
What GPT-5 Proposed?
- Max supply: 1,000,000,000 tokens
- Fee: 2% burned on each transfer
- Minting: owner-only, capped by max supply
- Pausable: owner can pause/unpause transfers
On paper, perfect. In tests, not so much.
Red Flags My Tests Found
Pause wasn’t enforced on transfers: The contract imported pausing logic but never actually blocked transfers when paused.
Burn fee also hit initial distributions: Owner distributing tokens to the community lost 2% every time. Usually you want fees only on user-to-user transfers.
Fee governance was under-specified: The burn fee could be changed by the owner with no bounds, no delay, and no event—ripe for mistakes or abuse.
Edge cases unaccounted
- Transfers of tiny amounts could round weirdly.
- Mint + immediate transfer flows behaved differently than expected.
- No explicit tests around zero addresses and paused state interactions.
The Foundry Tests That Broke It
- Cap enforcement: Mint exactly to the cap → pass. Mint 1 wei over → revert.
- Pause behavior: Pause → any transfer should revert; unpause → transfers resume. - Fee scope: Owner mint to user should be fee-free; user↔user transfers should burn the fee.
- Fee bounds: Disallow ridiculous values (e.g., >10%) and ensure changes emit events.
- Dust/rounding: Micro-transfers shouldn’t underflow/overflow or burn more than the amount.
- Role sanity: Only owner can mint; ownership transfer doesn’t silently loosen controls.
Running these revealed exactly where the AI’s “looks good” code… wasn’t.
The Fixes I Made
- Actually enforced pause on transfers.
- Excluded fee on mint/distribution paths (fee only on user↔user transfers).
- Bounded fee range with a sensible max and required an event on change.
- Added tests for tiny amounts and zero-address safety.
- Documented assumptions (e.g., “no fee on mint,” “fee burns to 0x00”).
What I Learned (so you don’t have to)
- AI is an incredible starter, not a reviewer. It drafts patterns fast; it doesn’t defend them under weird conditions.
- Tests are the spec. If it’s not in a test, it’s an assumption—and assumptions leak value.
- Write tests like an attacker. Pause, fee changes, dust, ownership edges, and weird order flows are where bugs hide.
- Governance matters. Even a tiny fee toggle needs bounds, events, and—ideally time delays.
Top comments (0)