T-Swap Handler Stateful Fuzz #148
-
Hi, I just started the handler stateful fuzz course on the T-Swap chapter. I wonder why we call Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hello @michael-lucas38 , I also wonder why we was withdrawing without depositing I really hope i explained enough to make you understand. |
Beta Was this translation helpful? Give feedback.
-
Actually both the function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
} From the logic above i don't see where it reverts if the amount we want to withdraw is zero, i was actually suspecting the below line of the function _balances[from] = fromBalance - value; Thinking maybe if you subtract zero from zero the EVM might revert but that is not the case as i did a quick test using |
Beta Was this translation helpful? Give feedback.
Hello @michael-lucas38 , I also wonder why we was withdrawing without depositing
handlerStatefullCatchesFuzz.withdrawToken()
but then i realize that the moment we defined ourtargetContract
in ourtestSetup
the fuzzer starts making random function calls to the contract base on what we have defined astargetSelector
, so it only makes call to the selector we included in ourtargetSelector
and the order of which it makes the call is random and that is why it is fuzzing. so at the end of any random call that the fuzzer have made to ourtargetContract
we want to withdraw any money in the contract since we want to assert that the balance of the contract is0
and starting balance of the user is…