20,000 USDC
View results
Submission Details
Severity: gas
Valid

Setter functions not checking if value changed

Summary

Setter functions can reset value to same value

Vulnerability Details

The following functions when setting state variables to a new variable do not check if the old variable is the same as the new variable.
Lender.sol line 84
function setLenderFee(uint256 _fee) external onlyOwner {
if (_fee > 5000) revert FeeTooHigh();
lenderFee = _fee;
}
Lender.sol line 92
function setBorrowerFee(uint256 _fee) external onlyOwner {
if (_fee > 500) revert FeeTooHigh();
borrowerFee = _fee;
}
Lender.sol line 100
function setFeeReceiver(address _feeReceiver) external onlyOwner {
feeReceiver = _feeReceiver;
}
Lender.sol line 210
function updateMaxLoanRatio(bytes32 poolId, uint256 maxLoanRatio) external {
if (pools[poolId].lender != msg.sender) revert Unauthorized();
if (maxLoanRatio == 0) revert PoolConfig();
pools[poolId].maxLoanRatio = maxLoanRatio;
emit PoolMaxLoanRatioUpdated(poolId, maxLoanRatio);
} // no check that new maxLoanRatio is not same as old

Lender.sol line 221
function updateInterestRate(bytes32 poolId, uint256 interestRate) external {
if (pools[poolId].lender != msg.sender) revert Unauthorized();
if (interestRate > MAX_INTEREST_RATE) revert PoolConfig();
pools[poolId].interestRate = interestRate;
emit PoolInterestRateUpdated(poolId, interestRate);
}

Impact

Gas: By doing so there is gas waste of SSTORE 5000 gas for no impact on state of contracts.

Tools Used

Manual Analysis

Recommendations

It is recommended to only store new variable in state if it is different from the old value see examples below
Lender.sol line 84
function setLenderFee(uint256 _fee) external onlyOwner {
if (_fee > 5000) revert FeeTooHigh();
if(_fee != lenderFee) {
lenderFee = _fee;
}
}
Lender.sol line 92
function setBorrowerFee(uint256 _fee) external onlyOwner {
if (_fee > 500) revert FeeTooHigh();
if(_fee != borrowerFee) {
borrowerFee = _fee;
}
}
Lender.sol line 100
function setFeeReceiver(address _feeReceiver) external onlyOwner {
if(_feeReceiver != feeReceiver) {
feeReceiver = _feeReceiver;
}
}
Ensure to check first that the new value to be set is different from the current value in storage
Change for all other instances in the links in similar manner

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.