RSKIP-139: Precompile to get transaction refunds

Abstract

RIF Enveloping, the Flyover protocol and The GasStation Network (GSN) require a first contract to bill a user for the gas consumed by a a call to a second contract. The first contract can learn how much has the second contract consumed by calling GAS opcode before and after the second contract has executed, and subtracting them. However, the first contract cannot learn how much gas the second contract execution has refunded. If it were known, the refunded gas could be deducted from the bill. Currently the second contract is overpaying gas. This RSKIP proposes the creation of a new native contract and method that returns the accumulated refund.

You can read the RSKIP139 here.

There is a bounty for implementing this RSKIP → RSKj Precompile to get transaction refunds · Issue #8 · rsksmart/rsk-gitcoin-hackathon-2021 · GitHub

EIP-3298 proposes getting rid of gas refunds completely. Could that be a good idea in RSK as well?

That RSKIP proposes removing STORAGE gas refunds, which I fully agree are problematic (and it was known to be problematic even before the launch of Ethereum).

There is nothing wrong with gas refunds, as long as the refund is taken from the gas consumed in the same transaction. For example, RSKIP209 uses gas refunds, and this solution doesn’t have any known drawback