Root + Impact
createLeveragedPosition() is a public function for users to use to deposit and borrow with leverage in a single transaction but because of the onlyOwner modifier, no one can call the function. This will make the protocol unless and nonfunctional for users.
Description
-
The normal behavior of the function is to allow anyone to deposit and borrow with leverage as the protocol intends to
-
The issue is that, there is onlyOwner modifier on the createLeveragedPosition() function which makes the createLeveragedPosition() only callable by the owner of the contract
function createLeveragedPosition(
address _flashLoanToken,
uint256 _flashLoanAmount,
uint256 _collateralAmount,
address _borrowToken,
uint256 _borrowAmount,
bytes calldata _oneInchSwapData,
uint256 _minReturnAmount
@> ) public onlyOwner {
require(_collateralAmount > 0, "Collateral Cannot be Zero");
IERC20(_flashLoanToken).transferFrom(msg.sender, address(this), _collateralAmount);
FlashLoanParams memory params = FlashLoanParams({
collateralToken: _flashLoanToken,
collateralAmount: _collateralAmount,
borrowToken: _borrowToken,
borrowAmount: _borrowAmount,
oneInchSwapData: _oneInchSwapData,
minReturnAmount: _minReturnAmount
});
bytes memory encodedParams = abi.encode(OperationType.OPEN, msg.sender, params);
aavePool.flashLoanSimple(address(this), _flashLoanToken, _flashLoanAmount, encodedParams, 0);
}
Risk
Likelihood:
The likelihood is high since every time a user calls the function, it will revert as not owner
Impact:
The protocol becomes useless since users can not deposit and borrow on leverage
Proof of Concept
Paste this in tests/unit/Stratax.t.sol
function test_NonOwnerCannotCreateLeveragedPosition() public {
address nonOwner = address(0xBEEF);
vm.prank(nonOwner);
vm.expectRevert("Not owner");
stratax.createLeveragedPosition(WETH, 1 ether, 1 ether, USDC, 1_000e6, "", 0);
}
Recommended Mitigation
function createLeveragedPosition(
address _flashLoanToken,
uint256 _flashLoanAmount,
uint256 _collateralAmount,
address _borrowToken,
uint256 _borrowAmount,
bytes calldata _oneInchSwapData,
uint256 _minReturnAmount
- ) public onlyOwner {
+ ) public {
require(_collateralAmount > 0, "Collateral Cannot be Zero");
...
}