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

[evm] implement EIP-6780 SELFDESTRUCT only in same transaction #4218

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dustinxie
Copy link
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes #(issue)

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • [] Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [] make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

Copy link

codecov bot commented Apr 2, 2024

Codecov Report

Attention: Patch coverage is 36.20690% with 37 lines in your changes missing coverage. Please review.

Project coverage is 76.69%. Comparing base (d716bb9) to head (24e6bd2).
Report is 55 commits behind head on master.

Current head 24e6bd2 differs from pull request most recent head 411da31

Please upload reports for the commit 411da31 to get more accurate results.

Files Patch % Lines
action/protocol/execution/evm/evmstatedbadapter.go 30.00% 30 Missing and 5 partials ⚠️
action/protocol/execution/evm/evm.go 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4218      +/-   ##
==========================================
+ Coverage   76.51%   76.69%   +0.18%     
==========================================
  Files         340      340              
  Lines       29273    29303      +30     
==========================================
+ Hits        22397    22475      +78     
+ Misses       5761     5719      -42     
+ Partials     1115     1109       -6     

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

Copy link

sonarcloud bot commented Apr 10, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
8.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

Copy link

sonarcloud bot commented Jun 4, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
8.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@@ -286,7 +307,7 @@ func (stateDB *StateDBAdapter) AddBalance(evmAddr common.Address, a256 *uint256.
if contract, ok := stateDB.cachedContract[addrHash]; ok {
state = contract.SelfState()
} else {
state, err = accountutil.LoadOrCreateAccount(stateDB.sm, addr, stateDB.accountCreationOpts()...)
state, _, err = accountutil.LoadOrCreateAccount(stateDB.sm, addr, stateDB.accountCreationOpts()...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

if contract address could be calculated, is it possible that AddBalance function is called and create the account before the cooresponding contract is created? if so, should this contract address be considered as "created in the same transaction"?

Copy link
Member Author

Choose a reason for hiding this comment

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

checked ethereum code, it does not detect collision and will overwrite the existing account

// CreateAccount explicitly creates a new state object, assuming that the
// account did not previously exist in the state. If the account already
// exists, this function will silently overwrite it which might lead to a
// consensus bug eventually.
func (s *StateDB) CreateAccount(addr common.Address) {
	s.createObject(addr)
}

our code will check and only create a new account if it does not exist yet. In this aspect, we are different from ethereum (and maybe better since we don't overwrite?)

Copy link

sonarcloud bot commented Oct 2, 2024

_, err = accountutil.LoadOrCreateAccount(stateDB.sm, addr, stateDB.accountCreationOpts()...)
if stateDB.assertError(err, "Failed to create account.", zap.Error(err), zap.String("address", evmAddr.Hex())) {
return
}
Copy link
Member Author

@dustinxie dustinxie Oct 2, 2024

Choose a reason for hiding this comment

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

if the address already exist in cache, no need to create it
this is same as Ethereum's code behavior

Copy link
Collaborator

Choose a reason for hiding this comment

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

unit test doesn't cover this case

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.

4 participants