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

BondNFT.claim can be called several times to increase rewards amount and drain all funds #182

Closed
code423n4 opened this issue Dec 14, 2022 · 3 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-170 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/BondNFT.sol#L168-L187

Vulnerability details

Impact

BondNFT.claim can be called several times to increase rewards amount.

Proof of Concept

BondNft.claim function is called to claim bond rewards that have accrued during the time.
https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/BondNFT.sol#L168-L187

    function claim(
        uint _id,
        address _claimer
    ) public onlyManager() returns(uint amount, address tigAsset) {
        Bond memory bond = idToBond(_id);
        require(_claimer == bond.owner, "!owner");
        amount = bond.pending;
        tigAsset = bond.asset;
        unchecked {
            if (bond.expired) {
                uint _pendingDelta = (bond.shares * accRewardsPerShare[bond.asset][epoch[bond.asset]] / 1e18 - bondPaid[_id][bond.asset]) - (bond.shares * accRewardsPerShare[bond.asset][bond.expireEpoch-1] / 1e18 - bondPaid[_id][bond.asset]);
                if (totalShares[bond.asset] > 0) {
                    accRewardsPerShare[bond.asset][epoch[bond.asset]] += _pendingDelta*1e18/totalShares[bond.asset];
                }
            }
            bondPaid[_id][bond.asset] += amount;
        }
        IERC20(tigAsset).transfer(manager, amount);
        emit ClaimFees(tigAsset, amount, _claimer, _id);
    }

If bond is already expired then function distributes the amount that is accrued in next epochs after bond has expired to bonds that are nor expired yet.

 if (bond.expired) {
                uint _pendingDelta = (bond.shares * accRewardsPerShare[bond.asset][epoch[bond.asset]] / 1e18 - bondPaid[_id][bond.asset]) - (bond.shares * accRewardsPerShare[bond.asset][bond.expireEpoch-1] / 1e18 - bondPaid[_id][bond.asset]);
                if (totalShares[bond.asset] > 0) {
                    accRewardsPerShare[bond.asset][epoch[bond.asset]] += _pendingDelta*1e18/totalShares[bond.asset];
                }
            }

The problem is that currently this function can be called as many times as you wish using Lock.claim function.
So that means that accRewardsPerShare[bond.asset][epoch[bond.asset]] will be always increasing.

Attack example.
1.Attacker creates 2 bonds. One is for short period, another is for little bit longer period.
2.When first bond has expired attacker calls claim too many times to increase accRewardsPerShare[bond.asset][epoch[bond.asset]] value to drain all funds from BondNft.
3.After that attacker claims his another bond and recieve all funds that are in BondNft as reward.

Tools Used

VsCode

Recommended Mitigation Steps

Make sure that accRewardsPerShare updating is made only once.
Such check may help if (bond.expired && bond.pending > 0).

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Dec 14, 2022
code423n4 added a commit that referenced this issue Dec 14, 2022
@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as duplicate of #68

@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as duplicate of #170

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

GalloDaSballo marked the issue as satisfactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-170 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants