Skip to content

Conversation

@romain-mg
Copy link

@romain-mg romain-mg commented Jul 31, 2025

Description

This PR addresses an issue in the EvenSplitGroupPool contract's group reward share calculation. The changes prevent situations where users are unable to add a new IP to a group due to an incorrect average reward share calculation by implementing an averageRewardShare stale detection and update mechanism.

When removing a IP, the removeIp function checks if the removed IP's expectedGroupRewardShare is equal to the group's averageRewardShare. The averageRewardShare may be outdated in this case, since it should be equal to the largest expectedGroupRewardShare of the group's remaining IPs. Therefore, it is marked as stale.

Then, when adding an IP, if the group averageRewardShare has been previously marked as stale and if the totalGroupRewardShare calculated using the potentially outdated averageRewardShare exceeds 100%, the _updateGroupAverageRewardShare function is called. This function iterates over all the IPs of the group to find the up to date averageRewardShare.

Since high gas costs may occur when calling _updateGroupAverageRewardShare in a group containing a high number of IPs, those checks ensure that this function is called if and only if

  • The group owner wants to add a new IP to the group
  • Not updating the averageRewardShare would make it impossible to add this new IP
  • Updating it may unlock this possibility

Related Issue

#469

Testing

Added test_EvenSplitGroupPool_addIp_after_removeIp_updateGroupRewardShare to the EvenSplitGroupPool tests. This test ensures that when removing the IP with the largest expectedGroupRewardShare from a group and then adding new IPs to the group until not updating the averageRewardShare would make the totalGroupRewardShare exceed 100%, the averageRewardShare is updated and the totalGroupRewardShare is now below 100%.

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.

1 participant