Submitted by hihen, also found by hansfriese, unforgiven, __141345__, rvierdiiev, and HollaDieWaldfee
Malicious user can drain all assets in BondNFT, and other users will lose their rewards.
When calling BondNFT.claim() for an expired bond, it will recalculate accRewardsPerShare. This is because the reward after the expireEpoch does not belong to that expired bond and needs to be redistributed to all other bonds.
In the current implementation of BondNFT.claim(), it can be called repeatedly as long as the expired bond is not released.
According to the formula in the above code, we can find that although each subsequent claim() of the expired bond will transfer 0 reward, the accRewardsPerShare will be updated cumulatively.
Thus, the pending rewards of all other users will increase every time the expired bond is claim()ed.
A malicious user can exploit this vulnerability to steal all assets in BondNFT contract:
An example of such an attack:
Output:
VS Code
I recommend that an expired bond should be forced to release(), claim() an expired bond should revert.
Sample code:
TriHaz (Tigris Trade) confirmed
Alex the Entreprenerd (judge) commented:
GainsGoblin (Tigris Trade) resolved:
