Omniscia Myso Finance Audit
FundingPool Code Style Findings
FundingPool Code Style Findings
FPL-01C: Duplicate Calculation of Same Value
Type | Severity | Location |
---|---|---|
Gas Optimization | FundingPool.sol:L43, L46 |
Description:
The FundingPool::deposit
function will calculate the amount deposited twice redundantly.
Example:
32function deposit(uint256 amount, uint256 transferFee) external {33 if (amount == 0) {34 revert Errors.InvalidSendAmount();35 }36 uint256 preBal = IERC20Metadata(depositToken).balanceOf(address(this));37 IERC20Metadata(depositToken).safeTransferFrom(38 msg.sender,39 address(this),40 amount41 );42 uint256 postBal = IERC20Metadata(depositToken).balanceOf(address(this));43 if ((postBal - preBal) != amount - transferFee) {44 revert Errors.InvalidSendAmount();45 }46 balanceOf[msg.sender] += postBal - preBal;47}
Recommendation:
We advise the value to be calculated once and stored to a local variable that is consequently utilized, optimizing the code's gas cost.
Alleviation (c740f7c6b5ebd365618fd2d7ea77370599e1ca11):
The FundingPool::deposit
flow was adjusted to be more standard, transferring a surplus of transferFee
rather than subtracting it from the expected transfer result and thus permitting usage of the amount
variable as the value deposited. As such, we consider this optimization adequately applied.
FPL-02C: Ineffectual Usage of Safe Arithmetics
Type | Severity | Location |
---|---|---|
Language Specific | FundingPool.sol:L53 |
Description:
The linked mathematical operation is guaranteed to be performed safely by surrounding conditionals evaluated in either require
checks or if-else
constructs.
Example:
50if (amount == 0 || amount > balanceOf[msg.sender]) {51 revert Errors.InvalidWithdrawAmount();52}53balanceOf[msg.sender] -= amount;
Recommendation:
Given that safe arithmetics are toggled on by default in pragma
versions of 0.8.X
, we advise the linked statement to be wrapped in an unchecked
code block thereby optimizing its execution cost.
Alleviation (c740f7c6b5ebd365618fd2d7ea77370599e1ca11):
The referenced arithmetic statement has been safely wrapped in an unchecked
code block, optimizing its execution cost.
FPL-03C: Inefficient mapping
Lookups
Type | Severity | Location |
---|---|---|
Gas Optimization | FundingPool.sol:L50, L53, L71, L77, L80, L81, L82, L83, L104, L107, L111, L112, L113 |
Description:
The linked statements perform key-based lookup operations on mapping
declarations from storage multiple times for the same key redundantly.
Example:
49function withdraw(uint256 amount) external {50 if (amount == 0 || amount > balanceOf[msg.sender]) {51 revert Errors.InvalidWithdrawAmount();52 }53 balanceOf[msg.sender] -= amount;54 IERC20Metadata(depositToken).safeTransfer(msg.sender, amount);55}
Recommendation:
As the lookups internally perform an expensive keccak256
operation, we advise the lookups to be cached wherever possible to a single local declaration that either holds the value of the mapping
in case of primitive types or holds a storage
pointer to the struct
contained.
Alleviation (c740f7c6b5):
The referenced mapping lookups have been partially optimized as certain pairs (i.e. subscriptionAmountOf
in FundingPool::unsubscribe
) do not make use of the capability to cache interim mapping
lookups (i.e. mapping(address => uint256) storage subscriptionAmountsOfProposal = subscriptionAmountOf[loanProposal]
). As such, we consider this exhibit partially alleviated.
Alleviation (37cf23668b):
Any potential caching operations for interim mapping
lookups have been properly applied to the referenced lines of code within the exhibit in the latest commit hash of the report, applying this exhibit's optimization in full.
FPL-04C: Redundant Parenthesis Statement
Type | Severity | Location |
---|---|---|
Code Style | FundingPool.sol:L43 |
Description:
The referenced statement is redundantly wrapped in parenthesis (()
).
Example:
43if ((postBal - preBal) != amount - transferFee) {
Recommendation:
We advise them to be safely omitted, increasing the legibility of the codebase.
Alleviation (c740f7c6b5ebd365618fd2d7ea77370599e1ca11):
The redundant parenthesis statement has been omitted as advised.