28. Cyfrin Updraft: PasswordStore Audit
Overview
Section titled “Overview”This external Cyfrin Updraft chapter is your first real security audit. Using a tiny
contract called PasswordStore, it teaches the single most important lesson in onchain
security through one unforgettable bug. The teaching is on Updraft; these notes frame the
takeaway and connect it to Lab 4’s AI-assisted review.
The core lesson
Section titled “The core lesson”- Nothing onchain is private.
PasswordStoretries to store a secret password in a contract variable and restrict who can read it via agetter. The flaw: all contract storage is public. Even aprivatevariable is readable by anyone who inspects the chain’s raw storage. Marking somethingprivatein Solidity controls contract-to-contract visibility, not secrecy from the world. - Access control ≠ confidentiality. Restricting a function doesn’t hide the underlying data; the data still sits in public storage. This confusion is the root of the vulnerability.
What auditing looks like
Section titled “What auditing looks like”- Read the contract as an adversary — ask “what does this assume, and how could that assumption be false?” Here the false assumption is “storage is secret.”
- Name findings clearly — a good audit states the vulnerability, how to exploit it, its impact, and a fix, in plain language. Practicing that clarity is part of the exercise.
- Common beginner risks to carry forward — beyond this one, the module wants you watching
for: broken access control, reentrancy, unsafe
approve/allowance flows, price/oracle manipulation, and leaked private keys.
What to bring back
Section titled “What to bring back”You should be able to explain why you can never store a secret onchain, and you should have a feel for reading a contract critically. In Lab 4 you’ll turn this into practice by asking an AI agent to review your own contract — and by knowing enough to judge whether its findings are real.
Check yourself
Section titled “Check yourself”- Why can’t a
privateSolidity variable keep a value secret from the public? - What does the
privatekeyword actually restrict, if not world visibility? - When an AI security review flags an issue, how would you verify it’s real rather than trust it blindly?
Go deeper: common vulnerability patterns
Section titled “Go deeper: common vulnerability patterns”The PasswordStore bug — a private variable is still readable by anyone — is one entry in a
small catalog of classic Solidity vulnerabilities every auditor learns to recognize. Solidity
by Example (maintained by Cyfrin) has a minimal, exploitable contract for each, with the fix.
Read them as a checklist:
- Accessing private data — the exact PasswordStore lesson: all contract storage is publicly readable. Fix: never store secrets on-chain.
- Re-entrancy — an external call lets the callee call back in before your state updates. Fix: checks-effects-interactions (update state before the external call) and/or a reentrancy guard.
- Phishing with tx.origin — authorizing with
tx.originlets a middle contract impersonate the owner. Fix: authorize withmsg.sender. - Source of randomness —
block.timestampandblockhashare predictable and miner-influenced. Fix: don’t use them for randomness; use a dedicated oracle/VRF. - Delegatecall — runs foreign code in your storage; a mismatched storage layout is catastrophic. Fix: keep delegated code stateless and layouts identical.
- Denial of service — a push payment to an address that reverts can freeze a contract. Fix: let users pull (withdraw) funds instead of pushing.
- Front-running — the mempool is public, so an attacker can reorder around your transaction. Fix: commit-reveal schemes and slippage limits.
- Signature replay — a valid signature reused a second time. Fix: include a
nonceand the contract address in the signed message. - Arithmetic overflow / underflow — silent wraparound before Solidity 0.8. Fix: Solidity ≥0.8 reverts by default; be deliberate inside
uncheckedblocks.
Defensive building blocks — OpenZeppelin
ReentrancyGuard— thenonReentrantmodifier that blocks reentrant calls.Pausable— an emergency stop that pauses functionality while a fix is pending.- Access control — restrict privileged functions with
Ownableor role-basedAccessControl.
Sources: Solidity by Example — Hacks (Cyfrin) and the OpenZeppelin Contracts docs. These are learning examples; a real audit also uses tests, static analysis, and tools like the AI-assisted review in Lab 4.
Open Course Segment
Section titled “Open Course Segment”Cyfrin Updraft: Smart Contract Security
Assignment: complete the PasswordStore audit segment.
