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

Use safe math when calculating pool tx values #6897

Closed
mattsse opened this issue Feb 29, 2024 · 1 comment · Fixed by #6900
Closed

Use safe math when calculating pool tx values #6897

mattsse opened this issue Feb 29, 2024 · 1 comment · Fixed by #6900
Assignees
Labels
A-tx-pool Related to the transaction mempool C-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started

Comments

@mattsse
Copy link
Collaborator

mattsse commented Feb 29, 2024

Describe the feature

This is applied on unvalidated txs:

let gas_cost = match &transaction.transaction {
Transaction::Legacy(t) => U256::from(t.gas_price) * U256::from(t.gas_limit),
Transaction::Eip2930(t) => U256::from(t.gas_price) * U256::from(t.gas_limit),
Transaction::Eip1559(t) => U256::from(t.max_fee_per_gas) * U256::from(t.gas_limit),
Transaction::Eip4844(t) => {
blob_sidecar = EthBlobTransactionSidecar::Missing;
U256::from(t.max_fee_per_gas) * U256::from(t.gas_limit)
}
#[cfg(feature = "optimism")]
Transaction::Deposit(_) => U256::ZERO,
};
let mut cost: U256 = transaction.value();
cost += gas_cost;
if let Some(blob_tx) = transaction.as_eip4844() {
// add max blob cost
cost += U256::from(blob_tx.max_fee_per_blob_gas * blob_tx.blob_gas() as u128);
}

even though invalid transactions will get rejected

these ops can overflow

TODO

use saturating math when calculating cost

saturating is fine because U256::MAX as cost will result in a rejected tx

Additional context

No response

@mattsse mattsse added C-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started A-tx-pool Related to the transaction mempool labels Feb 29, 2024
@justcode740
Copy link
Contributor

will take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tx-pool Related to the transaction mempool C-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants