juancito - Missing access control on `mintRebalancer` allows unrestricted minting of USSD tokens by anyone affecting pool balance on rebalance
sherlock-admin opened this issue · 0 comments
juancito
high
Missing access control on mintRebalancer
allows unrestricted minting of USSD tokens by anyone affecting pool balance on rebalance
Summary
USSD::mintRebalancer
is missing a modifier to only allow the rebalancer to call it. So anyone can mint any amount of USSD token from the USSD contract.
This allows anyone to alter the price of USSD/DAI by rebalancing the USSD/DAI pool via the USSDRebalancer::rebalance
function.
Vulnerability Detail
mintRebalancer()
can be called by anyone. _mint()
is the internal ERC20Upgradeable
function from OpenZeppelin to mint the USSD token in this case:
function mintRebalancer(uint256 amount) public override {
_mint(address(this), amount);
}
The balance of USSD in the USSD contract is used for the amount
and the collateralFactor
in the SellUSSDBuyCollateral()
function. The totalSupply
of the token (which will be altered as well) is also used.
164: uint256 amount = IUSSD(USSD).balanceOf(USSD);
178: uint256 cf = IUSSD(USSD).collateralFactor(); // @audit-info this also uses the balance and total supply
188: uint ownval = (getOwnValuation() * 1e18 / 1e6) * IUSSD(USSD).totalSupply() / 1e6;
This is then used to swap USSD tokens for DAI via the USSD/DAI pool:
169: IUSSD(USSD).UniV3SwapInput(bytes.concat(abi.encodePacked(uniPool.token0(), hex"0001f4", uniPool.token1())), amount);
173: IUSSD(USSD).UniV3SwapInput(bytes.concat(abi.encodePacked(uniPool.token1(), hex"0001f4", uniPool.token0())), amount);
201: IUSSD(USSD).UniV3SwapInput(collateral[i].pathbuy, daibought/portions); // <-- @audit
Impact
Anyone can unrestrictly mint USSD token, altering the contract balance and total supply.
After that anyone can alter the price of USSD by rebalancing the USSD/DAI pool via the USSDRebalancer::rebalance
function.
Code Snippet
- https://github.com/sherlock-audit/2023-05-USSD/blob/main/ussd-contracts/contracts/USSD.sol#L204-L206
- https://github.com/sherlock-audit/2023-05-USSD/blob/main/ussd-contracts/contracts/USSDRebalancer.sol#L164
- https://github.com/sherlock-audit/2023-05-USSD/blob/main/ussd-contracts/contracts/USSDRebalancer.sol#L169
Tool used
Manual Review
Recommendation
Add the onlyBalancer
modifier to the function:
- function mintRebalancer(uint256 amount) public override {
+ function mintRebalancer(uint256 amount) public override onlyBalancer {
_mint(address(this), amount);
}
Duplicate of #777