Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

ECIP-1042: GASPAY #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions ECIPs/ECIP-1042.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
ECIP: 1042
Title: GASPAY opcode
Author: Igor Artamonov <[email protected]>
Status: Draft
Type: Standard
Created: 2018-03-08

# ECIP-1042 - GASPAY opcode

# Abstract
Add an operation to consume gas and add amount paid for that gas to token balance.

# Motivation
A useful Smart Contract (i.e. valuable) should expect small reward for its execution. A micropayment could be very
small a sub-cent payment but sending an additional value to a contract will make it more complicated and cost of such
transfer or contract execution could exceed requested reward.

It’s proposed here to introduce a new EVM Operation that will allow a developer to consume a portion of transaction fee
(amount paid for a gas) and transfer it to current Smart Contract.

Using a gas payment provided with transaction provides flexibility and independence from market price of Ether. Gas Price
is dynamic value and supposed to represent fair market price of contract execution, therefore making micropayment value
proportional to const of transaction and more stable in long term.

# Specification
Provide a new operation `GASPAY a` where `a` is amount of gas to consume, and `0x0 <= a <= 0x0fffff`. The payment for
that gas goes to contract address. As a return it puts consumed value (Wei) into the stack.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we be more specific on this.

  1. If a DELEGATECALL happened, does the payment goes to the parent contract (which has the address field set in context), or the delegated contract?
  2. What is the case if we're in CREATE or a contract creation transaction?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. to delegated contract
  2. not sure what you mean


The cost of the operation itself is equal to 1/4 of requested amount of Gas plus 5000 (`a/4 + 5000`). The payment for
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this extra "gas" to contract paid a) at the end of the contract execution (like how miner gas works), or b) paid immediately at the GASPAY opcode? If it is a), does it do anything with refunded gas as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean should it be paid if transaction has failed? no, only if succeeded. but "payment" should be registered at the moment of opcode

that gas is going to miner address, and supposed to compensate potential miner loss from including in a block
transaction that doesn’t give all gas fee as a reward to a miner.

```
Op code value: 0x3d
Mnemonic: GASPAY
δ: 1
α: 1
```

With the current average price of 23000 MWei per Gas, a smart contract can earn up to $1 per operation, by
requesting payment for 1,048,575 of Gas.

# Risks consideration

## Miners don’t receive payment for all gas in a block
Currently miners expect that all payment for the gas goes to coinbase. After introducing this operation part of this
payment could go to smart contracts participated in block transactions. This plays a role only when we have blocks fully
packed with transaction, up to the block gas limit, which is a dynamic value and can be controlled by miners.

Because cost of the execution of that operation is a constant and roughly is about 5000 of Gas, then requested cost of
execution as `a/4 + 5000` will be as much as profitable as including other transactions with same gas limit. With that
cost it’s expected that a miner could earn 10%-20% of a requested amount, in addition to cost of actual work spent on
execution of that transaction. If gas prices per opcodes are fair, then a miner could be in favour of adding a
transaction with GASPAY opcode as it provides slightly more profit to a miner too.

## Software must distinguish payment went to contract and to miner
Most of the current 3rd party software expect that whole payment for a gas will go to a miner of the block. It includes
dev tools, block explorers and nodes (protocol implementations).

After introducing this new opcode, all this software must be updated according to a new way of gas payment calculation.

## Smart Contract language compilers
Solidity and other smart contract language compilers will need to be updated to support additional opcode