Submitted by carrotsmuggler, also found by kaden, n1punp, and chaduke
The funciton _withdraw in the balancer strategy contract is called during withdraw operations to withdraw WETH from the balancer pool. The function calculats the amount to withdraw, and then calls _vaultWithdraw function.
The function _vaultWithdraw submits an exit request with the following userData.
A value of 2 here corresponds to specifying the exact number of tokens coming out of the contract. Thus the function _vaultWithdraw will withdraw the exact number of tokens passed to it in its parameter.
The issue however is that the function _vaultWithdraw is not called with the amount of tokens needed to be withdrawn, it is called by the amount scaled down by pricePerShare. Thus if the actual withdrawn amount is less the amounts the user actually wanted. This causes a revert in the next step.
Since an insuffucient amount of tokens are withdrawn, this step will revert if there arent enough spare tokens in the contract. Since the contract incorrectly scales doen the withdraw amount and causes a revert, this is classified as a high severity issue.
The following exercise shows that passing the same exitRequest data to the balancerPool actually extracts the exact number of tokens as specified in minamountsOut.
A position is created on optimisms weth-reth pool. The userData is generated using the following code.
Min amount out of WETH is set to 500 wei. The exitRequestis then constructed as follows with the userData from above.
This is an exit request of type 2, which specifies the exact amount of tokens to be withdrawn. This transaction was then run on tenderly to check how many tokens are withdrawn. From the screenshot here from tenderly we can see only 500 wei of WETH is withdrawn.
This proves that the _vaultWithdraw function withdraws the exact amount of tokens passed to it as a parameter. Since the passed parameter is scaled down by pricePerShare, this leads to an insufficient amount withdrawn, and eventually a revert.
Tenderly
Pass the amount to be withdrawn without scaling it down by pricePerShare.
0xRektora (Tapioca) confirmed via duplicate issue 51
