Skip to content

Commit

Permalink
⚡️ rewards: perform check earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
santichez committed Apr 21, 2023
1 parent f8ab2a6 commit 84850f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-news-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly-protocol/protocol": patch
---

⚡️ rewards: perform check earlier
8 changes: 4 additions & 4 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ RewardsControllerTest:testClaimMarketWithoutRewards() (gas: 938771)
RewardsControllerTest:testClaimWithNotEnabledRewardAsset() (gas: 1028427)
RewardsControllerTest:testConfigSettingNewStartWithOnGoingDistributionShouldNotUpdate() (gas: 366825)
RewardsControllerTest:testConfigWithDistributionNotYetStartedShouldNotFail() (gas: 496116)
RewardsControllerTest:testConfigWithTransitionFactorHigherOrEqThanCap() (gas: 145279)
RewardsControllerTest:testConfigWithZeroDepositAllocationWeightFactorShouldRevert() (gas: 91039)
RewardsControllerTest:testConfigWithTransitionFactorHigherOrEqThanCap() (gas: 49747)
RewardsControllerTest:testConfigWithZeroDepositAllocationWeightFactorShouldRevert() (gas: 42868)
RewardsControllerTest:testDifferentDistributionTimeForDifferentRewards() (gas: 1563638)
RewardsControllerTest:testEmitAccrue() (gas: 1017507)
RewardsControllerTest:testEmitClaimRewards() (gas: 910732)
Expand All @@ -252,8 +252,8 @@ RewardsControllerTest:testSetDistributionConfigWithDifferentDecimals() (gas: 974
RewardsControllerTest:testSetDistributionOperationShouldUpdateIndex() (gas: 111881)
RewardsControllerTest:testSetDistributionWithOnGoingMarketOperations() (gas: 966597)
RewardsControllerTest:testSetHigherTotalDistribution() (gas: 1322777)
RewardsControllerTest:testSetLowerAndEqualDistributionPeriodThanCurrentTimestampShouldRevert() (gas: 911962)
RewardsControllerTest:testSetLowerAndEqualTotalDistributionThanReleasedShouldRevert() (gas: 909753)
RewardsControllerTest:testSetLowerAndEqualDistributionPeriodThanCurrentTimestampShouldRevert() (gas: 912358)
RewardsControllerTest:testSetLowerAndEqualTotalDistributionThanReleasedShouldRevert() (gas: 910149)
RewardsControllerTest:testSetLowerDistributionPeriod() (gas: 1543873)
RewardsControllerTest:testSetLowerDistributionPeriodAndLowerTotalDistribution() (gas: 1546642)
RewardsControllerTest:testSetLowerTotalDistribution() (gas: 1322690)
Expand Down
11 changes: 5 additions & 6 deletions contracts/RewardsController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,11 @@ contract RewardsController is Initializable, AccessControlUpgradeable {
/// @param configs The configurations to update each RewardData with.
function config(Config[] memory configs) external onlyRole(DEFAULT_ADMIN_ROLE) {
for (uint256 i = 0; i < configs.length; ) {
// transitionFactor cannot be eq or higher than 1e18 to avoid division by zero or underflow
if (configs[i].transitionFactor >= 1e18) revert InvalidConfig();
// depositAllocationWeightFactor cannot be zero to avoid division by zero when sigmoid equals 1e18
if (configs[i].depositAllocationWeightFactor == 0) revert InvalidConfig();

Distribution storage dist = distribution[configs[i].market];
RewardData storage rewardData = dist.rewards[configs[i].reward];

Expand Down Expand Up @@ -685,13 +690,7 @@ contract RewardsController is Initializable, AccessControlUpgradeable {
rewardData.compensationFactor = configs[i].compensationFactor;
rewardData.borrowAllocationWeightFactor = configs[i].borrowAllocationWeightFactor;
rewardData.depositAllocationWeightAddend = configs[i].depositAllocationWeightAddend;

// transitionFactor cannot be eq or higher than 1e18 to avoid division by zero or underflow
if (configs[i].transitionFactor >= 1e18) revert InvalidConfig();
rewardData.transitionFactor = configs[i].transitionFactor;

// depositAllocationWeightFactor cannot be zero to avoid division by zero when sigmoid equals 1e18
if (configs[i].depositAllocationWeightFactor == 0) revert InvalidConfig();
rewardData.depositAllocationWeightFactor = configs[i].depositAllocationWeightFactor;

emit DistributionSet(configs[i].market, configs[i].reward, configs[i]);
Expand Down

0 comments on commit 84850f9

Please sign in to comment.