Borrower can reduce the maxTotalSupply below the current totalSupply()
#14
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
grade-a
primary issue
Highest quality submission among a set of duplicates
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
🤖_primary
AI based primary recommendation
🤖_32_group
AI based duplicate group recommendation
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-08-wildcat/blob/fe746cc0fbedc4447a981a50e6ba4c95f98b9fe1/src/market/WildcatMarketConfig.sol#L101-L111
Vulnerability details
Vulnerability Details
According to the documentation; the borrower should not be able to set the
maxTotalSupply
below the outstanding supply of market tokensThis is in order to maintain stability in the market though it is not enforced in
setMaxTotalSupply()
so borrowers are free to set it to what they want as shown in the test below.POC
Add the test function below to
WildcatMarket.t.sol
and run:Reduce capacity
Tools Used
Manual Review
Foundry Testing
Recommendations
Add a check in setMaxTotalSupply to ensure the new value is not less than totalSupply():
function setMaxTotalSupply( uint256 _maxTotalSupply ) external onlyBorrower nonReentrant sphereXGuardExternal { MarketState memory state = _getUpdatedState(); // Revert if the market is closed if (state.isClosed) revert_CapacityChangeOnClosedMarket(); + if (_maxTotalSupply < state.totalSupply()) revert_NewCapLessThanCurrentSupply(); // Call the hook for max total supply update hooks.onSetMaxTotalSupply(_maxTotalSupply, state); // Update the state's max total supply state.maxTotalSupply = _maxTotalSupply.toUint128(); // Persist the state change _writeState(state); // Emit an event indicating the total supply cap has been updated emit_MaxTotalSupplyUpdated(_maxTotalSupply); }
Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: