GolomTrader’s _settleBalances double counts protocol fee, reducing taker’s payout for a NFT sold
The _settleBalances function double-counts the protocol fee when calculating the taker's payout, because the fee is multiplied by the order amount twice. An attacker could exploit this to cause the taker to receive less than due, with the excess funds left on the contract balance.
Submitted by hyh, also found by 0x52, 0xSky, auditor0517, ElKu, kaden, Krow10, Lambda, Limbooo, obront, rbserver, rotcivegaf, RustyRabbit, scaraven, wastewa, and zzzitron
Currently (o.totalAmt * 50) / 10000) protocol fee share is multiplied by amount twice when being accounted for as a deduction from the total in amount due to the msg.sender taker calculations in _settleBalances(), which is called by fillBid() and fillCriteriaBid() to handle the payouts.
Setting the severity to be high as reduced payouts is a fund loss impact for taker, which receives less than it’s due whenever amount > 1.
Notice that the amount lost to the taker is left on the contract balance and currently is subject to other vulnerabilities, i.e. can be easily stolen by an attacker that knowns these specifics and tracks contract state. When these issues be fixed this amount to be permanently frozen on the GolomTrader’s balance as it’s unaccounted for in all subsequent calculations (i.e. all the transfers are done with regard to the accounts recorded, this extra sum is unaccounted, there is no general native funds rescue function, so when all other mechanics be fixed the impact will be permanent freeze of the part of taker’s funds).
Proof of Concept
_settleBalances() uses (o.totalAmt - protocolfee - ...) * amount, which is o.totalAmt * amount - ((o.totalAmt * 50) / 10000) * amount * amount - ..., counting protocol fee extra amount - 1 times:
payEther(
(o.totalAmt - protocolfee - o.exchange.paymentAmt - o.prePayment.paymentAmt - o.refererrAmt) *
amount -
p.paymentAmt,
msg.sender
);
} else {
payEther(
(o.totalAmt - protocolfee - o.exchange.paymentAmt - o.prePayment.paymentAmt) * amount - p.paymentAmt,
msg.sender
);
function _settleBalances(
Order calldata o,
uint256 amount,
address referrer,
Payment calldata p
) internal {
uint256 protocolfee = ((o.totalAmt * 50) / 10000) * amount;
WETH.transferFrom(o.signer, address(this), o.totalAmt * amount);
WETH.withdraw(o.totalAmt * amount);
payEther(protocolfee, address(distributor));
payEther(o.exchange.paymentAmt * amount, o.exchange.paymentAddress);
payEther(o.prePayment.paymentAmt * amount, o.prePayment.paymentAddress);
if (o.refererrAmt > 0 && referrer != address(0)) {
payEther(o.refererrAmt * amount, referrer);
payEther(
(o.totalAmt - protocolfee - o.exchange.paymentAmt - o.prePayment.paymentAmt - o.refererrAmt) *
amount -
p.paymentAmt,
msg.sender
);
} else {
payEther(
(o.totalAmt - protocolfee - o.exchange.paymentAmt - o.prePayment.paymentAmt) * amount - p.paymentAmt,
msg.sender
);
}
Say, if amount = 6, while ((o.totalAmt * 50) / 10000) = 1 ETH, 6 ETH is total protocolfee and needs to be removed from o.totalAmt * 6 to calculate taker’s part, while 1 ETH * 6 * 6 = 36 ETH is actually removed in the calculation, i.e. 36 - 6 = 30 ETH of taker’s funds will be frozen on the contract balance.
Recommended Mitigation Steps
Consider accounting for amount once, for example:
function _settleBalances(
Order calldata o,
uint256 amount,
address referrer,
Payment calldata p
) internal {
- uint256 protocolfee = ((o.totalAmt * 50) / 10000) * amount;
+ uint256 protocolfee = ((o.totalAmt * 50) / 10000);
WETH.transferFrom(o.signer, address(this), o.totalAmt * amount);
WETH.withdraw(o.totalAmt * amount);
- payEther(protocolfee, address(distributor));
+ payEther(protocolfee * amount, address(distributor));
payEther(o.exchange.paymentAmt * amount, o.exchange.paymentAddress);
payEther(o.prePayment.paymentAmt * amount, o.prePayment.paymentAddress);
if (o.refererrAmt > 0 && referrer != address(0)) {
payEther(o.refererrAmt * amount, referrer);
payEther(
(o.totalAmt - protocolfee - o.exchange.paymentAmt - o.prePayment.paymentAmt - o.refererrAmt) *
amount -
p.paymentAmt,
msg.sender
);
} else {
payEther(
(o.totalAmt - protocolfee - o.exchange.paymentAmt - o.prePayment.paymentAmt) * amount - p.paymentAmt,
msg.sender
);
}
payEther(p.paymentAmt, p.paymentAddress);
- distributor.addFee([msg.sender, o.exchange.paymentAddress], protocolfee);
+ distributor.addFee([msg.sender, o.exchange.paymentAddress], protocolfee * amount);
}
0xsaruman (Golom) resolved and commented:
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 protocol fee variable already includes the amount multiplier, but it is subtracted again after multiplying the total by amount, causing the fee to be counted amount times too many.
Impact
The taker receives less than they are due whenever amount > 1, and the excess funds remain on the contract balance, potentially stolen by an attacker or permanently frozen.
What the attacker needed
Amount > 1; taker sells an NFT via fillBid or fillCriteriaBid
The fix
The protocol fee should be calculated without the amount multiplier and then multiplied by amount only when paying out, as shown in the recommended mitigation.
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 someone sells an NFT through this contract, the contract calculates how much the seller should get after subtracting fees. A mistake in the code subtracts the protocol fee more times than it should, so the seller gets less money than they are owed. The extra money stays stuck in the contract.
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.