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

LFM Phase-1 #30

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

LFM Phase-1 #30

wants to merge 11 commits into from

Conversation

giladHaimov
Copy link

@giladHaimov giladHaimov commented Jun 12, 2024

Local-Fee Market phase1: Native-token discount

Design-doc

Target

Provide gas-price discount for native-token transfer txs. his discount will only be applied for EOA targeted transfer so to avoid discounting potentially complex receive() logic at the destination contract.

The statistical calculation of the discount is provided at locaFeeMarket.AdjustGasPrice and relies on the historical mean and standard-deviation Core values calculated over the last year.

Interleaving into main tx flow

In order to do this two major problems needed to be addressed after the discount has been introduced into the tx:

  1. tx validation logic failing with an 'underpriced' error
  2. the recovery of the orig tx signer failed due to the (orig) gasPrice being interleaved in the R, S, V, signer calculation

To handle both these issues the original gas price needed to be accessible and these points of the calculation so to avoid these problems. Since this price is determined per-tx, a new field - OrigGasPrice - has been added to the internal transaction struct and is initialized right before discount introduction for future processing.
It should be noted that this field is geth-internal and is not visible to users via the tx receipt or any other mean.

Account-Abstraction support

Since this feature was designed to only work between EOAs and since ERC-4337 always relies on smart-contract logic rather than private-key, no discount will be provided for AA accounts. While I could thinks of ways around this limitation, mostly involving creating some sort of detection-mechanism for paymasters, these will involve an amount of complexion we're currently better off without.

Valid native-transfer detection

The following conditions are used to detect a native-transfer tx which is applicable for discount:

  1. Data size = 0 so to omit transfer commands issued from a smart contract
  2. Value > 0 so not to deal with non-transfer txs
  3. Gas units = 21k so to omit transfer txs aimed to a non-EOA (i.e. a smart contract)

It should be noted that condition #3 also allows us to omit txs issued from a contract's constructor, where data size is still zero due to the contract not yet being deployed.

Limitations

  1. (by design) Only applicable to EOA target so not to discount potentially costly contract logic
  2. (by design) Applicable only for EOA i.e. transferring Core to a smart-contract - even if it's receive() logic is empty - will still be under old prices
  3. (by design) Discounts will not be applied for 'internal txs' where a smart contract issues a transfer command as part of its internal logic
  4. Discount will only be provided if the transaction data field is empty
  5. Not applicable to txs issued directly from a node terminal: since the vast majority of the txs are sent via RPC, we decided to apply the Pareto principle here
  6. Burning addresses (0x00, 0xDEAD etc.) were not ruled out and will be discounted as well. Again Pareto principle.

Executed tests

  1. send native tx to EOA via RPC to the miner node ==> discount
  2. send native tx to EOA via RPC to a non-miner node ==> discount
  3. send native tx to contract destination via RPC to a miner node
  4. send native tx to contract destination via RPC to a non-miner node
  5. send a contract function internally containing a non-bounded native transfer call to an EOA to a non-miner node
  6. send a contract function internally containing a non-bounded native transfer call to an EOA to a miner node
  7. send a contract function internally containing a native transfer call bounded to 21k gas units to an EOA to a miner node
  8. send a contract function internally containing a native transfer call bounded to 21k gas units to an EOA to a non-miner node

Only (1) and (2) have resulted in a discount, as should be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant