Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

fix: contract address in contract creation receipt is wrong #851

Merged
merged 2 commits into from
Dec 28, 2021

Conversation

yihuang
Copy link
Contributor

@yihuang yihuang commented Dec 21, 2021

Closes: #850

Description

  • reset sender.nonce before evm.create
  • add unit tests and rpc tests

How the nonce is changed:

Ante handler:
  check(tx.nonce == sender.nonce)
  sender.nonce += 1
ApplyMessage:
  if contract_creation {
    sender.nonce = tx.nonce
    err := evm.create(...)
    sender.nonce = tx.nonce + 1
  } else {
    evm.call(...)
  }

Two contraints for the design:

  • sender's nonce should be increased even if ApplyMessage fails.
  • sender.nonce should be equal to tx.nonce when calling evm.create, so the contract address will be correct.

For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@yihuang yihuang changed the title Problem: contract address in contract creation receipt is wrong fix: contract address in contract creation receipt is wrong Dec 21, 2021
@codecov
Copy link

codecov bot commented Dec 21, 2021

Codecov Report

Merging #851 (2092388) into main (8bc3cc4) will decrease coverage by 0.02%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #851      +/-   ##
==========================================
- Coverage   56.79%   56.77%   -0.03%     
==========================================
  Files          72       72              
  Lines        6060     6066       +6     
==========================================
+ Hits         3442     3444       +2     
- Misses       2420     2424       +4     
  Partials      198      198              
Impacted Files Coverage Δ
x/evm/types/tx_args.go 0.00% <0.00%> (ø)
x/evm/keeper/state_transition.go 77.49% <100.00%> (+0.14%) ⬆️

x/evm/keeper/grpc_query.go Outdated Show resolved Hide resolved
x/evm/keeper/grpc_query.go Outdated Show resolved Hide resolved
x/evm/keeper/state_transition.go Outdated Show resolved Hide resolved
x/evm/keeper/state_transition.go Outdated Show resolved Hide resolved
x/evm/keeper/grpc_query.go Outdated Show resolved Hide resolved
x/evm/keeper/grpc_query.go Outdated Show resolved Hide resolved
tests/rpc/rpc_test.go Outdated Show resolved Hide resolved
@yihuang yihuang force-pushed the fix-contract-creation branch 4 times, most recently from e49d221 to f99d6f2 Compare December 22, 2021 17:16
Closes: evmos#850
- decrease nonce before evm.create
- add unit tests and rpc tests
@fedekunze
Copy link
Contributor

@yihuang can you add a Changelog entry for this fix?

@fedekunze fedekunze merged commit d822fee into evmos:main Dec 28, 2021
@yihuang yihuang deleted the fix-contract-creation branch December 28, 2021 08:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem: contract address in contract creation receipt is wrong
2 participants