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

[CREATE Part A] Modification to Copy Circuit #1356

Conversation

roynalnaruto
Copy link
Collaborator

@roynalnaruto roynalnaruto commented Apr 14, 2023

Description

This is Part A of a 3 part pull request to add support for CREATE/CREATE2 opcodes.

Part A: #1356
Part B: #1357
Part C: #1358

Issue Link

#1130

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Contents

As part of the bigger additions needed for the CREATE/CREATE2 opcodes' gadget, this PR adds support for the copy circuit to "always" have a value accumulator field value_acc.

Rationale

We need a value accumulator (of the random linear combination) in order to get the RLC(bytes) for the bytes copied from Memory to Bytecode (specifically the init code). This RLC is later used to do a lookup to the Keccak table to check the value of keccak256(init_code).

How Has This Been Tested?

The existing tests for copy circuit pass for the updated constraints on the copy circuit.

@github-actions github-actions bot added crate-mock Issues related to the mock workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member labels Apr 14, 2023
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.

Nice refactor by replace accumulation on value by value_acc which make thing more clear! just got few comments

@@ -94,11 +95,12 @@ impl<F: Field> ExecutionGadget<F> for ReturnRevertGadget<F> {

let is_contract_deployment =
is_create.clone() * is_success.expr() * not::expr(copy_rw_increase_is_zero.expr());
let (caller_id, address, reversion_info, code_hash) =
let (caller_id, address, reversion_info, code_hash, init_code_rlc) =
cb.condition(is_contract_deployment.clone(), |cb| {
// We don't need to place any additional constraints on code_hash because the
// copy circuit enforces that it is the hash of the bytes in the copy lookup.
Copy link
Member

Choose a reason for hiding this comment

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

since intruduce init_code_rlc i think the comment also need to adjust a bit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what comment I should add. Could you provide an example?

@@ -47,6 +47,8 @@ pub struct CopyCircuitConfig<F> {
pub is_last: Column<Advice>,
/// The value copied in this copy step.
pub value: Column<Advice>,
/// Random linear combination accumulator value.
pub value_acc: Column<Advice>,
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename value_acc into value_keccak_acc for more self-explanation

Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer to rename to value_acc_rlc. Most of our code and docs are using _rlc as suffix to represent rlc variables and it looks good to me without keyword, keccak.

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed in 55aebf9


cb.gate(meta.query_fixed(q_enable, Rotation::cur()))
});

meta.create_gate(
Copy link
Member

Choose a reason for hiding this comment

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

Seems this gate and next gate can be combine into just 1 gate ?

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed in 55aebf9

cb.gate(and::expr([
meta.query_fixed(q_enable, Rotation::cur()),
meta.query_advice(is_last, Rotation::next()),
and::expr([
Copy link
Member

Choose a reason for hiding this comment

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

Here nested and::expr seems unnessarary, is it for readibility?

Copy link
Contributor

Choose a reason for hiding this comment

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

agree, I don't think we need it, but it has better readability for me. I prefer to keep the way it is. How do you think?

@hero78119
Copy link
Member

hero78119 commented Apr 17, 2023

Also raise privacy-scaling-explorations/zkevm-specs#411 to align copy-circuit specs

@han0110 han0110 self-requested a review April 18, 2023 10:11
@aguzmant103 aguzmant103 linked an issue Apr 20, 2023 that may be closed by this pull request
@ed255
Copy link
Member

ed255 commented May 19, 2023

Moved to #1419

@ed255 ed255 closed this May 19, 2023
KimiWu123 added a commit that referenced this pull request May 25, 2023
### Description

NOTE: This is an updated version of
#1356

This is Part A of a 3 part pull request to add support for
`CREATE`/`CREATE2` opcodes.

Part A:
#1356
Part B:
#1357
Part C:
#1358

### Issue Link

#1130 

### Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Contents
 
As part of the bigger additions needed for the `CREATE`/`CREATE2`
opcodes' gadget, this PR adds support for the copy circuit to "always"
have a value accumulator field `value_acc`.

### Rationale

We need a value accumulator (of the random linear combination) in order
to get the `RLC(bytes)` for the bytes copied from `Memory` to `Bytecode`
(specifically the init code). This RLC is later used to do a lookup to
the Keccak table to check the value of `keccak256(init_code)`.

### How Has This Been Tested?

The existing tests for copy circuit pass for the updated constraints on
the copy circuit.

---------

Co-authored-by: Rohit Narurkar <[email protected]>
Co-authored-by: KimiWu <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
crate-mock Issues related to the mock 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 CREATE & CREATE2
6 participants