Omniscia Myso Finance Audit
Escrow Code Style Findings
Escrow Code Style Findings
EWO-01C: Common Option Initialization Code
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | Escrow.sol:L111, L112, L114, L117, L135, L136, L145, L149 |
Description:
The Escrow::initializeRFQMatch
and the Escrow::initializeMintOption
functions contain common code that can be compartmentalized to an internal
function.
Example:
103function initializeRFQMatch(104 address _router,105 address _owner,106 address optionReceiver,107 uint96 _exerciseFee,108 DataTypes.RFQInitialization calldata _rfqInitialization,109 uint256 oTokenIndex110) external initializer {111 optionInfo = _rfqInitialization.optionInfo;112 optionMinted = true;113 premiumPaid = _rfqInitialization.rfqQuote.premium;114 _mint(optionReceiver, _rfqInitialization.optionInfo.notional);115 // @dev: automatically set max. allowance to minimize116 // overhead for follow-on option token swapping via router117 _approve(optionReceiver, _router, type(uint256).max);118 _initialize(119 _router,120 _owner,121 _exerciseFee,122 _rfqInitialization.optionInfo.underlyingToken,123 oTokenIndex124 );125}126
127function initializeMintOption(128 address _router,129 address _owner,130 address optionReceiver,131 uint96 _exerciseFee,132 DataTypes.OptionInfo calldata _optionInfo,133 DataTypes.OptionNaming calldata _optionNaming134) external initializer {135 optionInfo = _optionInfo;136 optionMinted = true;137 router = _router;138 owner = _owner;139 exerciseFee = _exerciseFee;140
141 // @dev: initialize with custom name and symbol142 _name = _optionNaming.name;143 _symbol = _optionNaming.symbol;144
145 _mint(optionReceiver, _optionInfo.notional);146
147 // @dev: automatically set max. allowance to minimize148 // overhead for follow-on option token swapping via router149 _approve(optionReceiver, _router, type(uint256).max);150
151 _decimals = IERC20Metadata(_optionInfo.underlyingToken).decimals();152}
Recommendation:
We advise the highlighted statements to be refactored into an internal call, optimizing the bytecode size and maintainability of the codebase.
Alleviation (d9eb549dcca601db1fa91336ebe4d08fa8f2908b):
The code was optimized by bundling the option's mint as well as approval operation with the contract's optionMinted
status configuration to true
, optimizing the code's gas cost.
EWO-02C: Ineffectual Usage of Safe Arithmetics
Type | Severity | Location |
---|---|---|
Language Specific | ![]() | Escrow.sol:L344, L509, L514 |
Description:
The linked mathematical operation is guaranteed to be performed safely by logical inference, such as surrounding conditionals evaluated in require
checks or if-else
constructs.
Example:
506if (block.timestamp < _decayStartTime) {507 currentAsk = auctionParams.relPremiumStart;508} else if (block.timestamp < _decayStartTime + _decayDuration) {509 uint256 _timePassed = block.timestamp - _decayStartTime;
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 (d9eb549dcc):
The optimization was solely applied to the highlighted item out of the three lines of code identified by this exhibit rendering it partially addressed.
Alleviation (af42d4effc):
The optimization has been properly applied to the borrowedUnderlyingAmounts
subtraction as originally recommended, addressing this exhibit in full.