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

state: Refactor compute_new_account_address() #575

Merged
merged 2 commits into from
Feb 27, 2023
Merged

Conversation

chfast
Copy link
Member

@chfast chfast commented Feb 27, 2023

Refactor compute_new_account_address() to match 𝐀𝐃𝐃𝐑 from Yellow Paper.
This makes it a separate utility independent of evmc_message.

@chfast chfast force-pushed the new_account_address branch from a9f62c4 to 01a1671 Compare February 27, 2023 12:09
Refactor `compute_new_account_address()` to match Yellow Paper 𝐀𝐃𝐃𝐑.
This makes it a separate utility independent of `evmc_message`.
@chfast chfast force-pushed the new_account_address branch from 01a1671 to bd35f8f Compare February 27, 2023 12:10
@codecov
Copy link

codecov bot commented Feb 27, 2023

Codecov Report

Merging #575 (bd35f8f) into master (bce22af) will increase coverage by 0.07%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #575      +/-   ##
==========================================
+ Coverage   97.06%   97.13%   +0.07%     
==========================================
  Files          71       72       +1     
  Lines        6545     6571      +26     
==========================================
+ Hits         6353     6383      +30     
+ Misses        192      188       -4     
Flag Coverage Δ
blockchaintests 75.48% <ø> (ø)
statetests 69.48% <100.00%> (ø)
unittests 93.53% <94.28%> (+0.27%) ⬆️

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

Impacted Files Coverage Δ
test/state/host.hpp 100.00% <ø> (ø)
test/state/host.cpp 89.67% <100.00%> (+2.10%) ⬆️
test/unittests/state_new_account_address_test.cpp 100.00% <100.00%> (ø)

/// @param salt The salt for CREATE2. If null, CREATE address is computed. YP: ζ.
/// @param init_code The contract creation init code. Value only affects CREATE2. YP: 𝐢.
/// @return The computed address for CREATE or CREATE2 scheme.
address compute_new_account_address(const address& sender, uint64_t sender_nonce,
Copy link
Member

Choose a reason for hiding this comment

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

Why not have two overloads:

address compute_new_account_address(const evmc_message& msg, uint64_t sender_nonce) noexcept;
address compute_new_account_address(const address& sender, bytes32& salt, bytes_view init_code) noexcept;

The sender_nonce is irrelevant for create2 and this separation makes it clear which values are used in which.

Copy link
Member Author

Choose a reason for hiding this comment

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

Mostly so that a user don't need to know which overload to select. Now it only needs to provide arguments (sometimes redundantly) and will get the right answer. Non-functional change from what we had.

Copy link
Member

Choose a reason for hiding this comment

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

I think it still makes sense to separate and I'd aim for that later, but it is debatable.

@chfast chfast merged commit 34c65c5 into master Feb 27, 2023
@chfast chfast deleted the new_account_address branch February 27, 2023 14:10
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