Platform: Code4rena
Start Date: 29/07/2021
Pot Size: $20,000 USDC
Total HM: 8
Participants: 12
Period: 3 days
Judge: LSDan
Total Solo HM: 2
Id: 24
League: ETH
Rank: 7/12
Findings: 4
Award: $992.88
🌟 Selected for report: 2
🚀 Solo Findings: 0
169.7571 USDC - $169.76
shw
The approveMax
function of MStableYieldSource
calls the safeApprove
function to set the allowance to the maximum. However, at the time of call, the allowance should be non-zero since it was set to the maximum in the constructor function. The non-zero allowance would cause the safeApprove
function to revert because of a require
check in the OpenZeppelin's implementation (see the following link).
Referenced code: MStableYieldSource.sol#L61-L65
OpenZeppelin - SafeERC20.sol#L52-L55
Use safeIncreaseAllowance
to increase the allowance to the maximum instead (as used in the approveMaxAmount
function of SwappableYieldSource
).
#0 - PierrickGT
2021-08-06T16:40:42Z
419.1534 USDC - $419.15
shw
The supplyTokenTo
function of SwappableYieldSource
assumes that amount
of _depositToken
is transferred to itself after calling the safeTransferFrom
function (and thus it supplies amount
of token to the yield source). However, this may not be true if the _depositToken
is a transfer-on-fee token or a deflationary/rebasing token, causing the received amount to be less than the accounted amount.
Referenced code: SwappableYieldSource.sol#L211-L212
Get the actual received amount by calculating the difference of token balance before and after the transfer. For example, re-writing line 211-212 to:
uint256 balanceBefore = _depositToken.balanceOf(address(this)); _depositToken.safeTransferFrom(msg.sender, address(this), amount); uint256 receivedAmount = _depositToken.balanceOf(address(this)) - balanceBefore; yieldSource.supplyTokenTo(receivedAmount, address(this));
#0 - PierrickGT
2021-08-12T20:37:39Z
139.7178 USDC - $139.72
shw
According to the comments of the FundsTransferred
event in SwappableYieldSource
, the amount
parameter is the number of funds transferred. However, in the _transferFunds
function, the actual transferred amount is currentBalance
, which should be provided as the event parameter instead.
Referenced code: SwappableYieldSource.sol#L288
Change _amount
at line 288 to currentBalance
.
#0 - PierrickGT
2021-08-06T16:49:12Z
36.6656 USDC - $36.67
shw
Changing IERC20(savings.underlying())
to mAsset
at line 62 can save gas since they are identical, and the latter avoids unnecessary external calls.
Referenced code: MStableYieldSource.sol#L62
As above
#0 - PierrickGT
2021-08-13T16:15:54Z
🌟 Selected for report: shw
201.183 USDC - $201.18
shw
Changing the abi.encode
function to abi.encodePacked
at line 77 of SwappableYieldSource
can save gas since the abi.encode
function pads extra null bytes at the end of the call data, which is unnecessary. Also, in general, abi.encodePacked
is more gas-efficient.
Referenced code: SwappableYieldSource.sol#L77
Solidity-Encode-Gas-Comparison
Change abi.encode
to abi.encodePacked
at line 77.
#0 - PierrickGT
2021-08-12T21:16:57Z