DYAD - 0x77's results

The first capital efficient overcollateralized stablecoin.

General Information

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

DYAD

Findings Distribution

Researcher Performance

Rank: 168/183

Findings: 1

Award: $0.02

🌟 Selected for report: 0

🚀 Solo Findings: 0

Lines of code

https://github.com/DyadStablecoin/contracts/blob/1dda63c007f8e59b3726a271b26aafa6ea8993e0/src/core/VaultManagerV2.sol#L119

Vulnerability details

Description

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.

Impact Assessment

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.

Proof of Concept

  1. At block.number == 1, user Alice calls deposit to deposit funds, setting idToBlockOfLastDeposit[0] == 1.
  2. When block.number == 10, Alice attempts to withdraw her funds.
  3. Attacker Bob, monitoring Alice's withdrawal operations, initiates a deposit using the same 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.
  4. As miners process Alice's withdrawal request, the condition idToBlockOfLastDeposit[id] == block.number fails, resulting in a failed withdrawal for Alice.

Proof of code

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();
    }

}

Tools Used

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);
    }

Assessed type

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

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter