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

Memory opt with word look up #466

Merged
merged 134 commits into from
Jul 17, 2023
Merged

Memory opt with word look up #466

merged 134 commits into from
Jul 17, 2023

Conversation

DreamWuGit
Copy link
Member

@DreamWuGit DreamWuGit commented Apr 13, 2023

spec refer to privacy-scaling-explorations/zkevm-specs#407
copy circuit design https://hackmd.io/_bMS2rvjQK23efyMkoHbkw
memory to memory design: https://hackmd.io/tuqJYr-DT3eqXvSM_6AHGQ?view

Refactor

  • extract common codes for state.gen_copy_steps_for_XXX @DreamWuGit
  • rethink some complex opcodes like bus-mapping::return_revert/sha3 @lispc

EVM circuit

  • add new memory word Op and calculate slot, shift
  • update fixed size memory lookup opcodes (mload/mstore/mstore8/calldataload)
  • update calldatacopy/codecopy/excodecopy
  • update logs/ sha3 / returndatacopy (WIP)
  • constrain mask, slot , shift relation, word equality. (@Aurel) https://app.asana.com/0/0/1204561543121039/f
  • update invalid_creation_code, return/revert/ create
  • fix CI issues, review if soundness problem ?
  • handle value_prev Memory opt update #541

state circuit

Copy circuit

  • add addr_slot ,word_index, value_wrod_rlc, mask columns and look up RW memory word when word_index = 31
  • lookup tx log byte to word (use addr_slot as address)
  • copy circuit tests for calldatacopy/codecopy/extcodecopy/logs/sha3 pass
  • review and update disabled constraints affected by memory word lookup and better way to change instead of disable : rows[0].addr + 1 == rows[2].addr, rows[0].rw_counter + rw_diff == rows[1].rw_counter , write value == read valuevalue_acc(2) == value_acc(0) * r + value(2), constraint etc.
  • add returndatacopy test in copy circuit side, originally missing.
  • constrain mask is bool & word_index [0--32] increase by 1
  • constrain addr_slot starts with zero and increase by 32 ?
  • fix copy circuit degree increase by 1
  • change copy circuit to reflect real/mask length such that evm gadget can use real copy length using real length in copy table lookup #565
  • refactor all type copy bytes using rlc_acc equality check(refactor all copy bytes using rlc_acc equality check  #604)

@DreamWuGit DreamWuGit changed the title add MemoryWordAddress gadget and todos Memory opt with word look up Apr 13, 2023
naure and others added 4 commits July 13, 2023 13:05
* word_rlc: introduce value_prev in copy circuit

* memory_opt_word_rlc: verify word RLCs

---------

Co-authored-by: Aurélien Nicolas <info@nau.re>
* memory_opt_length: track both source and destination lengths. Simplify constraints

* memory_opt_length: constrain the shape of the mask

---------

Co-authored-by: Aurélien Nicolas <info@nau.re>
* memory_opt_rwc: fix and simplify RW counter logic

* memory_opt_rwc: simplify CopyEvent rw functions

---------

Co-authored-by: Aurélien Nicolas <info@nau.re>
@lispc
Copy link

lispc commented Jul 14, 2023

\b run testool

@zkevm-circuits-bots
Copy link

naure and others added 2 commits July 14, 2023 20:02
* memory_opt_check_align: require aligned memory addresses in State

* memory_opt_check_align: tests

---------

Co-authored-by: Aurélien Nicolas <info@nau.re>
* memory_opt_rm_ltchip: replace LessThan with IsEqual

* memory_opt_rm_ltchip: support other rotations in IsEqualChip

* memory_opt_rm_ltchip: constrain is_pad from is_src_end_next

* memory_opt_rm_ltchip: remove the old chip

* memory_opt_rm_ltchip: add doc and assertion

---------

Co-authored-by: Aurélien Nicolas <info@nau.re>
naure and others added 8 commits July 14, 2023 18:02
Co-authored-by: Aurélien Nicolas <info@nau.re>
* memory_opt_gadgets: move code into a function

* memory_opt_gadgets: move code into constrain_word_rlc()

* memory_opt_gadgets: move code into constrain_value_rlc()

* memory_opt_gadgets: move code into constrain_event_rlc_acc()

* memory_opt_gadgets: constrain_bytes_left

* memory_opt_gadgets: doc

* memory_opt_gadgets: move code into constrain_rw_counter. rustfmt works again!

* memory_opt_gadgets: constrain_forward_parameters and constrain_address

* memory_opt_gadgets: move code to constrain_mask()

* memory_opt_gadgets: move code to constrain_is_pad()

* memory_opt_gadgets: move code to constrain_non_pad_non_mask()

* memory_opt_gadgets: move code to constrain_first_last

* memory_opt_gadgets: constrain_masked_value and constrain_must_terminate

* memory_opt_gadgets: reorg is_pad and is_last

* memory_opt_gadgets: reorder gadgets to match the circuit

* memory_opt_gadgets: move code into constrain_tag. Done!

---------

Co-authored-by: Aurélien Nicolas <info@nau.re>
Co-authored-by: Aurélien Nicolas <info@nau.re>
* Avoid whole memory clone for CODECOPY and EXTCODECOPY.

* Update

* Fix to extend memory as range(begin_slot, full_length), and update `src_addr_end`.

* Delete unused function `write_memory_words` in callop.

* Delete memory clone in callop.

* Fix lint.

* Delete memory clone in calldatacopy.

* Update returndatacopy, and extract to a common function.

* Fix lint.

* Update bytecode copy.

* Small fix.
@lispc
Copy link

lispc commented Jul 17, 2023

\b run testool

@zkevm-circuits-bots
Copy link

@lispc lispc merged commit fc6c8a2 into develop Jul 17, 2023
14 checks passed
@lispc lispc deleted the memory_opt branch July 17, 2023 12:36
@lispc lispc restored the memory_opt branch October 12, 2023 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants