[Bug-Candidate]: Sender with zero balance can call the fuzzing harness with msg.value being non-zero
Describe the issue:
Sender with zero balance can call the fuzzing harness with msg.value being non-zero
Code example to reproduce the issue:
Repro: https://github.com/rappie/echidna-sender-bug-repro
Version:
master
Relevant log output:
checkSenderBalance(): failed!💥
Call sequence:
SenderBalance.checkSenderBalance() Value: 0xd766e4f69b27688c
Traces:
emit Log(senderBalanceAtDeploy=0, senderBalanceNow=0, sender=0x0000000000000000000000000000000000010000, msgValue=15521344913595132044)
Hi! I'd like to work on this one — sender-balance and msg.value semantics are home turf for me (I maintain evm-audit-lab, a Foundry-based vulnerability lab).
Reading the repro (echidna config + Foundry side-by-side): the harness accepts a non-zero msg.value from a sender with zero balance, where a real chain would fail the call on the insufficient-balance check.
Plan: pin down where sender balances are initialized versus where msg.value is applied during call-sequence execution, enforce the balance check there while keeping the default sender pre-funding behavior intact, and add a regression test modeled on the repro. I'll post my findings here before opening the PR.
Update: I've opened #1631 with a fix for this.
Root cause: toTx generated msg.value in [0, maxValue] without ever looking at the selected sender's funds, and setupTx credits the destination with the value without debiting the sender — so with balanceAddr: 0 (like the repro config) every non-zero value was impossible on a real chain but still executed by the fuzzer.
The fix caps the generated value at the sender's current balance read from vm.env.contracts (where populateAddresses seeds senders with balanceAddr and internal transfers update it). With a zero balanceAddr senders now transact with value 0 only; raising balanceAddr widens the reachable value range as before.
The PR includes a regression test mirroring the repro above. Feedback welcome.