Skip to content

Commit 08e6252

Browse files
committed
Fixed a check for non-zero weight when allocating rewards
We expect the pool weight to be non-zero so that we do not allocate rewards to an empty pool. The condition checking `currentPoolWeight >= 0` was incorrect given `== 0` case is exactly what we want to avoid. The transaction would fail later on `totalAmount / currentPoolWeight` but human-readable revert was the intention of this `require` check.
1 parent edf4690 commit 08e6252

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

contracts/Rewards.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ contract Rewards {
100100

101101
/// @notice Internal function for updating the global state of rewards.
102102
function addRewards(uint96 rewardAmount, uint32 currentPoolWeight) internal {
103-
require(currentPoolWeight >= 0, "No recipients in pool");
103+
require(currentPoolWeight > 0, "No recipients in pool");
104104

105105
uint96 totalAmount = rewardAmount + rewardRoundingDust;
106106
uint96 perWeightReward = totalAmount / currentPoolWeight;

test/sortitionPoolTest.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@ describe("SortitionPool", () => {
280280
).to.be.revertedWith("Ownable: caller is not the owner")
281281
})
282282

283+
it("can not be allocated for an empty pool", async () => {
284+
await token.connect(deployer).mint(deployer.address, 1000)
285+
await expect(
286+
token.connect(deployer).approveAndCall(pool.address, 300, []),
287+
).to.be.revertedWith("No recipients in pool")
288+
})
289+
283290
it("pays rewards correctly", async () => {
284291
await token.connect(deployer).mint(deployer.address, 1000)
285292
await pool.connect(owner).insertOperator(alice.address, 10000)

0 commit comments

Comments
 (0)