Skip to content
Race condition Audit finding Intermediate

Bid submission vulnerable to market parameters changes

The bid submission function reads market parameters such as payment cycle and default duration from a registry controlled by the market owner, so a market owner can change these settings while a bid transaction is pending. An evil market owner could set the default duration to zero, accept the bid, and immediately liquidate the loan to seize the borrower's collateral.

BAHOZ Follow with Fanz, T1MOH and 6 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-03-teller-judging/issues/205

Found by

BAHOZ, Fanz, T1MOH, cducrest-brainbot, ck, immeas, jpserrat, juancito, whoismatthewmc1

Summary

The details for the audit state:

Market owners should NOT be able to race-condition attack borrowers or lenders by changing market settings while bids are being submitted or accepted (while tx are in mempool). Care has been taken to ensure that this is not possible (similar in theory to sandwich attacking but worse as if possible it could cause unexpected and non-consentual interest rate on a loan) and further-auditing of this is welcome.

However, there is little protection in place to protect the submitter of a bid from changes in market parameters.

Vulnerability Detail

In _submitBid(), certain bid parameters are taken from the marketRegistry:

Solidity
    function _submitBid(...)
        ...
        (bid.terms.paymentCycle, bidPaymentCycleType[bidId]) = marketRegistry
            .getPaymentCycle(_marketplaceId);

        bid.terms.APR = _APR;

        bidDefaultDuration[bidId] = marketRegistry.getPaymentDefaultDuration(
            _marketplaceId
        );

        bidExpirationTime[bidId] = marketRegistry.getBidExpirationTime(
            _marketplaceId
        );

        bid.paymentType = marketRegistry.getPaymentType(_marketplaceId);
        
        bid.terms.paymentCycleAmount = V2Calculations
            .calculatePaymentCycleAmount(
                bid.paymentType,
                bidPaymentCycleType[bidId],
                _principal,
                _duration,
                bid.terms.paymentCycle,
                _APR
            );
        ...

All the parameters taken from marketRegistry are controlled by the market owner: https://github.com/sherlock-audit/2023-03-teller/blob/main/teller-protocol-v2/packages/contracts/contracts/MarketRegistry.sol#L487-L511

Impact

If market parameters are changed in between the borrower submitting a bid transaction and the transaction being applied, borrower may be subject to changes in bidDefaultDuration, bidExpirationTime, paymentType, paymentCycle, bidPaymentCycleType and paymentCycleAmount.

That is, the user may be committed to the bid for longer / shorter than expected. They may have a longer / shorter default duration (time for the loan being considered defaulted / eligible for liquidation). They have un-provisioned for payment type and cycle parameters.

I believe most of this will have a medium impact on borrower (mild inconveniences / resolvable by directly repaying the loan) if the market owner is not evil and adapting the parameters reasonably.

An evil market owner can set the value of bidDefaultDuration and paymentCycle very low (0) so that the loan will default immediately. It can then accept the bid, make user default immediately, and liquidate the loan to steal the user's collateral. This results in a loss of collateral for the borrower.

Code Snippet

Tool used

Manual Review

Recommendation

Take every single parameters as input of _submitBid() (including fee percents) and compare them to the values in marketRegistry to make sure borrower agrees with them, revert if they differ.

Discussion

ethereumdegen

The way the protocol was designed, market owners are 'trusted' however we will add a new submitBid method that adds these checks in case we want to support trustless market owners in the future

ethereumdegen

Github PR: Issue 205 - Harden submitBid from frontrun attacks by market owner

ethereumdegen

A fix was made but it is not being applied at this time because it would create too drastic of a change to the ABI, the way that contracts interact with submitBid. Furthermore, at the time, market owners are 'trusted' and so there is not a concern that they will frontrun.

When we do decide to open up the ability for anyone to be a market owner, we will revisit this fix and implement a protection strategy against front running the fees in the way or add a hard-cap to the fee such as 10% in order to not impact the ABI.

IAm0x52

Sponsor has acknowledged this risk

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

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 bid submission function reads mutable market parameters from a registry controlled by the market owner instead of taking them as explicit inputs from the bidder, so the owner can change them between submission and execution.

Impact

A borrower could be committed to unexpected terms, and an evil market owner could set the default duration to zero, accept the bid, and liquidate the loan to steal the borrower's collateral; the sponsor acknowledged the risk but did not apply the fix because market owners are currently trusted.

What the attacker needed

Market owner is malicious or changes settings; borrower submits a bid transaction

The fix

The bid submission function should take all market parameters as explicit inputs and compare them to the registry values, reverting if they differ; a fix was made but not applied because market owners are currently trusted.

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 submits a bid to borrow money, the contract looks up settings like how long until the loan is considered late. Those settings are controlled by the market owner. If the owner changes them just before the bid is processed, the borrower gets worse terms than they expected, and in the worst case the loan can be made to fail instantly so the borrower loses their collateral.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by BAHOZ

View all

1 more disclosed report, best first.

More from Teller

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.