Skip to content
DoS Audit finding Intermediate

MAX_TRUST_LIMIT might be too high

The smart contracts use an expensive sort function that could run out of gas if the list of stakers becomes too long. An attacker could add themselves as a staker to lengthen the list and cause a denial of service, though a limit of 100 stakers is in place.

gpersoon Follow

Originally disclosed on Code4rena

Submitted by gpersoon

Both SumOfTrust.sol and CreditLimitByMedian.sol contain an expensive sort function. This is used by UserManager.sol via the functions getLockedAmount and getCreditLimit.

If the list of stakers would be very long then the sort would take up all the gas and revert. Attackers could make the list of stakers longer by voting in themselves (as soon as they have 3 accounts voted in), this would result in a griefing attack.

Luckily the number of stakers and borrowers is limited in the function updateTrust by applying a limit of MAX_TRUST_LIMIT.

However this limit is quite high (100), if that amount of stakers would be present then an out of gas error would probably occur with the sort. Note: there are also other for loops in the code that could have a similar problem, however sort is the most expensive.

Proof of Concept

Recommended Mitigation Steps

Do a test with a MAX_TRUST_LIMIT number of stakers and borrowers and check if the code still works.

Set the MAX_TRUST_LIMIT so that everything still works, probably include a margin for future changes in gas costs.

GeraldHost (Union Finance) acknowledged:

yes we have tested for this and landed on the 100 limit. We have plans to improve gas efficiency considerably in future.

GalloDaSballo (judge) commented:

The warden has indentify a griefing exploit that can be applied only under specific circumstances, I agree with the severity

The original report as published on Code4rena, by gpersoon. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 sort algorithm has a gas cost that grows with the number of stakers, and the maximum allowed stakers (100) may still be too many for the sort to complete within a block's gas limit.

Impact

An attacker could cause a griefing attack by making the staker list longer, potentially causing out-of-gas errors in functions that use the sort, but the existing limit of 100 may mitigate this.

What the attacker needed

Attacker has 3 accounts voted in; attacker can vote in themselves as staker

The fix

The maximum number of stakers should be set to a value that keeps the sort within gas limits, with a margin for future gas cost changes, and tested with that many stakers.

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 smart contract has a function that sorts a list of people who have staked tokens. Sorting takes more gas (computational effort) as the list grows. If the list gets too long, the sorting uses up all the gas and the transaction fails, which could stop the contract from working for everyone.

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 gpersoon

View all

47 more disclosed reports, best first.

More from Union Finance contest

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.