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

feat(tests): Add blob gas subtraction order tests #407

Merged
merged 4 commits into from
Jan 29, 2024

Conversation

spencer-tb
Copy link
Collaborator

@spencer-tb spencer-tb commented Jan 28, 2024

🗒️ Description

Adds parameterized tests to ensure that the blob gas fee is subtracted from the sender's balance before a blob transaction is executed. Includes the case where the sender recieves funds before the blob tx is executed.

🔗 Related Issues

As requested by @marioevz: #385

✅ Checklist

  • All: Set appropriate labels for the changes.
  • All: Considered squashing commits to improve commit history.
  • All: Added an entry to CHANGELOG.md.
  • All: Considered updating the online docs in the ./docs/ directory.
  • Tests: Included the type and version of evm t8n tool used to locally execute test cases: e.g., ref with commit hash or geth 1.13.1-stable-3f40e65.
  • Tests: Ran mkdocs serve locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.

@spencer-tb spencer-tb added scope:tests Scope: Test cases type:feat type: Feature labels Jan 28, 2024
@spencer-tb spencer-tb force-pushed the feat/extra-4844-type-3-tx-tests branch from 464b83a to 04e4b29 Compare January 28, 2024 12:24
@spencer-tb
Copy link
Collaborator Author

spencer-tb commented Jan 28, 2024

I initially tried to verify the balance values stored within the post state of the destination_account.

This was easy without the additional parameterization of the max_fee_per... fields.
You can find the following revision here: spencer-tb@4be8852
Within this the entire total account minimum fee, required to execute the tx was removed (incl. the blob gas fee) before executing the tx and contract code.

However when it came to using the max_fee_per... fields, I maybe spent a day trying to figure out the correct formula for the balance subtraction, as the amount subtracted is less than the value for the total account minimum fee.

Would you like me continue and add a check for the balance? Similarly sstore the return value of the call to send funds?

@marioevz
Copy link
Member

I initially tried to verify the balance values stored within the post state of the destination_account.

This was easy without the additional parameterization of the max_fee_per... fields. You can find the following revision here: spencer-tb@4be8852 Within this the entire total account minimum fee, required to execute the tx was removed (incl. the blob gas fee) before executing the tx and contract code.

However when it came to using the max_fee_per... fields, I maybe spent a day trying to figure out the correct formula for the balance subtraction, as the amount subtracted is less than the value for the total account minimum fee.

Would you like me continue and add a check for the balance? Similarly sstore the return value of the call to send funds?

So if we try to check the stored balance, the balance should be zero only for cases where
a) tx.max_fee_per_gas == block.base_fee_per_gas
b) tx.max_fee_per_blob_gas == block.blob_base_fee_per_gas

both (a) and (b) are true, because if you check the validation steps in 1559 (which are very similar to 4844) https://eips.ethereum.org/EIPS/eip-1559, the formula for the minimum balance for the transaction to be intrinsically valid takes tx.max_fee_per_gas and tx.max_fee_per_blob_gas into account, whereas the actual balance subtraction, which happens right before the transaction execution, uses block.base_fee_per_gas and block.blob_base_fee_per_gas respectively.

So this is why we fund the account with the maximum amount it would have to pay in any block, because otherwise the transaction is invalid.

Copy link
Member

@marioevz marioevz left a comment

Choose a reason for hiding this comment

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

Looks really good, just a few comments.

tests/cancun/eip4844_blobs/test_blob_txs.py Outdated Show resolved Hide resolved
tests/cancun/eip4844_blobs/test_blob_txs.py Outdated Show resolved Hide resolved
tests/cancun/eip4844_blobs/test_blob_txs.py Outdated Show resolved Hide resolved
@marioevz
Copy link
Member

To calculate the actual balance we can use a similar approach to function total_account_minimum_balance, but instead of calculating using tx_max_fee_per_blob_gas and tx_max_fee_per_gas, we use the actual blob base fee and normal base fee of the block (functions blob_gasprice and block_fee_per_gas pytest fixtures), and we subtract that from the minimum account balance.

@spencer-tb spencer-tb force-pushed the feat/extra-4844-type-3-tx-tests branch from ddee4dc to f226e54 Compare January 29, 2024 08:33
@spencer-tb
Copy link
Collaborator Author

We now have the total_account_transactions_fee fixture within: b49c5b0 alongside the updates to the tests for the post state balance checks. Some small naming tweaks were made to the total_account_minimum_balance fixture.

Within: f226e54 I removed a duplicate fixture.

I am just working on adding the max_priority_fee_per_gas parameterization to the calculation.

@spencer-tb
Copy link
Collaborator Author

We should be a go now!

Copy link
Member

@marioevz marioevz left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks!

@marioevz marioevz merged commit 37ceb8b into ethereum:main Jan 29, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope:tests Scope: Test cases type:feat type: Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants