OpenEdition.buy() might revert due to uint overflow when it should work.
The buy function in OpenEdition casts the requested amount to a smaller integer type and multiplies it by the sale price, so the multiplication can overflow and revert. An attacker or ordinary buyer could find that a legitimate purchase fails when the total price exceeds the smaller type's maximum.
hansfriese Follow with AkshaySrivastav
Originally disclosed on Code4rena
Submitted by hansfriese, also found by AkshaySrivastav
OpenEdition.buy() might revert due to uint overflow when it should work.
Proof of Concept
OpenEdition.buy() validates the total funds like below.
function buy(uint256 _amount) external payable {
uint24 amount = uint24(_amount);
Sale memory temp = sale;
IEscher721 nft = IEscher721(temp.edition);
require(block.timestamp >= temp.startTime, "TOO SOON");
require(block.timestamp < temp.endTime, "TOO LATE");
require(amount * sale.price == msg.value, "WRONG PRICE"); //@audit overflow
Here, amount was declared as uint24 and sale.price is uint72.
And it will revert when amount * sale.price >= type(uint72).max and such cases would be likely to happen e.g. amount = 64(so 2^6), sale.price = 73 * 10^18(so 2^66).
As a result, buy() might revert when it should work properly.
Recommended Mitigation Steps
We should modify like below.
require(uint256(amount) * sale.price == msg.value, "WRONG PRICE");
stevennevins (Escher) confirmed
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
Likely the multiplication of a uint24 amount by a uint72 price is performed in the smaller type, so the product overflows before it can be compared with the payment.
Impact
Purchases whose total price exceeds the maximum of the smaller integer type would revert, so buyers could not complete valid purchases.
What the attacker needed
Purchase total exceeds the smaller type's max
The fix
The multiplication should be widened to a larger unsigned integer type before comparing with the payment value.
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.
A smart contract stores numbers in fixed-size boxes. If you multiply two numbers and the result is too big for the box, the calculation fails and the transaction is cancelled. Here the code used a box that was too small for the price, so some normal purchases would fail even though the buyer sent the right amount of money.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.