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

Delete empty account at BEACON_ROOTS_ADDRESS #871

Closed

Conversation

gurukamath
Copy link
Collaborator

What was wrong?

The current implementation of EIP-4788 did not delete the account at BEACON_ROOTS_ADDRESS if it is empty after being touched by the system message call. For example, in a case where the contract has not been deployed yet. EIP-4788 does not explicitly mention this deletion but it is implied post EIP-161

How was it fixed?

Delete the account at BEACON_ROOTS_ADDRESS if it is empty.

@gurukamath gurukamath changed the base branch from master to forks/cancun January 30, 2024 06:36
@codecov-commenter
Copy link

Codecov Report

Attention: 2112 lines in your changes are missing coverage. Please review.

Comparison is base (bf47143) 69.96% compared to head (4938522) 69.83%.
Report is 25 commits behind head on forks/cancun.

Files Patch % Lines
src/ethereum/cancun/fork.py 0.00% 236 Missing ⚠️
src/ethereum/cancun/vm/instructions/system.py 0.00% 207 Missing ⚠️
src/ethereum/cancun/vm/instructions/__init__.py 0.00% 162 Missing ⚠️
src/ethereum/cancun/vm/instructions/environment.py 0.00% 153 Missing ⚠️
src/ethereum/cancun/state.py 0.00% 149 Missing ⚠️
src/ethereum/cancun/vm/interpreter.py 0.00% 112 Missing ⚠️
src/ethereum/cancun/vm/instructions/arithmetic.py 0.00% 109 Missing ⚠️
src/ethereum/cancun/vm/instructions/stack.py 0.00% 98 Missing ⚠️
src/ethereum/cancun/vm/gas.py 0.00% 97 Missing ⚠️
src/ethereum/cancun/vm/__init__.py 0.00% 77 Missing ⚠️
... and 35 more
Additional details and impacted files
@@               Coverage Diff                @@
##           forks/cancun     #871      +/-   ##
================================================
- Coverage         69.96%   69.83%   -0.13%     
================================================
  Files               610      610              
  Lines             34295    34773     +478     
================================================
+ Hits              23993    24283     +290     
- Misses            10302    10490     +188     
Flag Coverage Δ
unittests 69.83% <12.69%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

EIP-4788 does not explicitly mention that the BEACON_ROOTS_ADDRESS if empty, should be deleted. However, it is implied in post EIP-161 networks
Comment on lines +535 to +536
if account_exists_and_is_empty(state, BEACON_ROOTS_ADDRESS):
destroy_account(state, BEACON_ROOTS_ADDRESS)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, is it necessary to check again after running destroy_touched_empty_accounts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh. This is an error. Will update.

@petertdavies
Copy link
Contributor

The question of whether BEACON_ROOTS_ADDRESS gets cleared is verifiably moot, because the account is not empty and cannot become empty. My recollection is that it was decided to remove the test from execution-spec-tests, rather than force everyone to implement this. If that's the case I don't see why we should be added code to the specs.

@gurukamath
Copy link
Collaborator Author

The question of whether BEACON_ROOTS_ADDRESS gets cleared is verifiably moot, because the account is not empty and cannot become empty. My recollection is that it was decided to remove the test from execution-spec-tests, rather than force everyone to implement this. If that's the case I don't see why we should be added code to the specs.

The way the ethereum/tests for cancun are currently filled, this account can end up being touched and empty. Will check with the team. @marioevz Any comments on this?

@marioevz
Copy link
Member

marioevz commented Feb 6, 2024

Execution spec tests fix: ethereum/execution-spec-tests#425

Still looking into ethereum/tests.

Copy link
Member

@chfast chfast left a comment

Choose a reason for hiding this comment

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

This is by design unspecified because this cannot happen in practice.

@gurukamath
Copy link
Collaborator Author

Opened issue for this to be fixed in the ethereum/tests repo

@gurukamath gurukamath closed this Feb 15, 2024
@chfast
Copy link
Member

chfast commented Feb 21, 2024

EIP-7523 fixes this because then the BEACON_ROOTS_ADDRESS cannot be empty in the pre-state.

@winsvega
Copy link
Contributor

winsvega commented Feb 21, 2024

but can it be non existent?
and if it is non existent then if no code exists at BEACON_ROOTS_ADDRESS, the call must fail silently
meanin the current ethereum/tests are correct

@chfast
Copy link
Member

chfast commented Feb 21, 2024

Exactly. Most of the tests don't have the BEACON_ROOTS_ADDRESS code in the state and they work fine. The system call works as a call to a non-existent account.

@winsvega
Copy link
Contributor

winsvega commented Feb 21, 2024

but then there is this option which is also legal - to just write storages without a silent call. it creates double reading.
because writing storages directly is not a call so it does not fail.

I think it would be better if:

if there is no contract in the state. deploy contract to the state. make silent call / write storages
if contrac alsready in the state verify it has nonce = 1, code = CODE

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.

7 participants