Skip to content
Race condition Audit finding Intermediate

LenderCommitmentForwarder#updateCommitment can be front-run by malicious borrower to cause lender to over-commit funds

The updateCommitment function overwrites all commitment data, resetting the maximum principal amount. A malicious borrower can front-run a lender's update with a loan, causing the lender to over-commit funds.

0x52 Follow with chaduke

Originally disclosed on Sherlock

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

Found by

0x52, chaduke

Summary

This is the same idea as approve vs increaseAlllowance. updateCommitment is a bit worse though because there are more reason why a user may wish to update their commitment (expiration, collateral ratio, interest rate, etc).

Vulnerability Detail

LenderCommitmentForwarder.sol#L212-L222

    require(
        _commitment.principalTokenAddress ==
            commitments[_commitmentId].principalTokenAddress,
        "Principal token address cannot be updated."
    );
    require(
        _commitment.marketId == commitments[_commitmentId].marketId,
        "Market Id cannot be updated."
    );

    commitments[_commitmentId] = _commitment;

LenderCommitmentForwarder#updateCommitment overwrites ALL of the commitment data. This means that even if a user is calling it to update even one value the maxPrincipal will reset, opening up the following attack vector:

  1. User A creates a commitment for 100e6 USDC lending against ETH
  2. User A's commitment is close to expiry so they call to update their commitment with a new expiration
  3. User B sees this update and front-runs it with a loan against the commitment for 100e6 USDC
  4. User A's commitment is updated and the amount is set back to 100e6 USDC
  5. User B takes out another loan for 100e6 USDC
  6. User A has now loaned out 200e6 USDC when they only meant to loan 100e6 USDC

Impact

Commitment is abused to over-commit lender

Code Snippet

LenderCommitmentForwarder.sol#L208-L233

Tool used

Manual Review

Recommendation

Create a function that allows users to extend expiry while keeping amount unchanged. Additionally create a function similar to increaseApproval which increase amount instead of overwriting amount.

Discussion

ethereumdegen

I think the only correct way to solve this is to never decrement or change the 'max principal' amount on a commitment because no matter how that is done it can be frontrun attacked in this way.

The only viable solution is to add a mapping that keeps track of how much capital has been allocated from a commitment and always make sure that that is LEQ than the maxPrincipal for that commitment.

ethereumdegen

Github PR: Issue 176 - fixing frontrun attackability of commitment maxPrincipal

IAm0x52

Fix looks good. Now tracks the amount of allocated principle instead of decrementing the max principal of the commitment.

The original report as published on Sherlock, by 0x52. 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 updateCommitment function overwrites the entire commitment struct, resetting the maxPrincipal to its original value instead of preserving the already allocated amount.

Impact

A malicious borrower could cause a lender to over-commit funds by front-running an update and taking multiple loans.

What the attacker needed

Lender has an active commitment; lender updates commitment; attacker can front-run

The fix

The fix tracks the amount of allocated principal instead of decrementing the max principal, as confirmed by the discussion.

How it was found

  1. User A creates a commitment for 100e6 USDC lending against ETH
  2. User A's commitment is close to expiry so they call to update their commitment with a new expiration
  3. User B sees this update and front-runs it with a loan against the commitment for 100e6 USDC
  4. User A's commitment is updated and the amount is set back to 100e6 USDC
  5. User B takes out another loan for 100e6 USDC
  6. User A has now loaned out 200e6 USDC when they only meant to loan 100e6 USDC

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 lender sets a limit on how much they will lend. When they update the commitment (e.g., to change the expiry), the limit is reset to the original amount, even if some has already been lent. An attacker can borrow just before the update, then borrow again after, so the lender lends more than intended.

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 0x52

View all

211 more disclosed reports, 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.