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

EIP1559 strict balance validation #857

Conversation

notlesh
Copy link
Contributor

@notlesh notlesh commented Sep 15, 2022

This PR clears up the accounting and validation related to max_fee_per_gas and base_fee in order to match the EIP1559 spec.

Essentially this PR swaps the checks done by validation and during execution.

Before:

  • validation checked sender's balance against base_fee (plus applicable tip)
  • execution deducted initial fee based on max_fee_per_gas

After this PR:

  • validation checks sender's balance against max_fee_per_gas
  • execution deducts initial fee based on base_fee (plus applicable tip)

TODO:

  • One thing I would like to be sure of is that a txn with max_fee_per_gas < base_fee can't be included -- should execute() check this or should it assume that this is properly checked during validation?
  • Additional tests?
  • Other TODOs in code comments

@notlesh notlesh requested a review from sorpaas as a code owner September 15, 2022 15:55
Comment on lines 123 to 127
// TODO: after simplifying the logic here, we no longer care about the specified priority
// fee except for calculating the total fee paid.
// When paying out the priority fee, we let correct_and_deposit_fee() come up with an
// arbitrary value that is used as the tip to pay.
// Assuming this is ok, actual_priority_fee_per_gas does not need to be returned above.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see three possibilities:

  1. do nothing (remove actual_priority_fee_per_gas and this comment)
  2. don't let correct_and_deposit_fee() return (or even know about...?) priority fee
  3. leave it as is but use actual_priority_fee_per_gas for sanity checks

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 or 3 would be appropriate for this PR, 2 would make sense as a follow-up.

Copy link
Member

Choose a reason for hiding this comment

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

I'd slightly prefer option 3. This is only executed once per transaction so the performance impact is minimum.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After another review, this was really always the case. Previously, we only calculated priority fee as an incremental step to get to total fee, and that's no longer necessary in this PR.

It's correct_and_deposit_fee() which is responsible for coming up with the tip to be paid.

We could add a sanity check that correct_and_deposit_fee() returns something equal to (...or less than?) the correct priority_fee, but that would require additional trait bounds for LiquidityInfo to at least compare it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with 1 for now. If 3 is worth the extra trait bounds in your opinion, I'm happy to do it.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that's okay. Please resolve the conflicts.

@notlesh
Copy link
Contributor Author

notlesh commented Oct 5, 2022

@sorpaas Conflicts resolved 👍

@sorpaas sorpaas merged commit e3ee95a into polkadot-evm:master Oct 6, 2022
notlesh added a commit to moonbeam-foundation/frontier that referenced this pull request Oct 6, 2022
* Change test assumptions

* Validate account balance against max_fee_per_gas

* Deduct base_fee + tip rather than max_fee_per_gas

* fmt

* Leave actual_priority_fee_per_gas unused

* Remove TODO comment
abhijeetbhagat pushed a commit to web3labs/frontier that referenced this pull request Jan 11, 2023
* Change test assumptions

* Validate account balance against max_fee_per_gas

* Deduct base_fee + tip rather than max_fee_per_gas

* fmt

* Leave actual_priority_fee_per_gas unused

* Remove TODO comment
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.

2 participants