Skip to content

28. Cyfrin Updraft: PasswordStore Audit

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.

  • Nothing onchain is private. PasswordStore tries to store a secret password in a contract variable and restrict who can read it via a getter. The flaw: all contract storage is public. Even a private variable is readable by anyone who inspects the chain’s raw storage. Marking something private in 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.
  • 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.

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.

  • Why can’t a private Solidity variable keep a value secret from the public?
  • What does the private keyword 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?

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.origin lets a middle contract impersonate the owner. Fix: authorize with msg.sender.
  • Source of randomnessblock.timestamp and blockhash are 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 nonce and 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 unchecked blocks.

Defensive building blocks — OpenZeppelin

  • ReentrancyGuard — the nonReentrant modifier that blocks reentrant calls.
  • Pausable — an emergency stop that pauses functionality while a fix is pending.
  • Access control — restrict privileged functions with Ownable or role-based AccessControl.

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.

Cyfrin Updraft: Smart Contract Security

Assignment: complete the PasswordStore audit segment.

Open Security course on Updraft

Module 4: L2, Indexing, Security & Web3 Identity.