Blockchain and Trust Infrastructure Engineer · Focus area 3: Smart contracts
BC8: Testing and securing smart contracts
Goal: test contracts thoroughly with Hardhat, recognise and fix reentrancy, access-control and other common attacks, check invariants and know what fuzzing, static analysis and audits add, and write an honest security review with an incident plan.
You'll need: BC7, Module 26 (Debugging and Testing), Module 46 (Backend Testing), Module 75 (Web App Security), Module 80
(Security Assessment), and the SakhiKosh practice kit (contracts/SakhiFund.sol, contracts/test/, test/contract.test.js).
Where this is used: every serious contract team tests and reviews before deployment; audit firms, bug bounty platforms and security researchers do this work full time.
How it differs: a web app bug might leak data or crash a page, and is patched the same day. A contract bug can let anyone take the money it holds, in one transaction, permanently, while the whole world can read the code looking for it.
Time: reading about 3 hours · practice (the Try it tasks) about 3 hours · assignment about 5 hours.
Lessons
- 1Testing contracts with HardhatReading 15–25 minutes, plus practice✓
- 2ReentrancyReading 15–25 minutes, plus practice✓
- 3Other common attacksReading 15–25 minutes, plus practice✓
- 4Invariants, fuzzing and analysis toolsReading 15–25 minutes, plus practice✓
- 5Security reviews and incident plansReading 15–25 minutes, plus practice✓
🛠️Assignment: Secure SakhiFund
- Fix every finding in the starter's SakhiFund: reentrancy,
tx.origin, unchecked return values, missing access controls and safeguards, plain ether and events. - Run
npm run test:contractuntil all 10 tests pass. - Write
docs/security-review.mdwith scope, findings with severities, fixes, tests and not verified. - Write a half-page incident plan for SakhiKosh: who pauses, who tells members, and how funds move to a fixed contract.
Self-check before you finish:
- [ ] The attack contracts fail against your fund (tests 3 to 5).
- [ ] The invariant holds over 60 random actions (test 9).
- [ ] Every finding has a severity and a matching fix.
- [ ] The review doesn't claim any check you didn't do.
✅Module check
Explain in a few sentences, in your own words:
How do you make a smart contract safe enough to deploy?
Show a good answer
A good answer mentions: tests on fresh fixtures for success, refusals, events, balances and every role; reentrancy fixed with
checks, effects, interactions and a guard on every external call; access control, msg.sender, checked returns, pull payments,
front-running and oracle risks; invariant tests, with fuzzing, static analysis and formal verification where the value justifies it;
and an honest review with severities, fixes, tests and what wasn't verified, plus audits, bounties and an incident plan.
📚Official references
Official documentation and guidance for this module's topics, chosen on 2 November 2026. Tools, laws and standards change, so check the current version before you rely on a detail. If a link has moved, search the same site.
📝Module quiz
10 questions · 10 marks each · 100 marks in all · pass mark 70% · retry as often as you like ·
