Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maxTotalSupply can be set to any value, even below the current total supply of the market #90

Open
howlbot-integration bot opened this issue Sep 20, 2024 · 2 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-14 edited-by-warden grade-a QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_32_group AI based duplicate group recommendation sufficient quality report This report is of sufficient quality

Comments

@howlbot-integration
Copy link

Lines of code

https://github.com/code-423n4/2024-08-wildcat/blob/main/src/market/WildcatMarketConfig.sol#L101-L111

Vulnerability details

Impact

maxTotalSupply can be set to a value below the current total supply of the market

Proof of Concept

The Wildcat protocol stated that the maxTotalSupply can not be set to below the total supply of the market in README.md:

capacity can only be reduced to a maximum of the current outstanding supply.

It is also stated in https://docs.wildcat.finance/using-wildcat/day-to-day-usage/borrowers#altering-capacity:

As a borrower, you are able to adjust the capacity up to whatever amount you wish, or down to the market's current outstanding supply of market tokens

However, a borrower can set the maximum total supply to any value even below the total supply of the market.
Copy below codes to WildcatMarket.t.sol and run forge test --match-test test_setMaxTotalSupply_LessThanTotalSupply:

  function test_setMaxTotalSupply_LessThanTotalSupply() external {
    //@audit-info alice deposits 50K
    vm.prank(alice);
    market.depositUpTo(50_000e18);
    vm.prank(borrower);
    market.setMaxTotalSupply(20_000e18);
    //@audit-info maxTotalSupply() is less than totalSupply()
    assertLt(market.maxTotalSupply(), market.totalSupply());
  }

Tools Used

Manual review

Recommended Mitigation Steps

Make sure the new maxTotalSupply is no less than the total supply of the market:

  function setMaxTotalSupply(
    uint256 _maxTotalSupply
  ) external onlyBorrower nonReentrant sphereXGuardExternal {
    MarketState memory state = _getUpdatedState();
    if (state.isClosed) revert_CapacityChangeOnClosedMarket();
+   if (_maxTotalSupply < state.totalSupply()) revert CapacityLessThanTotalSupply();

    hooks.onSetMaxTotalSupply(_maxTotalSupply, state);
    state.maxTotalSupply = _maxTotalSupply.toUint128();
    _writeState(state);
    emit_MaxTotalSupplyUpdated(_maxTotalSupply);
  }

Assessed type

Other

@howlbot-integration howlbot-integration bot added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value 🤖_32_group AI based duplicate group recommendation bug Something isn't working duplicate-14 edited-by-warden sufficient quality report This report is of sufficient quality labels Sep 20, 2024
howlbot-integration bot added a commit that referenced this issue Sep 20, 2024
@c4-judge
Copy link
Contributor

c4-judge commented Oct 4, 2024

3docSec changed the severity to QA (Quality Assurance)

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax grade-b and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Oct 4, 2024
@c4-judge
Copy link
Contributor

c4-judge commented Oct 4, 2024

3docSec marked the issue as grade-b

This was referenced Oct 4, 2024
@C4-Staff C4-Staff reopened this Oct 17, 2024
@C4-Staff C4-Staff added grade-a and removed grade-b labels Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-14 edited-by-warden grade-a QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_32_group AI based duplicate group recommendation sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

2 participants