Skip to content
DoS Audit finding Intermediate

updateTrust() vouchers also need check maxVouchers

The updateTrust function checks the maxVouchers limit for the vouchees array but not for the vouchers array, so a borrower's vouchers list can grow without bound. This could cause updateLocked to fail due to gas exhaustion when iterating over a large vouchers array.

bin2chen Follow

Originally disclosed on Sherlock

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

Found by

bin2chen

Summary

maxVouchers is to prevent the “vouchees“ array from getting too big and the loop will have the GAS explosion problem, but “vouchers“have the same problem, if you don't check the vouchers array, it is also possible that vouchers are big and cause updateLocked() to fail

Vulnerability Detail

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

vouchees check < maxVouchers ,but vouchers don't check

    function updateTrust(address borrower, uint96 trustAmount) external onlyMember(msg.sender) whenNotPaused {
...
            uint256 voucheesLength = vouchees[staker].length;
            if (voucheesLength >= maxVouchers) revert MaxVouchees();


            uint256 voucherIndex = vouchers[borrower].length;
            voucherIndexes[borrower][staker] = Index(true, uint128(voucherIndex));
            vouchers[borrower].push(Vouch(staker, trustAmount, 0, 0)); /**** don't check maxVouchers****/

Impact

it is also possible that vouchers are big and cause updateLocked() to fail

Code Snippet

Tool used

Manual Review

Recommendation

Solidity

   function updateTrust(address borrower, uint96 trustAmount) external onlyMember(msg.sender) whenNotPaused {
...
            uint256 voucheesLength = vouchees[staker].length;
            if (voucheesLength >= maxVouchers) revert MaxVouchees();


            uint256 voucherIndex = vouchers[borrower].length;
+         if (voucherIndex >= maxVouchers) revert MaxVouchees();
            voucherIndexes[borrower][staker] = Index(true, uint128(voucherIndex));
            vouchers[borrower].push(Vouch(staker, trustAmount, 0, 0)); 

The original report as published on Sherlock, by bin2chen. 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 updateTrust function enforces the maxVouchers limit only on the vouchees array and not on the vouchers array, allowing the vouchers array to grow unbounded.

Impact

It is also possible that vouchers are big and cause updateLocked() to fail.

What the attacker needed

A member account; contract not paused

The fix

The updateTrust function should also check that the vouchers array length does not exceed maxVouchers before adding a new voucher.

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 run code that costs gas, and if a loop goes over too many items it can run out of gas and fail. The contract limits how many people you can vouch for (vouchees) but forgets to limit how many people can vouch for you (vouchers). An attacker could add many vouchers to someone, making later operations that loop over that list fail.

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 bin2chen

View all

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