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

Feat/#1474 rw lookup index error #1482

Merged
merged 9 commits into from
Jun 21, 2023
Merged

Conversation

KimiWu123
Copy link
Contributor

@KimiWu123 KimiWu123 commented Jun 19, 2023

Description

address #1474 and also found #1483 when investigating this issue.

Issue Link

#1474

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

  • The root cause is that there are memory operations in block.get_rws() but there is only single copy lookup expression while copy table lookup happens in opcode execution. Which makes the indexes of assigned_rw_values and step.bus_mapping_instance are inconsistent.
  • Add a new function get_rws_for_check_rw_lookup specific for check_rw_lookup. This function could bypass memory operations if any copy table lookup happens, and it makes the indexes of assigned_rw_values and step.bus_mapping_instance consistent.

Rationale

  • Add a new function instead of modifying get_rws() is because trying to minimize the impact to our codebase since this is a check function.

@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 Jun 19, 2023
@KimiWu123 KimiWu123 self-assigned this Jun 19, 2023
@hero78119 hero78119 self-requested a review June 19, 2023 06:53
@KimiWu123 KimiWu123 marked this pull request as draft June 19, 2023 07:08
@KimiWu123 KimiWu123 force-pushed the feat/#1474-rw-lookup-index-error branch from 40c2183 to a627c6c Compare June 19, 2023 07:09
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.

Just notice it's in draft, but already review few so the comments is published first, will have another round once it's ready

@@ -73,6 +74,35 @@ impl<F: Field> Block<F> {
self.rws[step.rw_index(index)]
}

/// Get a read-write record for `check_rw_lookup`
pub(crate) fn get_rws_for_check_rw_lookup(
Copy link
Member

Choose a reason for hiding this comment

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

Hope I understand this function correctly 😃 (it will be nice to document it more) I think another option is having get_next_non_memoryrw_operef and make skip_memory_rw boolean logic check outside, which I think somehow make this util function dedicate to its functionality (and easier to read).

However, a bit worry about this stateful design. If there are other normal memory rw operation sequence consecutively happen after the memory rw trigger by copy constraints, will this function break and skip them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think another option is having get_next_non_memoryrw_operef and make skip_memory_rw boolean logic check outside,

it's a good idea!

However, a bit worry about this stateful design. If there are other normal memory rw operation sequence consecutively happen after the memory rw trigger by copy constraints, will this function break and skip them?

yes, I had the same concern either but after checking our code, only calldataload and memory have memory rw operations and no copy lookup inside. So, it should be fine now. But I'll figuire out other possiblilities.

bus-mapping/src/evm/opcodes/create.rs Show resolved Hide resolved
@KimiWu123 KimiWu123 force-pushed the feat/#1474-rw-lookup-index-error branch from a627c6c to b875da0 Compare June 19, 2023 07:12
@KimiWu123 KimiWu123 marked this pull request as ready for review June 20, 2023 04:37
@KimiWu123 KimiWu123 requested a review from hero78119 June 20, 2023 07:42
@ChihChengLiang ChihChengLiang self-requested a review June 20, 2023 10:42
Copy link
Collaborator

@ChihChengLiang ChihChengLiang left a comment

Choose a reason for hiding this comment

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

LGTM. I can confirm that the command in #1474 no longer logs errors.
Great work fixing the logs. It must take you a lot of effort to track this bug.

We should do a systematic refactor for check_rw_lookup to make the logging code easier to maintain.

@hero78119
Copy link
Member

hero78119 commented Jun 21, 2023

Last time discussed with @KimiWu123 . Right now this change only able to handle pretty special case: only 1 copy event. I think better way to fix is able to get real rw counter assigned value in check phase. To do that, it need some interface change, where the scope will be larger. Here I have some preliminary trying, 770f6cf Just record here so later we can FYI

Its ok to keep this pr to only fix single copy event issue. Just we need to have proper TODO in comment, and warn that once there are > 1 copy events happened then this check is skip

@KimiWu123
Copy link
Contributor Author

Refactor for check_rw_lookup created, #1489, cc @ChihChengLiang and @hero78119

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!

@KimiWu123 KimiWu123 enabled auto-merge June 21, 2023 09:16
@KimiWu123 KimiWu123 added this pull request to the merge queue Jun 21, 2023
Merged via the queue into main with commit d067644 Jun 21, 2023
18 of 19 checks passed
@KimiWu123 KimiWu123 deleted the feat/#1474-rw-lookup-index-error branch June 21, 2023 09:32
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-zkevm-circuits Issues related to the zkevm-circuits workspace member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inspect rw lookup index mismatch error related to contract creation
3 participants