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.
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
IUserManager(userManager).updateLocked(msg.sender, uint96(amount + fee), true);
…
IUserManager(userManager).updateLocked(borrower, uint96(repayAmount - interest), false);
It will call updateLocked() on UserManager.sol
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
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
vouchers[borrower].push(Vouch(staker, trustAmount, 0, 0));
for (uint256 i = 0; i < vouchers[borrower].length; i++) {
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++) {
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).
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
- A malicious member repeatedly calls the vouch function for a victim with a trust amount of zero.
- The victim's vouchers array grows very large.
- When the victim tries to borrow or repay, the contract loops over the huge array and the transaction runs out of gas.
- 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.