Builder can lock in a temporarily low lender fee for all future projects #15
Labels
bug
Something isn't working
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
valid
Lines of code
https://github.com/code-423n4/2022-08-rigor/blob/5ab7ea84a1516cb726421ef690af5bc41029f88f/contracts/Project.sol#L102
Vulnerability details
Impact
The admin has the capability to adjust the lender fee by calling the
replaceLenderFee()
function in theHomeFi.sol
contract.However, users have the ability to lock in future projects at the current 0.5% rate. If the rate is ever temporarily lowered or set to zero, they will also be able to lock in at that lower rate.
This happens because the lender fee is saved in the project initialization (when the
createProject()
function is called), and not pulled dynamically from theHomeFi.sol
contract at the time of the loan. Since users can create unlimited projects at any time without any specific commitment, they can create an arbitrary number of contracts with the lower rate locked in for future use.Proof of Concept
When
createProject()
is called, it calls out to the project factory'screateProject()
function.This function clones and initializes a new instance of
Project.sol
:Finally, this
initialize()
function sets the project's parameters, including calling out toHomeFi.sol
to fetch the current lender fee:This permanently sets the lender fee for the project to
homeFi.lenderFee()
at the time it is created, with no mechanism to update or override this fee.As a result, when
_lenderFee
is calculated and sent to the treasury in thelendToProject()
function ofCommunity.sol
, it is fixed at the original rate.Tools Used
VS Code, vim, hardhat
Recommended Mitigation Steps
Community.sol
can call directly to the HomeFi contract to get the currentlenderFee()
at the time thelendToProject()
function is called.uint256 _lenderFee = (_lendingAmount * homeFi.lenderFee()) / (homeFi.lenderFee() + 1000);
This will allow the protocol to dynamically update the lender fee and have the result of updating all projects going forward, as well as stopping malicious users from locking in low lender fees.
The text was updated successfully, but these errors were encountered: