A dev will lose rewards if after claiming his rewards he mints an NFT
A developer who claims rewards from DevFund and immediately mints an NFT with those funds can lose part of their rewards because the contract updates the developer's reward debt after the external call, so the new minting fees increase the debt before the developer's claim is settled.
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 hasn’t yet started, they stand to lose those rewards. This happens because the system updates the user’s rewardDebt after the callback.
Vulnerability Details
When claiming the dev’s 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 hasn’t started) which increases totalRewardDebt and only after that the dev’s 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 didn’t claim them.
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 hasn’t started yet, the rewards are then redirected to the DevFund contract which triggers the receive function and the totalRewardDebt is updated:
If I understand it correctly then it’s not an issue. I don’t see why myself or anybody else will do this. Especially using a sequencer based tx system like base. This is not an issue to me, not sure about everybody else.
@Koolex, so we are assuming that the protocol would have a receive() function to mint NFTs automatically? Why would that be a likely thing to happen? It was never mentioned that they would be minting NFTs and reenter into their own contract, that can’t possibly be more than a QA. It classifies as a few different things - out of scope and user error, not only is it user error but it is actually owner error and owners are supposed to be much more knowledgeable than users.
As it can be seen by the sponsor’s reply, they were not aware of this bug so it would be an owner error only if they knew the bug existed.
I don’t see why the devs wouldn’t do such thing to support their protocol by using the claimed rewards to mint NFTs. You can see that the sponsor said “not sure if I’ll do this but if I do then it can be an issue”. This means the devs can use this method.
How is it out of scope when the root cause is in the DevFund - a contract that is in-scope?
@TForge1 - There is a middle solution, implement a sweep function under restrictive condition; for instance, when there is no NFT to be nuked any longer. This way, rug-pull is not possible. You could also add to it a timeframe that has to pass first as a delay before sweeping even if all NFTs are nuked.
The original report as published on Code4rena, by 0xlemon. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the contract updates the developer's reward debt after transferring funds, allowing a reentrant mint to increase the total reward debt before the developer's debt is recorded.
Impact
Developers may lose rewards.
What the attacker needed
Developer contract with a receive function; airdrop has not started; developer mints NFT with claimed funds
The fix
Follow the checks-effects-interactions pattern and transfer the developer's funds only after updating all state variables in DevFund::claim().
How it was found
A developer claims rewards from DevFund.
The developer's contract immediately uses these funds to mint NFTs.
If the airdrop hasn't started, this minting triggers the DevFund's receive function.
The totalRewardDebt is increased before the developer's info.rewardDebt is updated.
This results in the developer's info.rewardDebt being set higher than it should be, causing them to lose out on some rewards.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
When a developer claims rewards, the contract sends the money first and only then records how much the developer has been paid. If the developer's contract uses that money to mint an NFT, the minting fees increase a shared total before the record is updated, so the developer is later treated as having already received more than they did.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.