Skip to content

Latest commit

 

History

History
292 lines (203 loc) · 13.1 KB

eip-0027.md

File metadata and controls

292 lines (203 loc) · 13.1 KB

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]

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] and [3]) to prolong emission (while preserving the total supply) via a soft-fork(4). 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)

    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))
    
    // output to pay miner
    val minerOut = ByIndex(Outputs, IntConstant(1))
    
    // 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
          )
        )
    )

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

    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).

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:

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
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:
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

Activation height: 777,217

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

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

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.
  2. Ergo Emission: details, retargeting via a soft-fork.
  3. Emission Soft-Fork Proposal.
  4. Zindros, Dionysis. "Soft Power: Upgrading Chain Macroeconomic Policy Through Soft Forks." International Conference on Financial Cryptography and Data Security. 2021.