Skip to content
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

User receives proportional reward for burning contrary to docs #228

Closed
c4-submissions opened this issue Nov 17, 2023 · 9 comments
Closed
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@c4-submissions
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-11-canto/blob/335930cd53cf9a137504a57f1215be52c6d67cb3/1155tech-contracts/src/Market.sol#L230-L233

Vulnerability details

Impact

Comment in code states that user doesn't receive reward for his own burn, similar to buying.
However actually he does receive claimable fees for this burn. As a result, actual fee paid for burn is less, because user receives part of it in return.

Proof of Concept

Here you can see incorrect order of operations: it firstly increases shareData[_id].shareHolderRewardsPerTokenScaled by fees, then calculates user's rewards

    function burnNFT(uint256 _id, uint256 _amount) external {
        uint256 fee = getNFTMintingPrice(_id, _amount);

        SafeERC20.safeTransferFrom(token, msg.sender, address(this), fee);
@>      _splitFees(_id, fee, shareData[_id].tokensInCirculation);
        // The user does not get the proportional rewards for the burning (unless they have additional tokens that are not in the NFT)
@>      uint256 rewardsSinceLastClaim = _getRewardsSinceLastClaim(_id);
        rewardsLastClaimedValue[_id][msg.sender] = shareData[_id].shareHolderRewardsPerTokenScaled;
        tokensByAddress[_id][msg.sender] += _amount;
        shareData[_id].tokensInCirculation += _amount;
        _burn(msg.sender, _id, _amount);

        SafeERC20.safeTransfer(token, msg.sender, rewardsSinceLastClaim);
        // ERC1155 already logs, but we add this to have the price information
        emit NFTsBurned(_id, msg.sender, _amount, fee);
    }

But must firstly calculate user's rewards, and only after split fees

Tools Used

Manual Review

Recommended Mitigation Steps

    function burnNFT(uint256 _id, uint256 _amount) external {
        uint256 fee = getNFTMintingPrice(_id, _amount);

        SafeERC20.safeTransferFrom(token, msg.sender, address(this), fee);
+       // The user does not get the proportional rewards for the burning (unless they have additional tokens that are not in the NFT)
+       uint256 rewardsSinceLastClaim = _getRewardsSinceLastClaim(_id);
        _splitFees(_id, fee, shareData[_id].tokensInCirculation);
-       // The user does not get the proportional rewards for the burning (unless they have additional tokens that are not in the NFT)
-       uint256 rewardsSinceLastClaim = _getRewardsSinceLastClaim(_id);
        rewardsLastClaimedValue[_id][msg.sender] = shareData[_id].shareHolderRewardsPerTokenScaled;
        ...
    }

Assessed type

Other

@c4-submissions c4-submissions added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Nov 17, 2023
c4-submissions added a commit that referenced this issue Nov 17, 2023
@c4-pre-sort
Copy link

minhquanym marked the issue as duplicate of #241

@c4-judge
Copy link

MarioPoneder marked the issue as not a duplicate

@c4-judge
Copy link

MarioPoneder marked the issue as duplicate of #9

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Nov 29, 2023
@c4-judge
Copy link

MarioPoneder marked the issue as satisfactory

@d3e4
Copy link

d3e4 commented Nov 30, 2023

This is not a duplicate of #9 and it is invalid. When fees are accrued the burner has not yet received his token on which to accrue rewards, so it all goes to previous holders.

@T1MOH593
Copy link

T1MOH593 commented Dec 1, 2023

Agree with above statement

@MarioPoneder
Copy link

Thank you for your comments!

This was indeed duplicated too quickly and I admit to have overlooked it since the Recommended Mitigation Steps seem to have identified the same core issue as #9, which is in fact not that case.

@c4-judge
Copy link

c4-judge commented Dec 4, 2023

MarioPoneder marked the issue as not a duplicate

@c4-judge c4-judge reopened this Dec 4, 2023
@c4-judge c4-judge closed this as completed Dec 4, 2023
@c4-judge
Copy link

c4-judge commented Dec 4, 2023

MarioPoneder marked the issue as unsatisfactory:
Invalid

@c4-judge c4-judge added unsatisfactory does not satisfy C4 submission criteria; not eligible for awards and removed satisfactory satisfies C4 submission criteria; eligible for awards labels Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

6 participants