---
eip: 1973
label: ERC-1973
title: Scalable Rewards
status: Stagnant
type: Standards Track
category: ERC
created: 2019-04-01
official: https://eips.ethereum.org/EIPS/eip-1973
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-1973.md
canonical: https://eips.huatuo.xyz/zh/eip-1973/
lang: zh
tldr: 一种按区块铸造固定数量代币、并在不断变化的参与者之间平均分配的模式，借助累计的“掩码”，每个人只需 O(1) 的 gas 即可领取自己的奖励。
tags: [token, rewards, distribution, pull-payment]
---

# ERC-1973: Scalable Rewards

> A mintable token rewards interface that mints 'n' tokens per block which are distributed equally among the 'm' participants in the DAPP's ecosystem.

**TL;DR:** 一种按区块铸造固定数量代币、并在不断变化的参与者之间平均分配的模式，借助累计的“掩码”，每个人只需 O(1) 的 gas 即可领取自己的奖励。

## 它解决什么问题？

用循环向大量参与者发放奖励（“推送”）无法扩展：地址达到数千个时，循环会超出区块 gas 上限，而且运行循环的人要承担全部 gas。ERC-1973 提出一种**拉取**式设计：每个参与者可随时领取自己的份额，且每次操作的成本与参与者数量无关。

奖励按区块铸造，因此早期参与者（参与者集合较小时）每人获得的份额较大，随着网络增长，人均数额会逐渐变小。

## 它如何运作

该设计是一个累加和（running-sum）累加器：

- **TPP（tokens per participant，每位参与者的代币数）：** 每次铸造新代币时，`TPP = minted / totalParticipants`。
- **roundMask：** 迄今为止所有 TPP 的累计总和。它回答的问题是：“从一开始就在的一位参与者，到现在能赚多少？”
- **participantMask：** 参与者加入或上次提取时记录的 `roundMask` 快照。
- **应得奖励：** `roundMask - participantMask`。提取之后，该参与者的掩码会被重置为当前的 `roundMask`。

铸造有速率限制：`tokensPerBlock` 设定发行量，`blockFreezeInterval` 是两次铸造之间必须经过的区块数。执行铸造时，会向合约发行 `(currentBlock - lastMintedBlock) * tokensPerBlock` 个代币。任何参与者都可以触发。

规范中的算例：2 个参与者时过了 65 个区块，`roundMask` 增加 32.5 个代币。又有 2 人加入，4 个参与者时过了 101 个区块，增加 25.25。从未提取过的参与者应得 `32.5 + 25.25 = 57.75`。

## 示例代码

会计核心部分，简化为现代 Solidity（无访问控制，也没有铸造调度）：

```solidity
// 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
    }
}
```
## 需要注意

- 状态为 **Stagnant**，没有完成的参考实现（规范中的测试用例和实现标注为 WIP）。
- 规范中的示例合约存在缺陷：除以 `totalParticipants` 的整数除法会损失精度（实际实现会按例如 `1e18` 放大），`removeMinters` 不会结算离开的参与者的奖励，`withdraw` 也不返回任何值。请勿原样部署。
- 同样的累加器思路在质押和流动性挖矿合约中被广泛使用，通常按质押量加权，而不是每位参与者平均分一份。
- 谁算“参与者”完全由部署者决定；在示例中，添加参与者不受任何限制。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-1973
