Omniscia Myso Finance Audit
Router Code Style Findings
Router Code Style Findings
RRE-01C: Inefficient Token Transfers
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | Router.sol:L73-L79, L88-L92 |
Description:
The Router::withdrawFromEscrowAndCreateAuction
function will withdraw the full available balance from the old escrow address towards the msg.sender
and perform another transfer from the msg.sender
towards the new escrow address to satisfy the notional value of the auction.
This transfer path is inefficient in case the withdrawal from the old escrow is less-than-or-equal to the notional value of the new auction.
Impact:
The Router::withdrawFromEscrowAndCreateAuction
function is presently inefficient if the old escrow possesses the same notional value as the new escrow address, a common use case for this particular function.
Example:
62function withdrawFromEscrowAndCreateAuction(63 address oldEscrow,64 address escrowOwner,65 DataTypes.AuctionInitialization calldata auctionInitialization66) external {67 if (!isEscrow[oldEscrow]) {68 revert Errors.NotAnEscrow();69 }70 if (msg.sender != IEscrow(oldEscrow).owner()) {71 revert Errors.InvalidSender();72 }73 IEscrow(oldEscrow).handleWithdraw(74 msg.sender,75 auctionInitialization.underlyingToken,76 IERC20Metadata(auctionInitialization.underlyingToken).balanceOf(77 oldEscrow78 )79 );80 (address newEscrow, uint256 oTokenIndex) = _createEscrow();81 IEscrow(newEscrow).initializeAuction(82 address(this),83 escrowOwner,84 getExerciseFee(),85 auctionInitialization,86 oTokenIndex87 );88 IERC20Metadata(auctionInitialization.underlyingToken).safeTransferFrom(89 msg.sender,90 newEscrow,91 auctionInitialization.notional92 );93 emit WithdrawFromEscrowAndCreateAuction(94 escrowOwner,95 oldEscrow,96 newEscrow,97 auctionInitialization98 );99}
Recommendation:
We advise a direct transfer from the old escrow contract to the new escrow contract to be performed if the notional
value of the new auction is greater than the old escrow contract's balance, fulfilling any difference from the msg.sender
directly if needed.
Alleviation (d9eb549dcca601db1fa91336ebe4d08fa8f2908b):
The code's transfer flows were optimized as advised, ensuring that the code will withdraw to the new escrow address directly if we are effectively replacing an old escrow with a new one, optimizing the code's gas cost in its most common use-case scenario.
RRE-02C: Repetitive Value Literal
Type | Severity | Location |
---|---|---|
Code Style | ![]() | Router.sol:L25, L740 |
Description:
The linked value literal is repeated across the codebase multiple times.
Example:
25bytes4(keccak256("isValidSignature(bytes32,bytes)"));
Recommendation:
We advise it to be set to a constant
variable instead, optimizing the legibility of the codebase.
In case the constant
has already been declared, we advise it to be properly re-used across the code.
Alleviation (d9eb549dcca601db1fa91336ebe4d08fa8f2908b):
The EIP1271_IS_VALID_SELECTOR
constant was renamed to EIP1271_SIG_AND_MAGIC_VALUE
and was properly set to replace the 0x1626ba7e
literal within the Router::_checkEIP1271Signature
function, increasing the legibility of the codebase as advised.