Summary
The stalkIssuedPerBdv
variable is not updated in the dewhitelistToken
function
Vulnerability Details
The dewhitelistToken
function removes an ERC-20 token from the Silo whitelist, but s.ss[token].stalkIssuedPerBdv
will not be updated.
function dewhitelistToken(address token) internal {
AppStorage storage s = LibAppStorage.diamondStorage();
LibWhitelistedTokens.updateWhitelistStatus(token, false, false, false);
updateStalkPerBdvPerSeasonForToken(token, 1);
delete s.ss[token].selector;
delete s.ss[token].encodeType;
delete s.ss[token].gaugePoints;
delete s.ss[token].gpSelector;
delete s.ss[token].lwSelector;
delete s.ss[token].optimalPercentDepositedBdv;
emit DewhitelistToken(token);
}
In the dewhitelistToken
, updateWhitelistStatus
, and updateStalkPerBdvPerSeasonForToken
functions, the update value of s.ss[token] is not completely updated.
Check the relevant SiloSettings as follows:
https://github.com/Cyfrin/2024-04-beanstalk-2/blob/main/protocol/contracts/beanstalk/AppStorage.sol#L603
https://github.com/Cyfrin/2024-04-beanstalk-2/blob/main/protocol/contracts/beanstalk/AppStorage.sol#L435-L449
* @dev A Token is considered Whitelisted if there exists a non-zero {SiloSettings} selector.
*/
struct SiloSettings {
bytes4 selector;
uint32 stalkEarnedPerSeason;
uint32 stalkIssuedPerBdv;
uint32 milestoneSeason;
int96 milestoneStem;
bytes1 encodeType;
int24 deltaStalkEarnedPerSeason;
bytes4 gpSelector;
bytes4 lwSelector;
uint128 gaugePoints;
uint64 optimalPercentDepositedBdv;
}
Comparison of the updated status of the current contract:
✅ bytes4 selector;
✅ uint32 stalkEarnedPerSeason;
❌ uint32 stalkIssuedPerBdv;
✅ uint32 milestoneSeason;
✅ int96 milestoneStem;
✅ bytes1 encodeType;
✅ int24 deltaStalkEarnedPerSeason;
✅ bytes4 gpSelector;
✅ bytes4 lwSelector;
✅ uint128 gaugePoints;
✅ uint64 optimalPercentDepositedBdv;
Impact
Removing a token's whitelisted status without updating the relevant variables may lead to inconsistencies in the data stored in the contract
Tools Used
Manual review
Recommendations
Please make sure to update or clear related variables appropriately when removing a token's whitelist status