Skip to content

fix: ensure getRewards and takeRewards return 0 for closed allos (L-11) #1149

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

Open
wants to merge 2 commits into
base: horizon-oz2/l10-unsafe-encoding
Choose a base branch
from

Conversation

tmigone
Copy link
Member

@tmigone tmigone commented Apr 29, 2025

Tricky bit in HorizonStakingExtension.sol is moving the closedAtEpoch storage update after the RewardsManager internal calls, here: https://github.com/graphprotocol/contracts/pull/1149/files#diff-f0ca33d417ab44fd34813873b594fcfb2dcb852a3bf77c8c3b8ccb88130d9797R378-R380

@tmigone tmigone requested review from Maikol and pcarranzav April 29, 2025 17:09
Copy link

openzeppelin-code bot commented Apr 29, 2025

fix: ensure getRewards and takeRewards return 0 for closed allos (L-11)

Generated at commit: e05352770d9e00d78e9490c657dc603fd3c69c45

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
2
4
0
15
38
59
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector

@tmigone tmigone force-pushed the horizon-oz2/l10-unsafe-encoding branch from 0d9825c to d6783a9 Compare April 30, 2025 17:56
@tmigone tmigone force-pushed the horizon-oz2/l11-rewards-closed-allos branch from caa7fa9 to 93a3838 Compare April 30, 2025 18:02
@tmigone tmigone force-pushed the horizon-oz2/l10-unsafe-encoding branch from d6783a9 to 34a771c Compare April 30, 2025 18:55
@tmigone tmigone force-pushed the horizon-oz2/l11-rewards-closed-allos branch from 93a3838 to 9fdcf37 Compare April 30, 2025 18:55
@@ -836,6 +843,9 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
);
}

// Close the allocation
__allocations[_allocationID].closedAtEpoch = alloc.closedAtEpoch;
Copy link
Member

Choose a reason for hiding this comment

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

The scary thing here is it breaks the checks-effects-interactions pattern... I don't see any reentrancy vectors, as I don't think we do any calls to untrusted addresses in this flow, but it's worth double checking, or reconsidering if it might not be better to make getRewards return 0 but takeRewards work as before

Copy link
Member Author

@tmigone tmigone May 2, 2025

Choose a reason for hiding this comment

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

Agreed, I noted this in the PR comment but perhaps worth doing the same in the code. I don't think there is reentrancy risk, but we can have OZ comment on which alternative they prefer, wdyt?

@tmigone tmigone force-pushed the horizon-oz2/l10-unsafe-encoding branch from 34a771c to 8808257 Compare May 2, 2025 15:13
@tmigone tmigone force-pushed the horizon-oz2/l11-rewards-closed-allos branch from 9fdcf37 to a76885d Compare May 2, 2025 15:20
@tmigone tmigone force-pushed the horizon-oz2/l10-unsafe-encoding branch 2 times, most recently from 6811eb0 to dbc4f37 Compare May 2, 2025 15:45
@tmigone tmigone force-pushed the horizon-oz2/l11-rewards-closed-allos branch 2 times, most recently from 568a714 to 7db0ae7 Compare May 2, 2025 15:47
@tmigone tmigone force-pushed the horizon-oz2/l10-unsafe-encoding branch from dbc4f37 to c2a753d Compare May 2, 2025 17:53
tmigone added 2 commits May 2, 2025 14:53
…L-11)

Signed-off-by: Tomás Migone <tomas@edgeandnode.com>
Signed-off-by: Tomás Migone <tomas@edgeandnode.com>
@tmigone tmigone force-pushed the horizon-oz2/l11-rewards-closed-allos branch from 7db0ae7 to e053527 Compare May 2, 2025 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants