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

No base-fee conversion in effective-gas-tip related methods #297

Open
ezdac opened this issue Dec 11, 2024 · 0 comments
Open

No base-fee conversion in effective-gas-tip related methods #297

ezdac opened this issue Dec 11, 2024 · 0 comments
Labels
type:bug Something isn't working

Comments

@ezdac
Copy link

ezdac commented Dec 11, 2024

Issue

We seem to have forgotten a lot of fee-currency conversions in EffectiveGasTip based calculations for fee-currency denominated transactions.

For most of the affected code, the tx.EffectiveGasTip(), tx.EffectiveGasTipCmp(),tx.EffectiveGasTipValue() methods are called to do some calculation (e.g. moving average) without considering wether the transaction is denominated in Celo or fee-currency.

tx.EffectiveGasTip()

A lot of calls to the tx.EffectiveGasTip() are affected, which are used e.g. here:

minerFee, _ := tx.EffectiveGasTip(block.BaseFee())

tip, err := tx.EffectiveGasTip(header.BaseFee)

func (oracle *Oracle) getBlockValues(ctx context.Context, blockNum uint64, limit int, ignoreUnder *big.Int, result chan results, quit chan struct{}) {

tx.EffectiveGasTipValue()

There is one usage of this method which is affected:

for i := range txs {
tips[i] = txs[i].EffectiveGasTipValue(baseFee)
}

tx.EffectiveGasTipCmp()

The entire function tx.EffectiveGasTipCmp() is compromised, whenever fee-currency and native transactions are compared:

func (tx *Transaction) EffectiveGasTipCmp(other *Transaction, baseFee *big.Int) int {
if baseFee == nil {
return tx.GasTipCapCmp(other)
}
return tx.EffectiveGasTipValue(baseFee).Cmp(other.EffectiveGasTipValue(baseFee))
}

This function however does not seem (yet) to be used in the op-geth codebase.

Severity

So far there seems to be no usage of those methods in EVM / state-transition related code, and the externally exposed affected surface consists of mostly convenience methods:

  • FeeHistory will return incorrect gas price history
  • SuggestGasTipCap will return incorrect gas-tip suggestions

op-geth/eth/api_backend.go

Lines 390 to 396 in a59c67f

func (b *EthAPIBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
return b.gpo.SuggestTipCap(ctx)
}
func (b *EthAPIBackend) FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (firstBlock *big.Int, reward [][]*big.Int, baseFee []*big.Int, gasUsedRatio []float64, baseFeePerBlobGas []*big.Int, blobGasUsedRatio []float64, err error) {
return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
}

Solution

For all calls to the aforementioned effective-gas-tip related methods, the passed in base-fee has to first be converted
to the transactions fee-currency when that transaction is a CIP-64 transaction.
When methods accumulate values between CIP-64 and Ethereum transactions, the accumulation has to be done in the same denomination.

@ezdac ezdac added the type:bug Something isn't working label Dec 11, 2024
@ezdac ezdac added this to the 5 - Celo MVP Mainnet milestone Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant