ERC-1973 · Stagnant · ERC · 2019-04-01
ERC-1973: Scalable Rewards
A pattern for minting a fixed number of tokens per block and splitting them equally among a changing set of participants, using cumulative 'masks' so each person pulls their own reward in O(1) gas.
What problem does it solve?
Paying rewards to many participants by looping over them ("push") does not scale: with thousands of addresses the loop exceeds the block gas limit, and whoever runs it pays all the gas. ERC-1973 proposes a pull design where each participant claims their own share whenever they like, and the cost of each operation does not depend on how many participants exist.
Rewards are minted per block, so early participants (when the set is small) earn a larger share each, and the per-person amount shrinks as the network grows.
How it works
The design is a running-sum accumulator:
- TPP (tokens per participant): each time new tokens are minted,
TPP = minted / totalParticipants. - roundMask: the running total of every TPP so far. It answers "how much would one participant have earned since the beginning?"
- participantMask: a snapshot of
roundMasktaken when a participant joins or last withdrew. - Reward owed:
roundMask - participantMask. After withdrawing, the participant's mask is reset to the currentroundMask.
Minting is rate-limited: tokensPerBlock sets the issuance, and blockFreezeInterval is how many blocks must pass before another mint. When a mint runs, it issues (currentBlock - lastMintedBlock) * tokensPerBlock tokens to the contract. Any participant can trigger it.
Worked example from the spec: 65 blocks pass with 2 participants, so roundMask grows by 32.5 tokens. Two more join, 101 blocks pass with 4 participants, adding 25.25. A participant who never withdrew is owed 32.5 + 25.25 = 57.75.
Sample code
The accounting core, simplified to modern Solidity (no access control or mint scheduling):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract RewardMasks {
uint256 public roundMask; // cumulative tokens-per-participant
uint256 public totalParticipants;
mapping(address => uint256) public participantMask;
function _join(address p) internal {
totalParticipants += 1;
participantMask[p] = roundMask; // start earning from now
}
function _distribute(uint256 minted) internal {
require(totalParticipants > 0, "no participants");
roundMask += minted / totalParticipants;
}
function _claim(address p) internal returns (uint256 owed) {
owed = roundMask - participantMask[p];
participantMask[p] = roundMask;
// transfer `owed` tokens to p
}
}
Things to know
- Status is Stagnant, with no finished reference implementation (the spec's test cases and implementation are marked WIP).
- The spec's sample contract has gaps: integer division by
totalParticipantsloses precision (real implementations scale by e.g.1e18),removeMintersdoes not settle the leaving participant's rewards, andwithdrawreturns no value. Do not deploy it as-is. - The same accumulator idea is widely used in staking and liquidity-mining contracts, usually weighted by stake rather than one equal share per participant.
- Who counts as a "participant" is entirely up to the deployer; in the sample, adding participants is unrestricted.