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

Add EIP: EOF - EXTCODEADDRESS instruction #9342

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

Conversation

shemnon
Copy link
Contributor

@shemnon shemnon commented Feb 8, 2025

Add an instruction to EOF that reads code delegation designations from the account without requiring code introspection.

Add an instruction to EOF that reads code delegation designations from
the account without requiring code introspection.
@shemnon shemnon requested a review from eth-bot as a code owner February 8, 2025 18:52
@github-actions github-actions bot added c-new Creates a brand new proposal s-draft This EIP is a Draft t-core labels Feb 8, 2025
@eth-bot
Copy link
Collaborator

eth-bot commented Feb 8, 2025

File EIPS/eip-7880.md

Requires 1 more reviewers from @g11tech, @lightclient, @SamWilsn

@eth-bot eth-bot added e-consensus Waiting on editor consensus e-review Waiting on editor to review labels Feb 8, 2025
@github-actions github-actions bot added the w-ci Waiting on CI to pass label Feb 8, 2025
Copy link

The commit 8c86b82 (as a parent of c6b3f75) contains errors.
Please inspect the Run Summary for details.

@github-actions github-actions bot removed the w-ci Waiting on CI to pass label Feb 12, 2025
@shemnon shemnon closed this Feb 12, 2025
@shemnon shemnon reopened this Feb 12, 2025
EIPS/eip-7880.md Outdated

| Constant | Value |
|---------------------------|--------------------------------------------------------------------|
| `FORK_BLKNUM` | tbd |
Copy link
Contributor

Choose a reason for hiding this comment

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

Forks are done based on timestamp rather than block number

Copy link
Contributor

Choose a reason for hiding this comment

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

also we don't now mention a block num/timestamp constant which would need to be updated. we can say on activation of this EIP if this is just a standard timestamp hf activation, else just refer to FORK_TIMESTAMP if needed for a fork boundary logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. On deeper reflection referring to a specific activation block or timestamp is also not quite right, we should be referenceing the block the fork is activated, which will be different on mainnet, devnets, and L2s.

Reworded it to reference fork activation, agnostic of how it is activagted.


Add an instruction to EOF that reads code delegation designations from an account without requiring code introspection.

## Motivation
Copy link
Contributor

Choose a reason for hiding this comment

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

To me, the motivation skips the case, out of which the entire premise of delegation introspection came about: https://hackmd.io/@otim/H1Q7yCHDyl#Why-is-%E2%80%9Cdelegation-introspection%E2%80%9D-useful . Without EXTCODEADDRESS, when an untrusted 7702 address is called, that call can be frontrun with a SetCode tx making it point to a different, malicious implementation.

- Notice: if [EIP-7702] delegation designations are updated in a future fork (such as allowing chained delegations), then this section is expected to comply with any such hypothetical changes.
- Otherwise, push `target_adress` onto the stack.

Note: If `target_address` or the delegation designator points to an account with a contract mid-creation then the code is empty and returns `0` (`TYPE_NONE`). This is aligned with similar behavior of instructions like `EXTCODESIZE`.
Copy link
Contributor

Choose a reason for hiding this comment

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

should it also be added in form of a note, that EXTCODEADDRESS belongs (somewhat awkwardly) to the group of code executing instructions, in the language of 7702

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's necessary, and would be awkward indeed

status: Draft
type: Standards Track
category: Core
created: 2024-09-01
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
created: 2024-09-01
created: 2025-02-08

- Notice: Future expansion of the EVM address space may enlarge the number of valid addresses. Do not rely on this step always halting with the current restrictions.
- deduct `GAS_COLD_ACCOUNT_ACCESS - GAS_WARM_ACCESS` if `target_address` is not in `accessed_addresses` and add `target_address` to `accessed_addresses`
- Load the code from `target_address` and refer to it as `loaded_code`
- If `loaded_code` indicates a delegation designator (for example, `0xef0100` as defined in [EIP-7702]) push the address of the designation onto the stack.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- If `loaded_code` indicates a delegation designator (for example, `0xef0100` as defined in [EIP-7702]) push the address of the designation onto the stack.
- If `loaded_code` indicates a delegation designator (for example, prefixed with `0xef0100` as defined in [EIP-7702]) push the address of the designation onto the stack.

- Notice: if [EIP-7702] delegation designations are updated in a future fork (such as allowing chained delegations), then this section is expected to comply with any such hypothetical changes.
- Otherwise, push `target_adress` onto the stack.

Note: If `target_address` or the delegation designator points to an account with a contract mid-creation then the code is empty and returns `0` (`TYPE_NONE`). This is aligned with similar behavior of instructions like `EXTCODESIZE`.
Copy link
Member

Choose a reason for hiding this comment

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

In case of delegation designator pointing to address mid-creation, it's true that EXTCODESIZE returns 0, but why would EXTCODEADDRESS do so? I think it should still return the delegate address.

Suggested change
Note: If `target_address` or the delegation designator points to an account with a contract mid-creation then the code is empty and returns `0` (`TYPE_NONE`). This is aligned with similar behavior of instructions like `EXTCODESIZE`.
Note: If `target_address` points to an account with a contract mid-creation then the code is empty and returns `0` (`TYPE_NONE`). This is aligned with similar behavior of instructions like `EXTCODESIZE`.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, but I would even go further. If target_address points to an account with a contract mid-creation, it should return target_address, in line with the generic rule "Otherwise, push target_adress onto the stack." above.

I missed this on first read. EXTCODEADDRESS should by principle return the address which holds the code which would execute if target_address was CALLed, regardless of what that code is.

Copy link
Member

Choose a reason for hiding this comment

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

EXTCODEADDRESS should by principle return the address which holds the code which would execute if target_address was CALLed, regardless of what that code is.

If it is called when delegate is mid-creation, empty code is executed, right? not the delegation designator interpreted as code.

Copy link
Contributor

Choose a reason for hiding this comment

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

right, but we're returning the address of that empty code, not the empty code. I'd say that mid-creationness should have nothing to do here, and this Note could be removed.

Copy link
Member

Choose a reason for hiding this comment

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

right, but we're returning the address of that empty code, not the empty code.

This confused me, but my logic is:

  • EXTCODEADDRESS(target) where target has regular code, returns target because CALL(target) executes target.code
  • EXTCODEADDRESS(target) where target has delegation designator, returns delegate_address because CALL(target) executes delegate_address.code
  • EXTCODEADDRESS(target) where target has delegation designator, but delegate_address is mid-creation, returns delegate_address because CALL(target) executes delegate_address.code (empty code), and not target.code (delegation designator)

Copy link
Member

@gumb0 gumb0 Feb 20, 2025

Choose a reason for hiding this comment

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

Good point, but I would even go further. If target_address points to an account with a contract mid-creation, it should return target_address

Ah yes, this I misdunderstood on the first read, actually I think I agree, so target_address should be returned in both these cases, but I would keep the note about it to be explicit.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Note: If `target_address` or the delegation designator points to an account with a contract mid-creation then the code is empty and returns `0` (`TYPE_NONE`). This is aligned with similar behavior of instructions like `EXTCODESIZE`.
Note: If `target_address` points to an account with a contract mid-creation, then `target_address` is returned. If delegation designator points to an account with a contract mid-creation, then address of the designation is returned.

Copy link
Contributor

Choose a reason for hiding this comment

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

target_address should be returned in both these cases, but I would keep the note about it to be explicit.

Wait, no :). Your above 3 points seem correct to me, but not this (assuming you're referring to the original two cases in the Note). The mid-creation cases should just follow the general logic specced above (and to not confuse, we'd better remove the Note):

So:

  • EXTCODEADDRESS(target) where target has delegation designator, but delegate_address is mid-creation, returns delegate_address, just like if delegate_address held empty code, code or another delegation
  • otherwise EXTCODEADDRESS(target) where target is mid-creation, returns target, just like if target held empty code or code

Mid-creationnes has no effect, the only branch of the logic is on whether target.code has delegation designator or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, your second suggested change looks ok to me (I'd still at least add that being midcreation has no effect whatsoever, in addition to the scenarios you've given).

[EIP-7702]: ./eip-7702.md
[EIP-7692]: ./eip-7692.md
[EIP-7761]: ./eip-7761.md
[Ethereum Execution Layer Spec Constants] :https://github.com/ethereum/execution-specs/blob/1adcc1bfe774798bcacc685aebc17bd9935078c3/src/ethereum/cancun/vm/gas.py#L65-L66
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[Ethereum Execution Layer Spec Constants] :https://github.com/ethereum/execution-specs/blob/1adcc1bfe774798bcacc685aebc17bd9935078c3/src/ethereum/cancun/vm/gas.py#L65-L66
[Ethereum Execution Layer Spec Constants]: https://github.com/ethereum/execution-specs/blob/1adcc1bfe774798bcacc685aebc17bd9935078c3/src/ethereum/cancun/vm/gas.py#L65-L66

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-new Creates a brand new proposal e-consensus Waiting on editor consensus e-review Waiting on editor to review s-draft This EIP is a Draft t-core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants