Stratax Contracts

First Flight #57
Beginner FriendlyDeFi
100 EXP
Submission Details
Impact: high
Likelihood: high

Users can not use the protocol since there is onlyOwner modifier on it

Author Revealed upon completion

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");
// Transfer the user's collateral to the contract
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);
// Initiate flash loan
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");
...
}

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!