Report ID
#34649
Report type
Smart Contract
Has PoC?
Yes
Target
https://etherscan.io/address/0xC1E088fC1323b20BCBee9bd1B9fC9546db5624C5
Impacts
Illegitimate minting of protocol native assets
Description
When a silo withdraw or transfer is executed, the amount of the deposited token is discounted from the user's position and the proportional BDV needs to be removed also from the user because it is used in order to compute the amount of stalk to account to the user when he mows. This BDV computation is intended to be rounded up against the user in order to always have more value deposited than bdv accounted. However, this computation does not round up and can be exploited by a user to have a greater bdv accounted in his position than the value of the deposited amount.
Vulnerability Details
In particular, the function to compute the bdv to remove is the following one:
As we can see in this computation, the math used is: (amountToRemove - 1)*BDV totalAmountDeposited + 1. However, this computation returns values that will be less than expected. For example: crateAmount = 3 amount = 5 crateBdv = 500 The correct result that it should return is: 5 * 500 / 3 = 833.333 -> 834 (rounded) However, the result of these data would be (5 - 1) * 500 / 3 + 1 = 667 Since the result will be less than expected, the bdv removed to the user's position will be smaller and he will end up with less value deposited than bdv accounted and will be able to mow more stalk than it should.
Impact Details
Since this function is also called during a withdraw of funds, a user could maliciously call several times this function with a specifically crafted amounts to have a bigger BDV accounted but without having deposited an enough amount to back this BDV value. So the end impact will be the user being able to mint more stalk than it should be able to.
References
https://github.com/BeanstalkFarms/Beanstalk/blob/master/protocol/contracts/libraries/Silo/LibTokenSilo.sol#L402
Proof of concept
I contacted with one of the Beanstalk developers (funderbrker) to let them know of the issue as soon as possible and they told me that I should submit it into Immunefi, due to the rush they told me it is not even needed to provide a PoC because it has been already verified.