Platform: Code4rena
Start Date: 18/04/2024
Pot Size: $36,500 USDC
Total HM: 19
Participants: 183
Period: 7 days
Judge: Koolex
Id: 367
League: ETH
Rank: 168/183
Findings: 1
Award: $0.02
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: MrPotatoMagic
Also found by: 0x175, 0x486776, 0x77, 0xAkira, 0xAsen, 0xDemon, 0xabhay, 0xblack_bird, 0xlemon, 0xloscar01, 0xtankr, 3docSec, 4rdiii, Abdessamed, AlexCzm, Angry_Mustache_Man, BiasedMerc, Circolors, Cryptor, DMoore, DPS, DedOhWale, Dinesh11G, Dots, GalloDaSballo, Giorgio, Honour, Imp, Jorgect, Krace, KupiaSec, Mrxstrange, NentoR, Pechenite, PoeAudits, Ryonen, SBSecurity, Sabit, T1MOH, TheFabled, TheSavageTeddy, Tychai0s, VAD37, Vasquez, WildSniper, ZanyBonzy, adam-idarrha, alix40, asui, blutorque, btk, c0pp3rscr3w3r, caglankaan, carrotsmuggler, d_tony7470, dimulski, dinkras, djxploit, falconhoof, forgebyola, grearlake, imare, itsabinashb, josephdara, kartik_giri_47538, ke1caM, kennedy1030, koo, lionking927, ljj, niser93, pep7siup, poslednaya, ptsanev, sashik_eth, shaflow2, steadyman, turvy_fuzz, ubl4nk, valentin_s2304, web3km, xyz, y4y, zhaojohnson, zigtur
0.0234 USDC - $0.02
A critical vulnerability has been identified in the withdraw function of the VaultManagerV2
smart contract, where a key state check idToBlockOfLastDeposit[id] == block.number
determines if withdrawals can proceed. This flaw allows attackers to manipulate the idToBlockOfLastDeposit
state by sending a VaultManagerV2::deposit
transaction before the user's withdrawal request. The lack of an isDNftOwner
check in the deposit function enables non-owners to execute this function, thus allowing attackers to modify critical states and block legitimate withdrawals at a low cost.
This vulnerability enables attackers to exploit the front-running technique to alter the contract state of VaultManagerV2::idToBlockOfLastDeposit
, causing legitimate withdrawal attempts to fail. This not only threatens the security of user funds but also severely compromises the contract's usability and trustworthiness.
block.number == 1
, user Alice
calls deposit to deposit funds, setting idToBlockOfLastDeposit[0] == 1
.block.number == 10
, Alice
attempts to withdraw her funds.tokenID
before Alice's withdrawal attempt. According to the ERC20
standard, transactions can be executed even if the amount sent is zero. Since the deposit function lacks proper asset ownership verification, Bob can successfully submit the transaction without actually holding any assets, thereby updating idToBlockOfLastDeposit[0]
to the current block number, 10
.idToBlockOfLastDeposit[id] == block.number
fails, resulting in a failed withdrawal for Alice.By adding the following code to the vaultManagerV2.t.sol
test file, we simulate the attack described above:
contract VaultManagerV2Test is Test, BaseTest { address alice; address bob; function testDeposited() public { vm.roll(1); alice = vm.addr(1); bob = vm.addr(2); vm.startPrank(alice); dNft.mt(); vaultManagerV2.deposit(0, address(daiVault), 0); assert(vaultManagerV2.idToBlockOfLastDeposit(0) == 1); vm.stopPrank(); vm.roll(10); vm.startPrank(bob); vaultManagerV2.deposit(0, address(daiVault), 0); assert(vaultManagerV2.idToBlockOfLastDeposit(0) == 10); vm.stopPrank(); vm.startPrank(alice); vaultManagerV2.withdraw(0, address(daiVault), 0, a); vm.stopPrank(); } }
foundry
To prevent future front-running attacks, it is advised to add an isDNftOwner
check to the deposit function, ensuring that only asset owners can invoke this function. The amendment is as follows:
- function deposit(uint id, address vault, uint amount) external isValidDNft(id) { + function deposit(uint id, address vault, uint amount) external isValidDNft(id) isDNftOwner(id) { idToBlockOfLastDeposit[id] = block.number; Vault _vault = Vault(vault); _vault.asset().safeTransferFrom(msg.sender, address(vault), amount); _vault.deposit(id, amount); }
DoS
#0 - c4-pre-sort
2024-04-27T11:37:44Z
JustDravee marked the issue as duplicate of #1103
#1 - c4-pre-sort
2024-04-27T11:45:34Z
JustDravee marked the issue as duplicate of #489
#2 - c4-pre-sort
2024-04-29T09:26:29Z
JustDravee marked the issue as sufficient quality report
#3 - c4-judge
2024-05-05T20:38:18Z
koolexcrypto marked the issue as unsatisfactory: Invalid
#4 - c4-judge
2024-05-05T20:39:23Z
koolexcrypto marked the issue as unsatisfactory: Invalid
#5 - c4-judge
2024-05-05T20:39:26Z
koolexcrypto marked the issue as unsatisfactory: Invalid
#6 - c4-judge
2024-05-05T21:40:27Z
koolexcrypto marked the issue as nullified
#7 - c4-judge
2024-05-05T21:40:32Z
koolexcrypto marked the issue as not nullified
#8 - c4-judge
2024-05-08T15:27:59Z
koolexcrypto marked the issue as duplicate of #1001
#9 - c4-judge
2024-05-11T19:49:57Z
koolexcrypto marked the issue as satisfactory