In this challenge, you need to pay the contract 1 gwei, but the mintFlag function doesn’t accept ETH directly.
The contract has two main entry points:
mintFlag(): This function resets a payment flag, calls the sender, checks if payment was received, and then mints the flag.receive(): This function accepts ETH. If the amount is exactly 1 gwei, it marks the payment flag as true.mintFlag function makes a low-level call to msg.sender: msg.sender.call(""). What side effect does this have?
_paid to be true *after* the callback returns, but it is set to false right before the callback.
receive function while inside the callback initiated by mintFlag.
This pattern demonstrates Control Flow Handover. When a contract calls an external address (especially using call), it pauses its own execution and hands control over to the called address.
While this challenge uses it “safely” (by checking a condition after the call), this mechanism is the root cause of Reentrancy Attacks. In a reentrancy attack, the called contract would call back into the original function (or another function sharing state) before the original state updates were finalized.
This challenge is conceptually the inverse of S1C5: Give Me My Points!. In S1C5, you used the callback to re-enter a function to exploit state that hadn’t updated yet. Here, you use the callback to update state that the caller is waiting for.