Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-0027: Emission Soft-Fork #52

Merged
merged 21 commits into from Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -19,3 +19,4 @@ Please check out existing EIPs, such as [EIP-1](eip-0001.md), to understand the
| [EIP-0022](eip-0022.md) | Auction Contract |
| [EIP-0024](eip-0024.md) | Artwork contract |
| [EIP-0025](eip-0025.md) | Payment Request URI |
| [EIP-0027](eip-0025.md) | Emission Retargeting Soft-Fork |
292 changes: 292 additions & 0 deletions eip-0027.md
@@ -0,0 +1,292 @@
Emission Retargeting Soft-Fork
===============================

* Author: kushti
* Status: Implemented
* Created: 17-Dec-2021
* Last edited: 4-Jun-2022
* License: CC0
* Forking: Soft Fork


Motivation
----------

The long-term security of the Ergo protocol, including its crypto-economic security, is always of the highest priority for the community and core developers. One of the hottest research topics in this field is the possible (in)stability of cryptocurrency protocols after their stable block rewards from emissions come to an end.[[1]](#references)

During the launch of the Ergo network, it was planned that miners would be rewarded with transaction fees and storage rent (a unique source of mining income) after the end of emission. However, it is difficult to estimate how sufficient or consistently storage rent will replace emissions.

Thus, it was proposed on the ErgoForum informally (in [[2]](#references) and [[3]](#references)) to prolong emission (while preserving the total supply) via a soft-fork([4](#references)). This EIP concludes previous discussions and provides further details on the proposed emission soft-fork design and implementation.

Updated Emission Schedule
-------------------------

Starting from block **#777,217** (the first block of the 759th voting epoch), the new emission rules described in this EIP will be applied on top of the rules described in the Ergo Whitepaper.

Before the end of the current emission (block #2,080,800):

* If the block reward **R >= 15 ERG**, send **12 ERG** to the re-emission contract.
* otherwise, if **R < 15 ERG**, send **R - 3 ERG** to the re-emission contract

After the end of the current emission (starting from block #2,080,800), the re-emission contract works like the existing emission contract. However, it does not have the emission curve encoded, only a flat payout.

* Pay **3 ERG each block** from the re-emission contract.


Updated Emission Details
------------------------

With the updated emission schedule described above, re-emission (with 3 ERG re-emission rewards per block) would be enough for 4,566,336 blocks (~17.38 years).

General Design
--------------

Ergo's emissions are controlled via a smart contract which has existed since before the genesis block (pre-genesis state).

This EIP proposes using the existing contract in combination with checks performed in the core protocol, which are only mandatory for mining nodes. Non-updated nodes will continue to successfully validate all transactions valid for the new nodes (both checking and not checking the new rules) after activation, making this change a **soft-fork**.

This EIP offers the following procedure for achieving this:

* Inject two new tokens into the emission contract.
* The first token is a *singleton* issued to mark the emission box (It can also be used to track the emission box efficiently).
* The second token is the re-emission token, which will go into mining reward boxes.

* The amount of re-emission tokens in a mining rewards box shows how many ERG a miner should send to the re-emission contract when spending the box. Any miner can do the injection, which happens on activation height.

We introduce two new contracts, which are described in greater detail below.

* The **re-emission contract** pays 3 ERG for each block after the end of emission.
* The **pay-to-reemission** contract is a proxy contract active before the re-emission contract.

Miners are forced to pay this proxy contract. The contract is similar to the existing fee contract but with no time lock.

We create new consensus-level checks that verify that the proper amount of re-emission tokens goes from the emission box to a miner rewards box.

Furthermore, we ensure that when spending a box that is *not an emission box but contains re-emission tokens* (the miner rewards box), the tokens are burnt, and the same amount of nanoERG is locked in a box with the pay-to-reemission contract (aka the proxy contract).

These checks can be switched off via a soft-fork (via a vote on disabling rule #123).

Contracts
-------------------

Contracts and new consensus-level checks define re-emission tokens flow and re-emission <-> ERG token swap
rules. They are as follows:

* At the activation height, re-emission tokens are injected into the emission box (consensus-level check)
* Starting from the given activation height, a miner must inject a certain amount of re-emission tokens into its reward box (consensus-level check)
* When a box with re-emission tokens (so a reward box) is spent, re-emission tokens must be burnt, and a corresponding amount of ERG must be sent to the pay-to-reemission contract (consensus-level check)
* Periodically, pay-to-re-emission boxes are merged with the re-emission contract box (contract-level check)
* From the re-emission contract box, ERGs can be withdrawn starting from the re-emission start height, 3 ERG per block (contract-level check)

**Re-emission contract**: This contract pays 3 ERG per block starting from block #2,080,800 . Also, this contract allows for merging with other boxes; the merging transaction must have only two outputs; the first output is for the re-emission contract, and the second one is to pay a mining fee (its value can be 0.01 ERG at most)

```scala
val reemissionRewardPerBlock = monetarySettings.oneEpochReduction // 3 ERG

val rOutTokens = OptionGet(ExtractRegisterAs(reemissionOut, R2)(SCollection(STuple(SCollection(SByte), SLong))))

val firstTokenId = SelectField(ByIndex(rOutTokens, IntConstant(0)), 0.toByte)

val correctNftId = EQ(firstTokenId, ByteArrayConstant(reemissionNftId))

// output of the reemission contract
val reemissionOut = ByIndex(Outputs, IntConstant(0))
scalahub marked this conversation as resolved.
Show resolved Hide resolved

// output to pay miner
val minerOut = ByIndex(Outputs, IntConstant(1))
scalahub marked this conversation as resolved.
Show resolved Hide resolved

// miner's output must have a script which is the time-locking reward for the miner's pubkey
// box height must be the same as block height
val correctMinerOutput = AND(
EQ(ExtractScriptBytes(minerOut), expectedMinerOutScriptBytesVal(monetarySettings.minerRewardDelay, MinerPubkey)),
EQ(Height, boxCreationHeight(minerOut))
)

// reemission output's height must be the same as block height
val heightCorrect = EQ(boxCreationHeight(reemissionOut), Height)

// reemission output's height is greater than reemission input
val heightIncreased = GT(Height, boxCreationHeight(Self))

// check that height is greater than end of emission (>= 2,080,800 for the mainnet)
val afterEmission = GE(Height, IntConstant(emissionPeriod))

// reemission contract must be preserved
val sameScriptRule = EQ(ExtractScriptBytes(Self), ExtractScriptBytes(reemissionOut))

// miner's reward
val correctCoinsIssued = EQ(reemissionRewardPerBlock, Minus(ExtractAmount(Self), ExtractAmount(reemissionOut)))

// when reemission contract box got merged with other boxes
val merging = AND(
GT(ExtractAmount(reemissionOut), ExtractAmount(Self)),
LE(ExtractAmount(ByIndex(Outputs, IntConstant(1))), LongConstant(10000000)), // 0.01 ERG
EQ(SizeOf(Outputs), 2)
)

AND(
correctNftId,
sameScriptRule,
OR(
merging,
AND(
heightCorrect,
correctMinerOutput,
afterEmission,
heightIncreased,
correctCoinsIssued
scalahub marked this conversation as resolved.
Show resolved Hide resolved
)
)
)
```

**Pay-to-Reemission contract**: Ensures that a box protected with the contract can only be spent by the re-emission contract.

```scala
val reemissionOut = ByIndex(Outputs, IntConstant(0))

val rOutTokens = OptionGet(ExtractRegisterAs(reemissionOut, R2)(SCollection(STuple(SCollection(SByte), SLong))))

val firstTokenId = SelectField(ByIndex(rOutTokens, IntConstant(0)), 0.toByte)

EQ(firstTokenId, ByteArrayConstant(reemissionNftId))
```

Voting for the Soft-Fork
------------------------

A solo miner or a pool needs to add the following to their configuration file to vote for the soft-fork on the mainnet (similar to the testnet voting already performed).

```conf
ergo {
voting {
8 = 1000
}
}
```

EIP-27 is 'locked in' when a voting epoch with at least 888 out of 1024 blocks indicates they support the proposal by their vote for increasing parameter #8, which holds transaction output cost. It will then be activated at the given activation height.

Activation Details
------------------

On emission height, emission NFT and re-emission tokens are injected into the emission contract by spending the **injection box**.

The following script protects the injection box.

```
{
INPUTS(0).value > 30000000L * 1000000000L &&
SELF.id == INPUTS(1).id
}
```

This is spendable by providing 30M ERG in the first input (Only the emission box has this amount of ERG).

API Methods Changed
-------------------

* `/emission/at`
* `/emission/scripts`
* `/wallet/balances`
* `/wallet/balances/withUnconfirmed`

Wallet Support
--------------
So that the wallet can account for the presence of the re-emission tokens and make payments correctly, the following flag must be set:

```conf
ergo {
wallet {
checkEIP27 = true
}
}
```

This flag is `false` by default for the sake of performance.

Node Settings
-------------

* It is mandatory for mining nodes to check EIP-27 rules, for that, use the following setting
```conf
ergo {
chain {
reemission {
checkReemissionRules = true
}
}
}
```

This option is off by default (so `= false`) in the mainnet for performance's sake. However, starting from version 4.0.31,
the node is not starting if `mining = true` and `checkReemissionRules = false`

* If a node wallet may have re-emission tokens (i.e. the node is mining or has the same wallet secret as a
mining node to do payouts), the following setting is needed to handle re-emission tokens (and pay to
pay-to-reemission contract) properly:
```conf
ergo {
wallet {
checkEIP27 = true
}
}
```

This option is off by default (so `= false`) for performance's sake.

Testnet Data
------------

Emission contract NFT id: `00594148f3b4205ec8d33f9f664b1baae20252df3592c8dbff5e9bdc30c77c44`

Re-emission token id: `004b1528123ef62ce2bbb7036ad2dd553e6a64252f86746a706729fa253b24cd`

Reemission contract NFT id: `001b81ceed43f4328754e368fc6a34c367ab8e00d1272be33c565bf247ad5748`

Activation height: `188001`

Re-emission start height: `186400`


Mainnet Data
------------

- Emission contract NFT id: `20fa2bf23962cdf51b07722d6237c0c7b8a44f78856c0f7ec308dc1ef1a92a51`
- Issued in tx #[a1cbc9e14999cc7620c9d952cb06f5f6a70a2c39bb7d3c8ff5311f825eca244c](https://explorer.ergoplatform.com/en/transactions/a1cbc9e14999cc7620c9d952cb06f5f6a70a2c39bb7d3c8ff5311f825eca244c)
- Block 738,624

- Re-emission token id: `d9a2cc8a09abfaed87afacfbb7daee79a6b26f10c6613fc13d3f3953e5521d1a`
- Issued in tx # [ff340e380559a5a1ba870f27367a50a1829a4a573e1a738ec764456ec47620e3](https://explorer.ergoplatform.com/en/transactions/ff340e380559a5a1ba870f27367a50a1829a4a573e1a738ec764456ec47620e3)
- block 738,694

- Reemission contract NFT id: `d3feeffa87f2df63a7a15b4905e618ae3ce4c69a7975f171bd314d0b877927b8`
- Issued in tx #[f06762711a3f33d3a479962e730a742f640105c6c5bb4e0a3e5a9405de700b4c](https://explorer.ergoplatform.com/en/transactions/f06762711a3f33d3a479962e730a742f640105c6c5bb4e0a3e5a9405de700b4c)
- block 738,628)

Activation height: `777,217`


- Injection box P2S address is `9puEV3pP1bNdFi17ScAWzHqGaZPAopM15fFz2FiotY1zdd1XBT9Kba`
- created in tx # [fca71b8b95f6ad14ce600a126c8842334d40d35f8754176c4cda2c95219f19f7](https://explorer.ergoplatform.com/en/transactions/fca71b8b95f6ad14ce600a126c8842334d40d35f8754176c4cda2c95219f19f7)
- output `997369af025fa60dab11d11f94bd5492dbb8731ea3a31154a0388e329f7edf4a`

use `utxo/byIdBinary/997369af025fa60dab11d11f94bd5492dbb8731ea3a31154a0388e329f7edf4a` request in node API to get injection box bytes:

```conf
{
"boxId": "997369af025fa60dab11d11f94bd5492dbb8731ea3a31154a0388e329f7edf4a",
"bytes": "80a8d6b9071003040005808098f4e9b5ca6a0402d1ed91c1b2a4730000730193c5a7c5b2a47302008f9e2d0220fa2bf23962cdf51b07722d6237c0c7b8a44f78856c0f7ec308dc1ef1a92a5101d9a2cc8a09abfaed87afacfbb7daee79a6b26f10c6613fc13d3f3953e5521d1a808088fccdbcc32300fca71b8b95f6ad14ce600a126c8842334d40d35f8754176c4cda2c95219f19f700"
}
```

- Re-emission contract box with reemission contract NFT created in tx # [70fc909f363294aa3f8863a8de4d87462e5f843f458292fd2267fbcef3073971](https://explorer.ergoplatform.com/en/transactions/70fc909f363294aa3f8863a8de4d87462e5f843f458292fd2267fbcef3073971)


References
----------

1. [Carlsten, Miles, et al. **"On the instability of bitcoin without the block reward."** Proceedings of the 2016 ACM SIGSAC Conference on Computer and Communications Security. 2016.](https://www.cs.princeton.edu/~arvindn/publications/mining_CCS.pdf)
2. [Ergo Emission: **details, retargeting via a soft-fork.**](https://www.ergoforum.org/t/ergo-emission-details-retargeting-via-a-soft-fork/2778)
3. [Emission Soft-Fork Proposal.](https://www.ergoforum.org/t/emission-soft-fork-proposal/2996/27)
4. [Zindros, Dionysis. **"Soft Power: Upgrading Chain Macroeconomic Policy Through Soft Forks."** International Conference on Financial Cryptography and Data Security. 2021.](https://eprint.iacr.org/2021/577.pdf)