Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Memory opt update #541

Merged
merged 56 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
cb77caf
memory_opt_opcodes: constraints for MLOAD/MSTORE/MSTORE8
Jun 9, 2023
1530d00
Merge branch 'memory_opt' into memory_opt_opcodes
Jun 9, 2023
1ac05ac
memory_opt_opcodes: refactor all memory alignment logic into a gadget
Jun 14, 2023
c6093b7
memory_opt_opcodes: connect calldata and memory values
Jun 14, 2023
234b976
memory_opt_opcodes: switch to BE-order to match current copy circuit
Jun 14, 2023
8a7d7f6
memory_opt_update: add memory value_prev to the RW API
Jun 14, 2023
ac68263
memory_opt_update: track value_prev for memory writes
Jun 14, 2023
064bf98
Merge branch 'memory_opt' into memory_opt_update
Jun 14, 2023
157433d
Merge branch 'memory_opt' into memory_opt_opcodes
Jun 14, 2023
3f339fc
Merge branch 'memory_opt_opcodes' into memory_opt_update
Jun 14, 2023
3826bdf
memory_opt_update: check value_prev of memory ops
Jun 14, 2023
e6cc558
memory_opt_update: common lookup with mstore8
Jun 14, 2023
16cc573
memory_opt_update: add column word_prev in copy circuit
Jun 14, 2023
3a15be7
Merge branch 'memory_opt' into memory_opt_update
Jun 14, 2023
e314578
memory_opt_update: find value_prev in memory_write_word
Jun 15, 2023
2d76c95
memory_opt_update: move common logic into read_memory_word
Jun 16, 2023
a4c2d14
Merge branch 'memory_opt' into memory_opt_update
naure Jun 21, 2023
b58b67d
memory_opt_update: fix tests
Jun 15, 2023
ed9a33a
memory_opt_update: move logic to a common read_memory_caller function
Jun 16, 2023
1edd989
memory_opt_update: fix, simplify, optimize RETURN copy
Jun 22, 2023
5f8bab0
memory_opt_update: refactor calldatacopy
Jun 22, 2023
dd62eff
memory_opt_update: calldatacopy with value prev
Jun 22, 2023
b5bb4d5
memory_opt_update: revert new_read name
Jun 22, 2023
6c8bbcd
memory_opt_update: returndatacopy with value prev
Jun 22, 2023
6b12567
memory_opt_update: common function align_range with correct edge cases
Jun 22, 2023
1b9b62b
memory_opt_update: optimize codecopy
Jun 22, 2023
4b456a3
memory_opt_update: optimize log copy
Jun 22, 2023
44d187e
memory_opt_update: fix LOG off-by-one word count
Jun 22, 2023
2a679a9
Merge branch 'memory_opt' into memory_opt_update
Jun 22, 2023
a222f35
memory_opt_update: prepare callop write_memory_words
Jun 22, 2023
f527230
Merge branch 'memory_opt' into memory_opt_update
Jun 22, 2023
fbf2a31
memory_opt_update: remove unnecessary stack_index
Jun 22, 2023
329169e
memory_opt_update: read actual log data
Jun 23, 2023
706b9ed
fix memory_word_value to memory_word_pair in callop
DreamWuGit Jun 27, 2023
acb2fe5
Merge branch 'memory_opt_update' of github.com:scroll-tech/zkevm-circ…
Jun 23, 2023
b6af05a
memory_opt_update: fix indexes in circuit_row
Jun 23, 2023
2d9a7bd
Merge branch 'memory_opt' into memory_opt_update
Jun 27, 2023
21f34eb
Merge branch 'memory_opt' into memory_opt_update
Jun 27, 2023
1e96a95
memory_opt_update: take rwc from bus-mapping instead of outdated calc…
Jun 28, 2023
ee1fe9a
memory_opt_update: remove redundant RWC calculations
Jun 28, 2023
3686329
memory_opt_update: remove redundant RWC calculations
Jun 28, 2023
c01b968
memory_opt_update: remove redundant RWC calculations
Jun 28, 2023
f2b6a00
memory_opt_update: remove redundant RWC calculations
Jun 28, 2023
d576242
memory_opt_update: track copy RWs for check_rw_lookups
Jun 28, 2023
6490e50
memory_opt_update: fix calldatacopy source length
Jun 28, 2023
68e820d
add prev bytes and refactor copy event (#569)
DreamWuGit Jun 30, 2023
5d0916c
sync & resolve upstream conflict
DreamWuGit Jun 30, 2023
b0f2fdb
fix returndatacopy and state test (#582)
DreamWuGit Jun 30, 2023
30d5a9f
memory_opt_update: fix copy_circuit_invalid_tx_log with a more flexib…
Jun 30, 2023
bbbcd9c
memory_opt_update: remove outdated constraint on log
Jun 30, 2023
26676b8
Revert "memory_opt_update: in log, use extend_for_range"
Jun 30, 2023
46079ec
fix state circuit: value_prev column is initial_value for first acces…
DreamWuGit Jul 3, 2023
fb5ae3e
memory_opt_update: in log, use extend_for_range
Jun 30, 2023
b1ed261
memory_opt_circuit: constrain is_tx_log
Jul 3, 2023
cb92aa1
memory_opt_update: fix check_rw_lookup again
Jul 3, 2023
e14d157
fix precompile prev bytes (#590)
lightsing Jul 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ use ethers_core::{
};
use ethers_providers::JsonRpcClient;
pub use execution::{
CopyDataType, CopyEvent, CopyStep, ExecState, ExecStep, ExpEvent, ExpStep, NumberOrHash,
CopyBytes, CopyDataType, CopyEvent, CopyStep, ExecState, ExecStep, ExpEvent, ExpStep,
NumberOrHash,
};
use hex::decode_to_slice;

Expand Down
46 changes: 38 additions & 8 deletions bus-mapping/src/circuit_input_builder/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ impl_expr!(CopyDataType, u64::from);
pub struct CopyStep {
/// Byte value copied in this step.
pub value: u8,
/// Byte value before this step.
pub prev_value: Option<u8>,
/// mask indicates this byte won't be copied.
pub mask: bool,
/// Optional field which is enabled only for the source being `bytecode`,
Expand All @@ -336,6 +338,34 @@ pub enum NumberOrHash {
Hash(H256),
}

/// Represents all bytes related in one copy event.
#[derive(Clone, Debug)]
pub struct CopyBytes {
/// Represents the list of (bytes, is_code, mask) copied during this copy event
pub bytes: Vec<(u8, bool, bool)>,
/// Represents the list of (bytes, is_code, mask) read to copy during this copy event, used for
/// memory to memoryb write case
pub aux_bytes: Option<Vec<(u8, bool, bool)>>,
/// Represents the list of bytes before this copy event, it is reuqired for memory write copy
/// event
pub bytes_write_prev: Option<Vec<u8>>,
}

impl CopyBytes {
/// construct CopyBytes instance
pub fn new(
bytes: Vec<(u8, bool, bool)>,
aux_bytes: Option<Vec<(u8, bool, bool)>>,
bytes_write_prev: Option<Vec<u8>>,
) -> Self {
Self {
bytes,
aux_bytes,
bytes_write_prev,
}
}
}

/// Defines a copy event associated with EVM opcodes such as CALLDATACOPY,
/// CODECOPY, CREATE, etc. More information:
/// <https://github.com/privacy-scaling-explorations/zkevm-specs/blob/master/specs/copy-proof.md>.
Expand All @@ -360,13 +390,12 @@ pub struct CopyEvent {
pub log_id: Option<u64>,
/// Value of rw counter at start of this copy event
pub rw_counter_start: RWCounter,
/// Represents the list of (bytes, is_code, mask) copied during this copy event
pub bytes: CopyEventSteps,
/// Represents the list of (bytes, is_code, mask) read to copy during this copy event
pub aux_bytes: Option<CopyEventSteps>,
/// Represents the list of bytes related during this copy event
pub copy_bytes: CopyBytes,
}

pub type CopyEventSteps = Vec<(u8, bool, bool)>;
pub type CopyEventPrevBytes = Vec<u8>;

impl CopyEvent {
/// rw counter at step index
Expand All @@ -388,7 +417,7 @@ impl CopyEvent {

// // step_index == self.bytes.len() when caculate total rw increasing.
if self.dst_type == CopyDataType::TxLog
&& step_index != self.bytes.len() * 2
&& step_index != self.copy_bytes.bytes.len() * 2
&& step_index % 64 == 63
{
// log writing
Expand All @@ -400,16 +429,17 @@ impl CopyEvent {

/// rw counter increase left at step index
pub fn rw_counter_increase_left(&self, step_index: usize) -> u64 {
if self.rw_counter_step(self.bytes.len() * 2) < self.rw_counter_step(step_index) {
if self.rw_counter_step(self.copy_bytes.bytes.len() * 2) < self.rw_counter_step(step_index)
{
panic!("prev rw_counter_step > total tw_counter");
}
// self.rw_counter_step(self.bytes.len() * 2) - self.rw_counter_step(step_index)
self.rw_counter_step(self.bytes.len() * 2) - self.rw_counter_step(step_index)
self.rw_counter_step(self.copy_bytes.bytes.len() * 2) - self.rw_counter_step(step_index)
}

/// Number of rw operations performed by this copy event
pub fn rw_counter_delta(&self) -> u64 {
self.rw_counter_increase(self.bytes.len() * 2)
self.rw_counter_increase(self.copy_bytes.bytes.len() * 2)
}

// increase in rw counter from the start of the copy event to step index
Expand Down
Loading