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

Clarify the difference between code and recipient #286

Merged
merged 5 commits into from
Jul 13, 2021
Merged

Conversation

yperbasis
Copy link
Member

@yperbasis yperbasis commented Jul 12, 2021

An evmc_message contains only two addresses (sender and "destination").
However, in case of DELEGATECALL we need 3 addresses (sender, recipient, and code), so we recover the missing 3rd address from the address_stack_.

See Section 8 "Message Call" of the Yellow Paper.
destination in evmc_message can mean either code or recipient, depending on the context.

@chfast
Copy link
Member

chfast commented Jul 12, 2021

This issue was brought up some other time (cannot find it now): the single DELEGATECALL case requires the evmc::Host to track the recipient address because this information cannot be recovered from the evmc::message. Otherwise the Host implementation can be "stateless".

I think it is time to solve it on EVMC level by adding one more evmc::address field.
If you have good spec insights, can you suggest names for these?


if (message.kind == EVMC_CALL) {
if (message.flags & EVMC_STATIC) {
// Match geth logic
// https://github.com/ethereum/go-ethereum/blob/v1.9.25/core/vm/evm.go#L391
state_.touch(message.destination);
state_.touch(recipient_address);
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be fixing a consensus bug. Are there any tests failing?

Copy link
Member Author

Choose a reason for hiding this comment

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

This seems to be fixing a consensus bug. Are there any tests failing?

Not really because this code is executed only when message.kind == EVMC_CALL

@yperbasis
Copy link
Member Author

This issue was brought up some other time (cannot find it now): the single DELEGATECALL case requires the evmc::Host to track the recipient address because this information cannot be recovered from the evmc::message. Otherwise the Host implementation can be "stateless".

I think it is time to solve it on EVMC level by adding one more evmc::address field.
If you have good spec insights, can you suggest names for these?

I'd suggest to split "destination" into "recipient" and "code", in line with Section 8 "Message Call" of the Yellow Paper.

@@ -224,7 +225,22 @@ evmc::result EVM::call(const evmc_message& message) noexcept {
return res;
}

evmc_address EVM::recipient_of_call_message(const evmc_message& message) noexcept {
Copy link
Member

Choose a reason for hiding this comment

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

This is similar code for it in Aleth: https://github.com/ethereum/aleth/blob/master/libevm/ExtVMFace.cpp#L206-L208

I'm usually confused by this, but it seems that for the CALLCODE the answer is also message.destination.

@chfast
Copy link
Member

chfast commented Jul 12, 2021

I'd suggest to split "destination" into "recipient" and "code", in line with Section 8 "Message Call" of the Yellow Paper.

Sounds good except I cannot name it "code" :). Then code_address, recipient_address, sender_address? Or code_address, recipient, sender? Or code_account?

@codecov
Copy link

codecov bot commented Jul 12, 2021

Codecov Report

Merging #286 (5cd5ac9) into master (6995360) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #286      +/-   ##
==========================================
+ Coverage   81.14%   81.18%   +0.03%     
==========================================
  Files          82       82              
  Lines        7334     7349      +15     
==========================================
+ Hits         5951     5966      +15     
  Misses       1383     1383              
Impacted Files Coverage Δ
core/silkworm/execution/evm.hpp 100.00% <ø> (ø)
core/silkworm/execution/evm.cpp 97.29% <100.00%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6995360...5cd5ac9. Read the comment docs.

@yperbasis
Copy link
Member Author

I'd suggest to split "destination" into "recipient" and "code", in line with Section 8 "Message Call" of the Yellow Paper.

Sounds good except I cannot name it "code" :). Then code_address, recipient_address, sender_address? Or code_address, recipient, sender? Or code_account?

My preference would be code_address, recipient, sender

@yperbasis yperbasis merged commit b5228ef into master Jul 13, 2021
@yperbasis yperbasis deleted the delegatecall branch July 13, 2021 10:49
@yperbasis
Copy link
Member Author

@chfast I think a better idea would be not to change evmc::message, but to add code_address as an argument to evmc_host_interface::call. I'll quickly try if it works.

@yperbasis
Copy link
Member Author

@chfast Oh well, extending evmc_host_interface::call seems to be too much work on the evmc side.

I've created ethereum/evmc#611, ethereum/evmone#360, and #288 that add code_address to evmc_message.

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