Submitted by 0xlemon, also found by yixxas
https://github.com/code-423n4/2024-07-traitforge/blob/main/contracts/DevFund/DevFund.sol#L69
https://github.com/code-423n4/2024-07-traitforge/blob/main/contracts/DevFund/DevFund.sol#L74
A developer may lose rewards if the receive function is triggered during the reward claim process from DevFund, resulting in their info.rewardDebt being higher than expected. This scenario can occur when a developer claims their rewards and then immediately mints an NFT with the funds, but the airdrop hasnt yet started, they stand to lose those rewards. This happens because the system updates the users rewardDebt after the callback.
When claiming the devs rewards are calculated as follows:
uint256 pending = info.pendingRewards + (totalRewardDebt - info.rewardDebt) * info.weight;
Then, we do a call to that dev to transfer his funds and only after that call do we update his reward debt to the total reward debt.
This can create a flow in which the developer loses a portion of his rewards. For example, if the dev has a contract that receives his rewards and wants to use that money to then buy an NFT, as he believes in the protocol and wants to support it, he would have a receive function like this:
However, in this scenario the DevFund::receive function will be triggered (if the airdrop hasnt started) which increases totalRewardDebt and only after that the devs info is updated to the totalRewardDebt, which means that the user will later receive less rewards because info.rewardDebt will include the new rewards from the received minting fees but the dev didnt claim them.
This is DevFund::claim():
We can see that the info.rewardDebt happens after the call to the dev, so now if the dev immediately calls the TraitForgeNft contract:
This will mint the developer some NFTs and for each minted NFT the DevFund::receive() will be triggered. The minting in TraitForgeNft distributes the fees to the NukeFund contract and if the airdrop hasnt started yet, the rewards are then redirected to the DevFund contract which triggers the receive function and the totalRewardDebt is updated:
Only after these steps we update the reward debt of the dev, which will be much higher so the developer loses the rewards from this minting fees.
Note: This scenario is more than likely to happen because the developers will want to support the protocol and participate in it.
Follow the CEI pattern and transfer the devs funds only after updating all the state variables in DevFund::claim().
TForge1 (TraitForge) commented:
Koolex (judge) commented:
TForge1 (TraitForge) commented:
samuraii77 (warden) commented:
0xlemon (warden) commented:
Koolex (judge) commented:
