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

[CREATE Part A (updated)] Modification to Copy Circuit #1419

Merged
merged 11 commits into from
May 25, 2023

Conversation

ed255
Copy link
Member

@ed255 ed255 commented May 19, 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)
  • 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 May 19, 2023
@ed255
Copy link
Member Author

ed255 commented May 19, 2023

This PR is a continuation of #1356
The requests and comments have not been addressed yet, that's the next step before merging.

@github-actions github-actions bot added the crate-bus-mapping Issues related to the bus-mapping workspace member label May 22, 2023
@github-actions github-actions bot removed the crate-bus-mapping Issues related to the bus-mapping workspace member label May 22, 2023
zkevm-circuits/src/copy_circuit.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/copy_circuit.rs Show resolved Hide resolved
zkevm-circuits/src/copy_circuit.rs Show resolved Hide resolved
@KimiWu123 KimiWu123 requested a review from han0110 May 23, 2023 05:39
@KimiWu123 KimiWu123 self-assigned this May 23, 2023
Copy link
Member Author

@ed255 ed255 left a comment

Choose a reason for hiding this comment

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

Currently the tests are not passing due to a degree increase of the gates expressions, take a look at my comment for a possible fix. Following Han observation about the missing constraints on is_first and is_last I think a careful review of this circuit could be really useful! I suggest that we resolve the underconstraints in a future PR (Kimi already opened an issue for that), and move on with this PR once the tests pass to unblock the CREATE.

@@ -50,6 +50,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_rlc: Column<Advice>,
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this related to #971 ?
I see that now the rlc is accumulated in value_acc_rlc and then exposed in the table via rlc_acc, so rlc values never appear in the value column. So probably the issue is solved here.

Copy link
Contributor

Choose a reason for hiding this comment

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

This was @roynalnaruto's fix and not sure the reason behind. But it seems solved the issue you mentioned.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think to have an extra value_acc_rlc is to support memory <-> bytecode copy and rlc at the same time without changing other parts too much.

And it seems to also resolve #971, so we could try to move the phase of value from second to first and see if it works as expected.

Comment on lines 249 to 255
or::expr([
and::expr([
tag.value_equals(CopyDataType::Memory, Rotation::cur())(meta),
tag.value_equals(CopyDataType::Bytecode, Rotation::next())(meta),
]),
tag.value_equals(CopyDataType::RlcAcc, Rotation::next())(meta),
]),
Copy link
Member Author

Choose a reason for hiding this comment

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

The expression from here may be causing the final gate degree ti increase more than 9 (and that's why tests are not passing). A simple solution would be to split this into 2 constraints. Following this pattern:
if A or B then X -> if A then X, if B then X.

Another thing that comes to my mind is that or::expr returns a boolean, but to build a selector expression just having 0 when false and != 0 when true is enough, so perhaps you could replace the or by a +. This would give 2 when both expressions are true, but that's ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice idea! It looks nice and clean now, fixed in 52d480a

@KimiWu123 KimiWu123 removed the request for review from hero78119 May 25, 2023 03:28
Copy link
Collaborator

@han0110 han0110 left a comment

Choose a reason for hiding this comment

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

LGTM now! Thanks for addressing all the comments.

@KimiWu123 KimiWu123 enabled auto-merge May 25, 2023 05:15
@KimiWu123 KimiWu123 self-requested a review May 25, 2023 07:51
@KimiWu123 KimiWu123 added this pull request to the merge queue May 25, 2023
Merged via the queue into main with commit dbe67c8 May 25, 2023
@KimiWu123 KimiWu123 deleted the feat/create-part-a branch May 25, 2023 07:52
lispc pushed a commit that referenced this pull request May 26, 2023
…adgets (#1425)

### Description

**NOTE: This is an updated version of
#1357

This PR is actually based on top of #1419

### 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
Error types for insufficient balance and nonce overflow. These are
supporting changes required for the CREATE/CREATE2 opcodes' gadget.

### Rationale
The above errors will be handled within the CREATE/CREATE2 opcodes'
gadget. In case of insufficient balance, it is also handled in the
CallOp gadget for call related opcodes.

---------

Co-authored-by: Rohit Narurkar <rohit.narurkar@protonmail.com>
@ed255 ed255 linked an issue May 31, 2023 that may be closed by this pull request
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
4 participants