Skip to content
Business logic Audit finding Beginner

Missing upper limit definition in replaceLenderFee() of HomeFi.sol

The admin of the HomeFi contract can set the lender fee to any arbitrary value, including one greater than 100%. This causes the fee calculation in lendToProject() to overflow, making all future lending calls revert.

MiloTruck Follow

Originally disclosed on Code4rena

Submitted by MiloTruck, also found by 141345, 0x52, 8olidity, cccz, Ch_301, codexploder, cryptonue, hansfriese, Ruhum, and sseefried

Community.sol#L392-L394 HomeFi.sol#L184-L197

The admin of the HomeFi contract can set lenderFee to greater than 100%, forcing calls to lendToProject() to all projects created in the future to revert.

Proof of Concept

Using the function replaceLenderFee(), admins of the HomeFi contract can set lenderFee to any arbitrary uint256 value:

 185:        function replaceLenderFee(uint256 _newLenderFee)
 186:            external
 187:            override
 188:            onlyAdmin
 189:        {
 190:            // Revert if no change in lender fee
 191:            require(lenderFee != _newLenderFee, "HomeFi::!Change");
 192:
 193:            // Reset variables
 194:            lenderFee = _newLenderFee;
 195:
 196:            emit LenderFeeReplaced(_newLenderFee);
 197:        }

New projects that are created will then get its lenderFee from the HomeFi contract. When communities wish to lend to these projects, it calls lendToProject(), which has the following calculation:

 392:        // Calculate lenderFee
 393:        uint256 _lenderFee = (_lendingAmount * _projectInstance.lenderFee()) /
 394:            (_projectInstance.lenderFee() + 1000);

If lenderFee a large value, such as type(uint256).max, the calculation shown above to overflow. This prevents any community from lending to any new projects.

Recommended Mitigation Steps

Consider adding a reasonable fee rate bounds checks in the replaceLenderFee() function. This would prevent potential griefing and increase the trust of users in the contract.

zgorizzo69 (Rigor) confirmed


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

The replaceLenderFee() function lacks an upper bound check on the new fee value, allowing an arbitrarily large uint256 that causes an arithmetic overflow in the fee calculation.

Impact

All calls to lendToProject() for newly created projects would revert, preventing any community from lending to them.

What the attacker needed

Admin privileges on HomeFi contract; new project created after fee change

How it was found

  1. The admin calls replaceLenderFee() with a very large value, such as the maximum uint256.
  2. A new project is created and inherits this lenderFee from HomeFi.
  3. A community calls lendToProject() for that project.
  4. The fee calculation overflows and the transaction reverts.

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 lets an administrator change a fee percentage. There is no check that the new fee is sensible, so the admin can set it to an enormous number. When someone later tries to lend money, the maths overflows and the transaction fails, blocking all new lending.

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 by MiloTruck

View all

35 more disclosed reports, best first.

More from Rigor Protocol contest

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.