Skip to content
Business logic Audit finding Intermediate

updateCommitmentBorrowers does not delete all existing users

The updateCommitmentBorrowers function uses the delete keyword on a mapping that contains an EnumerableSet, which does not clear the underlying mapping. As a result, previously removed borrowers remain in the set and can still call acceptCommitment to obtain a loan.

cducrest-brainbot Follow with monrel and nobody2018

Originally disclosed on Sherlock

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

Found by

cducrest-brainbot, monrel, nobody2018

Summary

delete a complex structure that includes mapping will cause problem. See [ethereum/solidity#11843](https://github.com/ethereum/solidity/pull/11843) for more info.

Vulnerability Detail

The lender can update the list of borrowers by calling LenderCommitmentForwarder.updateCommitmentBorrowers. The list of borrowers is EnumerableSetUpgradeable.AddressSet that is a complex structure containing mapping. Using the delete keyword to delete this structure will not erase the mapping inside it. Let's look at the code of this function.

Solidity
mapping(uint256 => EnumerableSetUpgradeable.AddressSet)
        internal commitmentBorrowersList;
        
function updateCommitmentBorrowers(
        uint256 _commitmentId,
        address[] calldata _borrowerAddressList
    ) public commitmentLender(_commitmentId) {
        delete commitmentBorrowersList[_commitmentId];
        _addBorrowersToCommitmentAllowlist(_commitmentId, _borrowerAddressList);
    }

I wrote a similar function to prove the problem.

Solidity
using EnumerableSet for EnumerableSet.AddressSet;
    mapping(uint256 => EnumerableSet.AddressSet) internal users;
    
    function test_deleteEnumerableSet() public {
        uint256 id = 1;
        address[] memory newUsers = new address[](2);
        newUsers[0] = address(0x1);
        newUsers[1] = address(0x2);

        for (uint256 i = 0; i < newUsers.length; i++) {
            users[id].add(newUsers[i]);
        }
        delete users[id];
        newUsers[0] = address(0x3);
        newUsers[1] = address(0x4);
        for (uint256 i = 0; i < newUsers.length; i++) {
            users[id].add(newUsers[i]);
        }
        bool exist = users[id].contains(address(0x1));
        if(exist) {
            emit log_string("address(0x1) exist");
        }
        exist = users[id].contains(address(0x2));
        if(exist) {
            emit log_string("address(0x2) exist");
        }
    }
/*
[PASS] test_deleteEnumerableSet() (gas: 174783)
Logs:
  address(0x1) exist
  address(0x2) exist
*/

Impact

The deleted Users can still successfully call LenderCommitmentForwarder.acceptCommitment to get a loan.

Code Snippet

https://github.com/sherlock-audit/2023-03-teller/blob/main/teller-protocol-v2/packages/contracts/contracts/LenderCommitmentForwarder.sol#L240-L246

Tool used

Manual Review

Recommendation

In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an array of EnumerableSet.

Discussion

ethereumdegen

Github PR : Issue 88 - Changing the way borrowers are updated for Lender Commitment

IAm0x52

Fix looks good. updateCommitmentBorrowers has been split into two separate functions:

addCommitmentBorrowers - Explicitly adds borrowers listed removeCommitmentBorrowers - Explicitly removes borrowers listed

The original report as published on Sherlock, by cducrest-brainbot. 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

Impact

Previously removed borrowers could still call acceptCommitment and obtain a loan, bypassing the lender's updated borrower list.

What the attacker needed

Lender role; existing commitment with borrowers

The fix

The function was fixed by splitting it into separate add and remove functions that explicitly manage borrowers.

How it was found

  1. Lender calls updateCommitmentBorrowers with a new list of borrowers.
  2. The function deletes the existing commitmentBorrowersList entry for the commitment.
  3. The function adds the new borrowers to the list.
  4. Previously deleted borrowers are still present in the set due to the mapping not being cleared.
  5. Those borrowers can still call acceptCommitment and get a loan.

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.

In Solidity, a smart contract language, a mapping is like a dictionary that stores data. When you use 'delete' on a structure that contains a mapping, the mapping itself is not cleared. So, old entries stay, and people who were supposed to be removed can still access the system.

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 by cducrest-brainbot

View all

11 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.

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.