Platform: Code4rena
Start Date: 24/10/2023
Pot Size: $36,500 USDC
Total HM: 4
Participants: 147
Period: 6 days
Judge: 0xDjango
Id: 299
League: ETH
Rank: 10/147
Findings: 2
Award: $681.07
π Selected for report: 1
π Solo Findings: 0
π Selected for report: ayden
Also found by: 0xWaitress, Madalad, Yanchuan, cartlex_, ciphermarco, critical-or-high, d3e4, mert_eren, peanuts, pontifex, trachev, twcctop
676.5498 USDC - $676.55
https://github.com/code-423n4/2023-10-ethena/blob/main/contracts/StakedUSDe.sol#L191#L194
Malicious users can transfer USDe
token to StakedUSDe
protocol directly lead to a denial of service (DoS) for StakedUSDe due to the limit shares check .
User deposit USDe
token to StakedUSDe
protocol to get share via invoke external deposit
function. Let's see how share is calculate :
function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256) { return assets.mulDiv(totalSupply() + 10 ** _decimalsOffset(), totalAssets() + 1, rounding); }
Since decimalsOffset() == 0 and totalAssets equal the balance of USDe
in this protocol
function totalAssets() public view virtual override returns (uint256) { return _asset.balanceOf(address(this)); }
The minimum share is set to 1 etherγ
uint256 private constant MIN_SHARES = 1 ether;
Assuming malicious users transfer 1 ether of USDe
into the protocol and receive ZERO shares, how much tokens does the next user need to pay if they want to exceed the minimum share limit of 1 ether? That would be 1 ether times 1 ether, which is a substantial amount.
I add a test case in StakedUSDe.t.sol
:
function testMinSharesViolation() public { address malicious = vm.addr(100); usdeToken.mint(malicious, 1 ether); usdeToken.mint(alice, 1000 ether); //assume malicious user deposit 1 ether into protocol. vm.startPrank(malicious); usdeToken.transfer(address(stakedUSDe), 1 ether); vm.stopPrank(); vm.startPrank(alice); usdeToken.approve(address(stakedUSDe), type(uint256).max); //1000 ether can't exceed the minimum share limit of 1 ether vm.expectRevert(IStakedUSDe.MinSharesViolation.selector); stakedUSDe.deposit(1000 ether, alice); }
We can see even alice deposit a substantial number of tokens but still cannot surpass the 1 ether share limit which will lead to a denial of service (DoS) for StakedUSDe due to MinShares checks
vscode
We can solve this issue by setting a minimum deposit amount
DoS
#0 - c4-pre-sort
2023-10-31T01:48:34Z
raymondfam marked the issue as sufficient quality report
#1 - c4-pre-sort
2023-10-31T01:48:52Z
raymondfam marked the issue as duplicate of #32
#2 - c4-judge
2023-11-10T20:52:18Z
fatherGoose1 changed the severity to 2 (Med Risk)
#3 - c4-judge
2023-11-10T20:58:07Z
fatherGoose1 marked the issue as satisfactory
#4 - c4-judge
2023-11-14T17:17:07Z
fatherGoose1 marked the issue as selected for report
#5 - fatherGoose1
2023-11-14T17:17:29Z
Solid and succinct report providing an easy-to-understand POC.
#6 - k4zanmalay
2023-11-17T07:12:21Z
Hey @fatherGoose1! In light of this sponsor's comment https://github.com/code-423n4/2023-10-ethena-findings/issues/90#issuecomment-1815520156, will this issue be invalidated too? If there will be prestaked MIN_SHARES amount, _checkMinShares()
will never revert, to be honest it can be completely omitted at this point.
#7 - fatherGoose1
2023-11-27T20:36:49Z
Despite the sponsor claiming that they will personally stake MIN_SHARES, that cannot be verified via the code. This will remain a medium.
π Selected for report: 0xmystery
Also found by: 0x11singh99, 0xAadi, 0xAlix2, 0xG0P1, 0xStalin, 0xWaitress, 0x_Scar, 0xhacksmithh, 0xhunter, 0xpiken, Al-Qa-qa, Arz, Avci, Bauchibred, BeliSesir, Breeje, Bughunter101, DarkTower, Eeyore, Fitro, HChang26, Imlazy0ne, J4X, JCK, Kaysoft, Kral01, Madalad, Mike_Bello90, Noro, PASCAL, PENGUN, Proxy, Rickard, Shubham, SovaSlava, Strausses, Team_Rocket, ThreeSigma, Topmark, Udsen, Walter, Yanchuan, Zach_166, ZanyBonzy, adam-idarrha, adeolu, almurhasan, arjun16, ast3ros, asui, ayden, btk, cartlex_, castle_chain, cccz, chainsnake, codynhat, critical-or-high, cryptonue, csanuragjain, deepkin, degensec, dirk_y, erebus, foxb868, ge6a, hunter_w3b, jasonxiale, kkkmmmsk, lanrebayode77, lsaudit, marchev, matrix_0wl, max10afternoon, nuthan2x, oakcobalt, oxchsyston, pavankv, peanuts, pep7siup, pipidu83, pontifex, ptsanev, qpzm, radev_sw, rokinot, rotcivegaf, rvierdiiev, sorrynotsorry, squeaky_cactus, supersizer0x, tnquanghuy0512, twcctop, twicek, young, zhaojie, ziyou-
4.5226 USDC - $4.52
1.should use EIP-1271 Standard Signature Validation Method for Contracts Standard way to verify a signature when the account is a smart contract https://github.com/code-423n4/2023-10-ethena/blob/main/contracts/EthenaMinting.sol#L342 Recommend to use EIP-1271 Standard to verify a signature when the account is a smart contract
2.unnecessary bitwise or opration
https://github.com/code-423n4/2023-10-ethena/blob/main/contracts/EthenaMinting.sol#L394
If invalidator
not it zero transaction must be revert in verifyNonce
, thus invalidator
== 0 , The bitwise OR operation with 0 on any number always results in the same number, so the OR operation is unnecessary
3.unnecessary addition operation
If the result of getUnvestedAmount
is bigger than zero the transaction must be revert. So blow addition operation is unnecessary result in waste of gas
https://github.com/code-423n4/2023-10-ethena/blob/main/contracts/StakedUSDe.sol#L91
4.unstake not checked the unstake amount lead to waste of gas fee.
https://github.com/code-423n4/2023-10-ethena/blob/main/contracts/StakedUSDeV2.sol#L78#L90
user can invoke unstake
directly without invoking cooldown.Since userCooldown.cooldownEnd
==0 , silo will withdraw zero amount assets which can lead to waste of gas fee.
- if (block.timestamp >= userCooldown.cooldownEnd) { //@audit should ensure >0. + if (block.timestamp >= userCooldown.cooldownEnd && userCooldown.underlyingAmount>0) { userCooldown.cooldownEnd = 0; userCooldown.underlyingAmount = 0; silo.withdraw(receiver, assets); } else { revert InvalidCooldown(); }
#0 - c4-pre-sort
2023-11-02T03:34:46Z
raymondfam marked the issue as sufficient quality report
#1 - c4-judge
2023-11-14T16:45:23Z
fatherGoose1 marked the issue as grade-b