Implemented as part of the "Analysis of Smart Contracts on Blockchain" course of UoA, Spring semester 2026.
The meaningful files are:
-
src/MyToken.sol: ERC20 Token Standard [1] compliant smart contract implementation.Contains both a safe
burnfunction and an unsafevulnBurnfunction that does not follow the Checks-Effects-Interactions (CEI) pattern and is thus vulnerable to a re-entrancy attack [2]. -
src/Attacker.sol: Attacker contract that performs a re-entrancy attack.Leverages its
receivefunction to recursively call the vulnerablevulnBurn. -
script/AttackScript.s.sol: A deployment script that orchestrates the attack.
Generated documentation from these source files lives in https://kchousos.github.io/Smart-Contracts-HW1.
First start the local testnet in a separate terminal with the following command:
$ anvilThen, deploy the script on the testnet:
$ forge script script/AttackScript.s.sol \
--rpc-url http://127.0.0.1:8545 \
--private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80A sample transaction trace of the attack exists in /trace.log. Such a trace can be produced with the following command:
$ forge script script/AttackScript.s.sol \
--rpc-url http://127.0.0.1:8545 \
--private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
-vvvv
NatSpec comments [3] in the source code added with the help of Claude Sonnet 4.6.