Skip to content
Business logic Audit finding Intermediate

Pre-check is not correct

A pre-check in the fillCriteriaBid function can revert a transaction even though the subsequent settlement logic would succeed. An attacker could cause a legitimate bid fill to fail under specific conditions, disrupting protocol functionality.

0xSky Follow

Originally disclosed on Code4rena

Submitted by 0xSky

https://github.com/code-423n4/2022-07-golom/blob/e5efa8f9d6dda92a90b8b2c4902320acf0c26816/contracts/core/GolomTrader.sol#L342

https://github.com/code-423n4/2022-07-golom/blob/e5efa8f9d6dda92a90b8b2c4902320acf0c26816/contracts/core/GolomTrader.sol#L397

fillCriteriaBid can be reverted due to the pre-check while it can work.

Proof of Concept

When refererrAmt > 0 and referrer address is not set (is 0), (o.totalAmt - protocolfee - o.exchange.paymentAmt - o.prePayment.paymentAmt) * amount - p.paymentAmt >= 0 and o.totalAmt < o.exchange.paymentAmt + o.prePayment.paymentAmt + o.refererrAmt can hold true at the same time.

It is when o.refererrAmt > (p.paymentAmt + protocolfee) / amount. In that case, _settleBalances can work, but fillCriteriaBid will be reverted due to the check in line 342.

Recommended Mitigation Steps

I think require(o.totalAmt >= o.exchange.paymentAmt + o.prePayment.paymentAmt) is correct.

0xsaruman (Golom) confirmed, but disagreed with severity and commented:

Very small chance of both conditions happening, o.refererrAmt > (p.paymentAmt + protocolfee) / amount and referrer address is 0.

Resolved https://github.com/golom-protocol/contracts/commit/c15fa96271d8cf764274271eee649c79ca1b1f7d

LSDan (judge) commented:

Nice catch.

This tracks as a medium for me… it breaks protocol functionality given external factors.


The original report as published on Code4rena, by 0xSky. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 pre-check required the total amount to cover exchange and pre-payment amounts plus the referrer fee, but the settlement logic only needed it to cover exchange and pre-payment amounts, so the check was stricter than necessary.

Impact

The function could revert when it should succeed, breaking protocol functionality under specific conditions, though the chance of both conditions occurring is very small.

What the attacker needed

RefererrAmt > 0; referrer address is zero; specific amount conditions hold

The fix

The issue was fixed by changing the pre-check to only require the total amount to cover the exchange and pre-payment amounts, not the referrer fee.

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.

Smart contracts often check conditions before doing work. Here, one check was too strict: it blocked a valid action that would have worked if allowed to continue. This meant some trades could not be completed even though they should have been.

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.

More from Golom contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.