fillAsk() Allows for msg.value to be larger than require locking the excess in the contract
The fillAsk() function only checks that msg.value is at least the required amount, not exactly equal, so any excess Ether sent is permanently locked in the contract. An attacker could deliberately overpay to trap funds, or a user might accidentally lose money.
Originally disclosed on Code4rena
Submitted by AuditsAreUS, also found by 0xSky, arcoun, bin2chen, cccz, CertoraInc, codexploder, cryptonue, dipp, GimelSec, GiveMeTestEther, Green, horsefacts, jayphbee, joestakey, Lambda, minhquanym, obront, peritoflores, rbserver, reassor, rotcivegaf, Ruhum, RustyRabbit, scaraven, Treasure-Seeker, Twpony, and ych18
It is possible to send a higher msg.value than is required to fillAsk(). The excess value that is sent will be permanently locked in the contract.
Proof of Concept
There is only one check over msg.value and it is that it’s greater than o.totalAmt * amount + p.paymentAmt. As seen in the following code snippet from #217.
require(msg.value >= o.totalAmt * amount + p.paymentAmt, 'mgmtm');
The issue here is that the contract will only ever spend exactly o.totalAmt * amount + p.paymentAmt. Hence if msg.value is greater than this then the excess value will be permanently locked in the contract.
Recommended Mitigation Steps
To avoid this issue consider enforcing a strict equality.
require(msg.value == o.totalAmt * amount + p.paymentAmt, 'mgmtm');
0xsaruman (Golom) disagreed with severity and commented:
Disagree with severity cause it’s user choice to send more.
I agree with this being a medium. It opens up the potential for griefing attacks and all sorts of other issues that may be beyond the scope of “the user decided to send excess funds”. Further, it’s common for contracts to return excess funds, so the user may reasonably expect this behaviour.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The contract uses a greater-than-or-equal check on msg.value instead of requiring exact equality, and it never refunds the excess.
Impact
Excess Ether sent to fillAsk() is permanently locked in the contract, which could be used for griefing or cause accidental loss of funds.
What the attacker needed
User sends more Ether than required
The fix
The issue was fixed by changing the check to require strict equality between msg.value and the required amount.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you call a function that accepts Ether, you send some amount of Ether along with the call. This contract only checks that you sent at least enough, not exactly enough. If you send more than needed, the extra Ether stays stuck in the contract forever because there is no way to withdraw it.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.