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

CREATE's with failure condition #866

Open
Tracked by #865
OlivierBBB opened this issue Jul 25, 2024 · 8 comments
Open
Tracked by #865

CREATE's with failure condition #866

OlivierBBB opened this issue Jul 25, 2024 · 8 comments

Comments

@OlivierBBB
Copy link
Collaborator

OlivierBBB commented Jul 25, 2024

Question. If a CREATE(2) produces a failure condition does Besu create and enter a child frame ? In particular will it trigger TraceContextEnter/TraceContextExit/TraceContextReEntry ?


Our definition of Failure condition:

  • no exception
  • no abort (i.e. sufficient balance & creator call stack depth < 1024
  • BUT: createe has either nonzero nonce and/or nonempty code

Preliminary Conclusion. The link you provide suggests that CREATE's that aren't aborted (and may therefore still raise a failure condition) actually spawn a child context.

Note. This would be easy to test by the way. Just attempt to CREATE2 with the same init code and salt two times in a row. The second CREATE2 will raise a failure condition.


@lu-pinto and @daniellehrner: could you confirm the above interpretation ?

@OlivierBBB OlivierBBB mentioned this issue Jul 25, 2024
13 tasks
@OlivierBBB OlivierBBB changed the title empty CREATE's with failure condition Jul 25, 2024
@lu-pinto
Copy link
Collaborator

I don't think it gets to invoke the child frame because in the case of e.g. invalid init contract code, an empty item would be put on the operand stack signaling failure and not a new frame. Another example would be if the code is too large a halt state would be returned back. So there's some validation of the code before the child frame gets to execute from what I see, which would fall into your criteria I believe?

The child frame is only spawned here and then we re-enter the process cycle again to run the init code and TraceContextEnter gets called.

@OlivierBBB
Copy link
Collaborator Author

OlivierBBB commented Jul 26, 2024

Thanks @lu-pinto. WRT The code size issue

if (code != null && code.getSize() > maxInitcodeSize) { ... }

maxInitcodeSize limitations apply on later releases than London (IIRC it's twice as much as the maximum deployed bytecode size of 24576). Our arithmetization targets the London EVM.

@OlivierBBB
Copy link
Collaborator Author

OlivierBBB commented Jul 26, 2024

invalid init contract code

What do you mean by that ?

Also for info: everything in Linea is done with respect to the London EVM. So any EIP's beyond London don't apply.

@OlivierBBB
Copy link
Collaborator Author

OlivierBBB commented Jul 26, 2024

This snippet of code you point to preceding the nonce update

    if (value.compareTo(account.getBalance()) > 0
        || frame.getDepth() >= 1024
        || account.getNonce() == -1
        || code == null
        || code.getEofVersion() != frame.getCode().getEofVersion()) {
      fail(frame);
    }

relates to what the issue calls aborted CREATE's. In the present issue we are concerned with what we have called CREATE's raising a failure condition.

And the link you provide suggests that CREATE's that aren't aborted (and may therefore still raise a failure condition) actually spawn a child context.

@OlivierBBB
Copy link
Collaborator Author

Sidenote (for myself) I recognize either

        || account.getNonce() == -1

@letypequividelespoubelles pointed out that the nonce restriction is likely related to java's Long.MAX_VALUE and some EIP about the max value of nonces being 2**64 - 1.

This condition is I guess some Besu stuff.

        || code == null

Note. We are not enforcing the nonce to be a uint64 ... This may lead to some reference tests breaking.

@lu-pinto
Copy link
Collaborator

lu-pinto commented Jul 26, 2024

Our arithmetization targets the London EVM.

I see... I don't remember hearing that until now. I'll have another look keeping that in mind.

maxInitcodeSize limitations apply on later releases than London

Maybe I'm missing something but I don't see that this check is configurable through any settings specifically to the London hardfork. Currently the besu code that Linea is running on is built on a fairly recent version of the besu client. delivery-26 is built from backport of besu@529bd33 git hash. Maybe the condition doesn't trigger with a london genesis file but it's not explicitly apparent that is the case.

@lu-pinto
Copy link
Collaborator

I had another thorough look at unit tests that seem to confirm what I mentioned for maxInitcodeSize -> the check is done even for London EVMs. However the configuration is set to Integer.MAX_VALUE which is a large enough value that this check can be neglected. See london configuration here.

Regarding the invalid init contract code case, when code is loaded before execution, you are right that only EVMs with EOF V1 spec are impacted (not london). There is only a tiny case when maxEofVersion (CodeFactory.java) but that is a developer error which shouldn't happen since it's defined in EvmSpecVersion also.

@lu-pinto
Copy link
Collaborator

lu-pinto commented Jul 30, 2024

Regarding:

Preliminary Conclusion. The link you provide suggests that CREATE's that aren't aborted (and may therefore still raise a failure condition) actually spawn a child context.

I don't see anything else other than the contract account validation after loading the child frame on the stack, inside ContractCreationProcessor.start(). At this point we have already entered the context for the child frame, so your conclusion is correct.
The contract account is checked if it already exists here. Is this the createe you were looking for @OlivierBBB? I'm guessing createe is the contract address being created by the sender. One other condition where we would fail is if the contract account storage is also not empty.

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

No branches or pull requests

2 participants