-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: fix credit unlock rate bug #85
Comments
Report ID Report type If distributedCredit is large at that moment (just before harvest, lots unlocked), it will be larger than what it would have potentially been under the new unlock regime (as if we "took the unlocking back"). This has the effect of producing an underflow in _calculateUnlockedCredit (https://github.com/alchemix-finance/v2-foundry/blob/master/src/AlchemistV2.sol#L1629), since pendingCredit * percentUnlocked / FIXED_POINT_SCALAR) < distributedCredit. As a consequence, every call to this function, its callers: _distributeCredit, _distributeUnlockedCredit, _calculateUnrealizedDebt, accounts, bubbling up to almost the entire contract API including harvest, poke, burn, repay, liquidate, donate, deposit, withdraw, mint, is going to revert. Impact One can also imagine that this condition is used to maliciously grief the contract, by front running the configureCreditUnlockRate transaction with a dust burn transaction which will bump distributedCredit to its maximum possible value (as demonstrated in the PoC). Even with the "soft" recommendation in place (only send configureCreditUnlockRate after harvest), it is theoretically possible that the signed configureCreditUnlockRate is going to be maliciously withheld until enough time had passed to damage the contract. Recommendation Long term, configureCreditUnlockRate could have a break-in period, where it becomes effective only after the next harvest. Amending distributedCredit at the moment of this call is also an option, as is requiring configureCreditUnlockRate to only succeed if pendingCredit * percentUnlocked / FIXED_POINT_SCALAR) >= distributedCredit. Yet another option is to catch this condition in _calculateUnlockedCredit and return 0. Proof of concept
In my case it was line 855 of https://github.com/alchemix-finance/v2-foundry/blob/a5bfebfc260fd936762c791bd4367f6ec8c7f4f4/test/AlchemistV2.spec.ts Run tests with npx hardhat test Observe Error: VM Exception while processing transaction: reverted with panic code 0x11 (Arithmetic operation underflowed or overflowed outside of an unchecked block) |
No description provided.
The text was updated successfully, but these errors were encountered: