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

feat: define initcode mode and require validation of RETURNCONTRACT #86

Merged
merged 10 commits into from
May 22, 2024

Conversation

charles-cooper
Copy link
Contributor

require EOFCREATE to point to initcode, and RETURNCONTRACT to point to runtime code.

spec/eof.md Outdated Show resolved Hide resolved
spec/eof.md Outdated Show resolved Hide resolved
spec/eof.md Outdated Show resolved Hide resolved
spec/eof.md Outdated
@@ -316,10 +316,15 @@ The following instructions are introduced in EOF code:
- the first code section must have a type signature `(0, 0x80, max_stack_height)` (0 inputs non-returning function)
- `EOFCREATE` `initcontainer_index` must be less than `num_container_sections`
- `EOFCREATE` the subcontainer pointed to by `initcontainer_index` must have its `len(data_section)` equal `data_size`, i.e. data section content is exactly as the size declared in the header (see [Data section lifecycle](#data-section-lifecycle))
- `EOFCREATE` the subcontainer pointed to by `initcontainer_index` must be an "initcode" subcontainer, that is, it *must* contain a `RETURNCONTRACT` instruction.
Copy link
Member

Choose a reason for hiding this comment

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

Can EOFCREATE point to a container which contains only REVERT or INVALID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm, interesting! are there any implicit STOP instructions in EOF?

Copy link
Member

Choose a reason for hiding this comment

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

hm, interesting! are there any implicit STOP instructions in EOF?

no, a terminating instruction or an unconditional jump is required at the end of each code section.

Copy link
Contributor Author

@charles-cooper charles-cooper Apr 4, 2024

Choose a reason for hiding this comment

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

in this case, maybe i should change the wording to:

the subcontainer pointed to by initcontainer_index must be an "initcode" subcontainer, that is, it must not contain a RETURN or STOP instruction.

Copy link
Member

Choose a reason for hiding this comment

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

the subcontainer pointed to by initcontainer_index must be an "initcode" subcontainer, that is, it must not contain a RETURN or STOP instruction.

I think this is too weak of a definition, in light of the conditions which are listed below. Also, this makes a REVERT-only subcontainer an "initcode" one, which is not natural IMO.

To be clear: I think the current wording is fine, we just need to be aware of how we treat containers which contain only REVERTs and INVALIDs. As of now, such container is invalid when pointed to by EOFCREATE and valid when pointed to by RETURNCONTRACT, and this rule is implicit. Maybe better to add a **Note** at the bottom to make it explicit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe three types of containers -- RETURN/STOP (0b01), RETURNCONTRACT (0b10) and none (0b00). 0b11 is invalid, but 0b00 can be referenced by either EOFCREATE or RETURNCONTRACT. i don't think an initcode which can only REVERT or INVALID would be very useful, but it might be used somehow for a signaling purpose (like there is information in the revertdata)? but in such a case you would just want to call the contract.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

speaking of signaling - should EOFCREATE and/or TXCREATE return status codes, like EXT*CALL?

Copy link
Member

Choose a reason for hiding this comment

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

maybe three types of containers

This is now unclear to me - does your proposition introduce explicit types in the header or implicit based on the instructions? I thought implicit, without modification to the header

speaking of signaling - should EOFCREATE and/or TXCREATE return status codes, like EXT*CALL?

Both return new address (or zero on failure). I don't recall any discussion happening on this topic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now unclear to me - does your proposition introduce explicit types in the header or implicit based on the instructions? I thought implicit, without modification to the header

it's still implicit, but i was saying we could allow containers with only REVERT or INVALID (and no RETURN/STOP/RETURNCONTRACT) as initcode. i don't think it's very useful though, especially without signaling. (it essentially would be a way to call a subcontainer without actually deploying it.)

Copy link
Member

@pdobacz pdobacz left a comment

Choose a reason for hiding this comment

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

apologies for late feedback, it took me some time to get to this

spec/eof.md Outdated
- `RETURNCONTRACT` `deploy_container_index` must be less than `num_container_sections`
- `RETURNCONTRACT` the subcontainer pointed to `deploy_container_index` must not be an "initcode" subcontainer, that is, it *must not* contain a `RETURNCONTRACT` instruction.
Copy link
Member

Choose a reason for hiding this comment

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

"not contain RETURNCONTRACT" is not the negation of "initcode" subcontainer definition from 2 lines above - that would be "may contain RETURN or STOP". I think trying to define "initcode" container or mode doesn't help, let's just list the rules (exact wording pending):

  1. EOFCREATE points to container without RETURN or STOP
  2. RETURNCONTRACT points to container without RETURNCONTRACT

and that's it, no? I think it covers all the situations described here, following the "lax" ruleset; that is, a container with only REVERT & INVALID is always good.

And actually there's a third one, which is missed here altogether (just realized it), I'm not sure it belongs better here or in the TXCREATE runtime spec:

  1. Top-level container from initcodes pointed to with TXCREATE is without RETURN or STOP

This leaves us with a potential rule to consider: what about subcontainers not pointed to at all? I would simply not allow them, as they're just dead code which may become "undead" on upgrades if we miss it.

  1. Container with a subcontainer not pointed to by either EOFCREATE or RETURNCONTRACT is invalid.

(lastly, albeit this can't be fixed in this PR, just need to remember to fix it in the future, in case #78 goes through:)

  1. Top-level container from tx data in "Creation transaction (to is nil)" is without RETURN or STOP

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok I'll make the changes and remove "initcode-mode"

  1. i can make the change in this PR
  2. i don't know how they could become "undead", but yea i think it is a good idea in general to ban dead code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

although i think it's helpful to have "initcode" as a term for discussion purposes, i'll update the wording and see what you think

Copy link
Member

@pdobacz pdobacz left a comment

Choose a reason for hiding this comment

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

If I'm not mistaken, there was consensus in favor of this change on the EOF impl call, with the expansion of banning dead subcontainers in a follow-up PR. @gumb0 can you take another look before we merge?

@gumb0
Copy link
Contributor

gumb0 commented May 8, 2024

It needs rebase now

  1. TXCREATE addition should go into eof_future_upgrades.md file where TXCREATE lives now
  2. Similar to TXCREATE validation check that top level container is initcontainer should be added to creation transaction.

@gumb0 gumb0 requested a review from pdobacz May 16, 2024 11:19
Copy link
Member

@pdobacz pdobacz left a comment

Choose a reason for hiding this comment

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

2 nits, lgtm

spec/eof.md Outdated Show resolved Hide resolved
spec/eof.md Outdated Show resolved Hide resolved
@gumb0 gumb0 requested a review from pdobacz May 21, 2024 15:00
@pdobacz pdobacz merged commit 1c03068 into ipsilon:main May 22, 2024
1 check passed
gumb0 added a commit to ethereum/evmone that referenced this pull request Jun 24, 2024
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