Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

circuit for invalid creation code #1292

Conversation

DreamWuGit
Copy link
Collaborator

@DreamWuGit DreamWuGit commented Mar 8, 2023

Description

circuit for invalid creation code error in create, markdown spec privacy-scaling-explorations/zkevm-specs#400

Issue Link

issue #1291

Type of change

  • New feature (non-breaking change which adds functionality)

Rationale

Get first byte of code to store , check it is 0xef

This PR contains:

  • buss mapping: at the return opcode in create, get the first byte .
  • add circuit & test
  • add tx deploy trace test .

@github-actions github-actions bot added crate-bus-mapping Issues related to the bus-mapping workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member labels Mar 8, 2023
@hero78119
Copy link
Member

Hi @DreamWuGit , would you kindly resolved the conflict, since this pr #1342 is merged :) ? Thanks!
I think few error handling step should be able to handled by new merged restore context function.

@lispc
Copy link
Collaborator

lispc commented Apr 17, 2023

yes @DreamWuGit can copy new codes from scroll fork i think. i have already merged these branches.

@aguzmant103 aguzmant103 requested a review from lispc April 20, 2023 12:04
@ed255
Copy link
Member

ed255 commented Apr 27, 2023

@DreamWuGit kindly reminder: could you update this PR to resolve conflicts? Thanks!

@ChihChengLiang
Copy link
Collaborator

ChihChengLiang commented Jun 13, 2023

CREATE PRs (#1419 #1425 #1430 ) are all merged. This PR is unblocked.
@DreamWuGit

@ChihChengLiang ChihChengLiang linked an issue Jun 13, 2023 that may be closed by this pull request
@lispc
Copy link
Collaborator

lispc commented Jun 15, 2023

@silathdiir will work on this

@ChihChengLiang
Copy link
Collaborator

@silathdiir is this ready for review?

@silathdiir
Copy link
Contributor

Yes, thanks. I update this PR with latest main branch, and also the spec doc PR privacy-scaling-explorations/zkevm-specs#400.

Please help review when you have time. Thanks.

Copy link
Member

@hero78119 hero78119 left a comment

Choose a reason for hiding this comment

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

Hi, one question regarding to soundness

In create.rs and return_revert, I didn't find the constraint where force the prover must fill is_success == false if code starting with 0xef. I am wondering what if a malicious prover fill is_success = true, can the create/return_revert circuit catch up this InValidCreationWord error or actually it can pass?
From what I understand the only place to avoid this soundness is create.rs must also have constrain which force to go this error execution step.

@silathdiir
Copy link
Contributor

silathdiir commented Jun 23, 2023

Hi, one question regarding to soundness

In create.rs and return_revert, I didn't find the constraint where force the prover must fill is_success == false if code starting with 0xef. I am wondering what if a malicious prover fill is_success = true, can the create/return_revert circuit catch up this InValidCreationWord error or actually it can pass? From what I understand the only place to avoid this soundness is create.rs must also have constrain which force to go this error execution step.

Yes, I see, I think you are right.
I will add is_first_byte_invalid and constrain as below to create.rs and begin_tx.rs (which may also call Create) in this PR:

let is_first_byte_invalid = IsEqualGadget::construct(cb, first_byte.expr(), 0xef.expr());

cb.condition(is_success.expr(), |cb| {
    cb.require_zero(
        "init_code_first_byte != 0xef if success",
        is_first_byte_invalid
    );
});

@github-actions github-actions bot added the crate-eth-types Issues related to the eth-types workspace member label Jun 26, 2023
@silathdiir
Copy link
Contributor

Hi @hero78119, sorry for late update.

After some investigation, it seems that in CREATE (or CREATE2) execution step, the contract Run result could not be retrieved (from memory) to check this ErrInvalidCode error. Please correct me if I was wrong, thanks.

So I fix to add a constraint which constrains the first byte of create init code must not be 0xef to return_revert in this commit 3138114. Please help review again when you have time. Thanks.

Copy link
Member

@hero78119 hero78119 left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix!! @silathdiir 🙏

I think we also need to fix specs part, other than that all LTGM!

bus-mapping/src/circuit_input_builder/input_state_ref.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/evm_circuit/execution/return_revert.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/evm_circuit/util/common_gadget.rs Outdated Show resolved Hide resolved
…`init_code_first_byte` to 0 in else condition, and rename `construct_with_last_return` to `construct_with_return_data`.
Copy link
Member

@hero78119 hero78119 left a comment

Choose a reason for hiding this comment

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

👍 LGTM! 💯

@ChihChengLiang
Copy link
Collaborator

Hi @lispc,
Would you be available to review this PR?
We can assign another reviewer if you are busy.

@KimiWu123 KimiWu123 mentioned this pull request Jul 7, 2023
48 tasks
@lispc
Copy link
Collaborator

lispc commented Jul 7, 2023

i will have a look

@lispc lispc added this pull request to the merge queue Jul 7, 2023
Merged via the queue into privacy-scaling-explorations:main with commit 3733326 Jul 7, 2023
@lispc lispc deleted the error_invalid_creation_code branch July 7, 2023 05:10
cameron1024 pushed a commit to cameron1024/zkevm-circuits that referenced this pull request Jun 30, 2024
* refactor many prover codes

* fix

* fix

* tmp hack for opcode parsing
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
crate-bus-mapping Issues related to the bus-mapping workspace member crate-eth-types Issues related to the eth-types workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement InvalidCreationCode error state
7 participants