Smart contract unable to operate due to lack of token funds
Description
Brief/Intro
Attacker can stop protocol from allocating assets to the AutoETH vaults on Ethereum mainnet at any time by forcing approvals to be insufficient which falls in the Smart contract unable to operate due to lack of token funds severity class for Medium.
Once done, the TokeAutoETHStrategy contract will no longer be able to ever allocate assets to the autoETH vault.
Vulnerability Details
function_allocate(uint256amount)internaloverridereturns(uint256){require(TokenUtils.safeBalanceOf(address(weth),address(this))>= amount,"Strategy balance is less than amount");@> TokenUtils.safeApprove(address(weth),address(router), amount);@>uint256 shares = router.depositMax(autoEth,address(this),0); TokenUtils.safeApprove(address(autoEth),address(rewarder), shares); rewarder.stake(address(this), shares);return amount;}
The function above handles the TokeAutoEth contract's WETH allocation to the autoETH vault on Ethereum mainnet. The function approves the router for x amount of WETH, then the router is called with the depositMax() function. This function will try to transfer the current balance of the TokeAutoETH strategy contract in WETH and then use that to mint shares that are ultimately staked into the Rewarder contract.
Below is the depositMax function from AutoPilot Router: https://etherscan.io/address/0x37dd409f5e98ab4f151f4259ea0cc13e97e8ae21#code#F1#L108
An attacker can render this TokeAutoETH Strategy contract to be unable to allocate funds to the autoETH vault by:
Just send 1 wei of WETH into the TokeAutoETH strategy contract anytime.
When we try to allocate say 100 WETH to the autoETH vault, the router will be approved for 100 WETH
The strategy then calls depositMax where that function computes the assetBalance of the strategy contract to be 100 WETH plus 1 wei
Then the router will attempt to transfer 100 WETH plus 1 wei from the strategy contract which will revert because the approval amount to the router is 100 WETH and not 100 WETH plus 1 wei
As a result, WETH allocations to the autoETH vault to then earn yield will not be possible
Impact Details
The TokeAutoETH will be rendered useless for allocation of WETH to the Autopilot vault contracts as the router will attempt to transfer more tokens that it is approved for.
The better function to use in this case is the depositBalance() function which will require us to transfer the 100 WETH allocation to the router contract and the contract then utilizes the balance. That function's implementation in the Autopilot router is seen below:
In the POC above, you will find that the test reverts and if you read the test logs, you will find the reason to be the case where it tries to transfer 100,000,000,000,000,000,001 whereas we approved it for 100,000,000,000,000,000,000: