Skip to content
Business logic Audit finding Advanced

Index mismatch on vouchers and vouchees might lead to invalid borrower-voucher-staker association

When a borrower has only one voucher but the staker has vouched for several borrowers, the code overwrites the voucher index of the wrong borrower's record. This can corrupt the association between borrowers, vouchers and stakers in the contract.

weeeh_ Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-union-judging/issues/4

Found by

weeeh_

Summary

In certain situation, we can have a wrong borrower-voucher-staker association on the smart contract UserManager.sol

Vulnerability Detail

When vouchers[borrower] does contain only one element, which means borrower does only have one vouche, and the staker gave more than one vouche to borrowers, and so vouchees[staker].length > 1 and vouchees[staker][0].borrower != borrower. Then as shown on loc https://github.com/sherlock-audit/2023-02-union/blob/main/union-v2-contracts/contracts/user/UserManager.sol#L604 the vouchees[staker][0].voucherIndex will be overwritten to 0, which might be the wrong value, because we are modifying the struct Vouchee associated to another borrower.

Impact

The issue might impact the integrity of the contract by mismatching borrowers and stakers

Code Snippet

https://github.com/sherlock-audit/2023-02-union/blob/main/union-v2-contracts/contracts/user/UserManager.sol#L583-L607

Tool used

vim Manual Review

Recommendation

We suggest to check the vouchers[borrower] length before writing to vouchees map.

Discussion

kingjacob

https://github.com/unioncredit/union-v2-contracts/pull/105 PR also fixes the related 4,31,41,39

dmitriia

Looks ok

The original report as published on Sherlock, by weeeh_. 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 removal logic writes to the first vouchee entry without checking whether that entry actually belongs to the borrower being removed.

Impact

The integrity of the contract could be affected because borrowers and stakers may be mismatched.

What the attacker needed

Staker vouches for more than one borrower; borrower has exactly one voucher

The fix

The code should check the length of the borrower's voucher list before writing to the vouchees map, and a pull request addressing this and related issues was merged.

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 staker puts credit behind borrowers, and the contract keeps a list of who vouched for whom. When one borrower is removed from that list, the code updates the wrong entry, so the records no longer match reality. That means the contract's bookkeeping about who backs whom can become wrong.

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 from Union Finance Update

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.