Skip to content
DoS Audit finding Intermediate

gas limit DoS via unbounded operations

A malicious member can repeatedly vouch for a victim with a zero trust amount, filling the victim's vouchers array. This makes loops over that array unbounded, so the victim's borrow, repay, and registration transactions run out of gas and fail.

Ch_301 Follow with ctf_sec

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-union-finance-judging/issues/69

Found by

Ch_301, ctf_sec

Summary

Only one attack will lead to two types of vulnerabilities in UserManager.sol and UToken.sol

Vulnerability Detail

On UserManager.sol ==> updateTrust() Case one: malicious users (members) can keep vouching Alice with trustAmount == 0 until his vouchers array achieves the max limit (2**256-1) So when a normal member tries to give vouching to Alice with trustAmount != 0 he will find because the vouchers array completely full.

Case two (which is more realistic ): malicious users (members) can keep vouching Alice with trustAmount == 0 until his vouchers array achieves late’s say 20% of max limit (2**256-1) The problem is when Alice invoke borrow() or repayBorrow() on UToken.sol

Solidity
   IUserManager(userManager).updateLocked(msg.sender, uint96(amount + fee), true);
  …
  IUserManager(userManager).updateLocked(borrower, uint96(repayAmount - interest), false);

It will call updateLocked() on UserManager.sol

Solidity
   function updateLocked(
        address borrower,
        uint96 amount,
        bool lock
    ) external onlyMarket {
        uint96 remaining = amount;

        for (uint256 i = 0; i < vouchers[borrower].length; i++) {
 

The for loop could go through vouchers[] which could be long enough to lead to a "gas limit DoS via unbounded operations" And the same thing with registerMember(), any user could lose all their fund in this transaction

Solidity
       function registerMember(address newMember) public virtual whenNotPaused {
        if (stakers[newMember].isMember) revert NoExistingMember();

        uint256 count = 0;
        uint256 vouchersLength = vouchers[newMember].length;

        // Loop through all the vouchers to count how many active vouches there
        // are that are greater than 0. Vouch is the min of stake and trust
        for (uint256 i = 0; i < vouchersLength; i++) {

Impact

1- The user couldn’t get any more vouching 2- The user will be not able to borrow() or repayBorrow() 3- No one can in invokeregisterMember() successfully for a specific user

Code Snippet

Solidity
   vouchers[borrower].push(Vouch(staker, trustAmount, 0, 0));

https://github.com/sherlock-audit/2022-10-union-finance/blob/main/union-v2-contracts/contracts/user/UserManager.sol#L555

Solidity
    for (uint256 i = 0; i < vouchers[borrower].length; i++) {

https://github.com/sherlock-audit/2022-10-union-finance/blob/main/union-v2-contracts/contracts/user/UserManager.sol#L807

Solidity
           uint256 vouchersLength = vouchers[newMember].length;

        // Loop through all the vouchers to count how many active vouches there
        // are that are greater than 0. Vouch is the min of stake and trust
        for (uint256 i = 0; i < vouchersLength; i++) {

https://github.com/sherlock-audit/2022-10-union-finance/blob/main/union-v2-contracts/contracts/user/UserManager.sol#L637-L641

Tool used

Manual Review

Recommendation

Add check for trustAmount == 0

Discussion

dmitriia

Some minimal trustAmount looks to be needed here as the same can be repeated with dust amounts (say 1 wei, as the attacker pays gas anyway, so financially it will not matter).

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

Likely the contract allows vouches with a zero trust amount and does not cap the number of vouchers per user, so loops over the vouchers array can grow without bound.

Impact

The victim cannot receive new vouches, cannot borrow or repay, and cannot be registered as a member; the report notes that even a small number of zero-value vouchers (around 20% of the maximum) is enough to cause this.

What the attacker needed

Attacker is a member; attacker pays gas for many transactions

The fix

The contract should reject vouches with a zero trust amount and enforce a minimum trust amount to prevent dust-based attacks.

How it was found

  1. A malicious member repeatedly calls the vouch function for a victim with a trust amount of zero.
  2. The victim's vouchers array grows very large.
  3. When the victim tries to borrow or repay, the contract loops over the huge array and the transaction runs out of gas.
  4. The same happens when anyone tries to register the victim as a member.

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 this smart contract, each user has a list of people who vouch for them. The code loops over that list when the user borrows or registers. An attacker can add many useless entries to the list, making the loop so long that the transaction runs out of gas and fails.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by Ch_301

View all

39 more disclosed reports, best first.

More from Union Finance

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.