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

Q-AJN-7: zero ERC20 transfer on claim reward #74

Merged
merged 1 commit into from
May 8, 2023
Merged

Conversation

grandizzy
Copy link
Contributor

@grandizzy grandizzy commented May 8, 2023

Description of change

High level

  • Do not ERC20.transfer if rewards claimed are 0
    • check rewardClaimed_ is not 0 in claimDelegateReward() prior to transferring to the recipient

Description of bug or vulnerability and solution

  • In the case where the caller doesn't have any rewards to claim, gas will be wasted on transferring a zero value.
    • if claimed rewards are 0 then do not attempt to transfer
    • _getDelegateReward better readability: minor change to calculate rewards if (votingPowerAllocatedByDelegatee != 0) instead if (votingPowerAllocatedByDelegatee == 0) return 0;
    • expose unit test

Contract size

Pre Change

| Contract              | Size (kB) | Margin (kB) |
|-----------------------|-----------|-------------|
| GrantFund             | 19.422    | 5.154       |

Post Change

| Contract              | Size (kB) | Margin (kB) |
|-----------------------|-----------|-------------|
| GrantFund             | 19.419    | 5.157       |

Gas usage

Pre Change

| Function Name                               | min             | avg    | median | max    | # calls |
| claimDelegateReward                         | 1407            | 57897  | 58540  | 65340  | 341     |

Post Change

| Function Name                               | min             | avg    | median | max    | # calls |
| claimDelegateReward                         | 1407            | 38175  | 36570  | 65359  | 11      |

- if claimed rewards are 0 then do not attempt to transfer
- expose unit test
@grandizzy grandizzy added the enhancement New feature or request label May 8, 2023
@grandizzy grandizzy requested review from MikeHathaway, prateek105, ith-harvey and EdNoepel and removed request for MikeHathaway May 8, 2023 08:18
Copy link
Contributor

@EdNoepel EdNoepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the Transfer check.

Copy link
Contributor

@prateek105 prateek105 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Collaborator

@MikeHathaway MikeHathaway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the fix

@grandizzy grandizzy merged commit 86ddbf8 into main May 8, 2023
@grandizzy grandizzy deleted the quantstamp-ajn-7 branch May 8, 2023 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants