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

Commit 0361459

Browse files
authored
remove Memory related codes (#574)
* remove Memory related * update inline doc * remove memory constraints * fix inline doc * remove outdated test
1 parent 5a69b35 commit 0361459

File tree

11 files changed

+58
-275
lines changed

11 files changed

+58
-275
lines changed

bus-mapping/src/circuit_input_builder.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl Default for CircuitsParams {
125125
///
126126
/// The generated bus-mapping operations are:
127127
/// [`StackOp`](crate::operation::StackOp)s,
128-
/// [`MemoryOp`](crate::operation::MemoryOp)s and
128+
/// [`MemoryWordOp`](crate::operation::MemoryWordOp)s and
129129
/// [`StorageOp`](crate::operation::StorageOp), which correspond to each
130130
/// [`OpcodeId`](crate::evm::OpcodeId)s used in each `ExecTrace` step so that
131131
/// the State Proof witnesses are already generated on a structured manner and
@@ -313,7 +313,7 @@ impl<'a> CircuitInputBuilder {
313313
values.1 += step
314314
.bus_mapping_instance
315315
.iter()
316-
.filter(|rw| rw.0 == operation::Target::Memory)
316+
.filter(|rw| rw.0 == operation::Target::MemoryWord)
317317
.count();
318318
values.2 += step
319319
.bus_mapping_instance
@@ -330,7 +330,7 @@ impl<'a> CircuitInputBuilder {
330330
.rev()
331331
{
332332
log::debug!(
333-
"op {:?}, count {}, mem rw {}(avg {:.2}), stack rw {}(avg {:.2})",
333+
"op {:?}, count {}, memory_word rw {}(avg {:.2}), stack rw {}(avg {:.2})",
334334
op,
335335
count,
336336
mem,
@@ -339,7 +339,10 @@ impl<'a> CircuitInputBuilder {
339339
*stack as f32 / *count as f32
340340
);
341341
}
342-
log::debug!("memory num: {}", self.block.container.memory.len());
342+
log::debug!(
343+
"memory_word num: {}",
344+
self.block.container.memory_word.len()
345+
);
343346
log::debug!("stack num: {}", self.block.container.stack.len());
344347
log::debug!("storage num: {}", self.block.container.storage.len());
345348
log::debug!(

bus-mapping/src/circuit_input_builder/input_state_ref.rs

+4-38
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use crate::{
1515
},
1616
exec_trace::OperationRef,
1717
operation::{
18-
AccountField, AccountOp, CallContextField, CallContextOp, MemoryOp, MemoryWordOp, Op,
19-
OpEnum, Operation, StackOp, Target, TxAccessListAccountOp, TxLogField, TxLogOp,
20-
TxReceiptField, TxReceiptOp, RW,
18+
AccountField, AccountOp, CallContextField, CallContextOp, MemoryWordOp, Op, OpEnum,
19+
Operation, StackOp, Target, TxAccessListAccountOp, TxLogField, TxLogOp, TxReceiptField,
20+
TxReceiptOp, RW,
2121
},
2222
precompile::is_precompiled,
2323
state_db::{CodeDB, StateDB},
@@ -214,24 +214,7 @@ impl<'a> CircuitInputStateRef<'a> {
214214
Ok(())
215215
}
216216

217-
/// Push a read type [`MemoryOp`] into the
218-
/// [`OperationContainer`](crate::operation::OperationContainer) with the
219-
/// next [`RWCounter`](crate::operation::RWCounter) and `call_id`, and then
220-
/// adds a reference to the stored operation ([`OperationRef`]) inside
221-
/// the bus-mapping instance of the current [`ExecStep`]. Then increase
222-
/// the `block_ctx` [`RWCounter`](crate::operation::RWCounter) by one.
223-
pub fn memory_read(
224-
&mut self,
225-
step: &mut ExecStep,
226-
address: MemoryAddress,
227-
value: u8,
228-
) -> Result<(), Error> {
229-
let call_id = self.call()?.call_id;
230-
self.push_op(step, RW::READ, MemoryOp::new(call_id, address, value));
231-
Ok(())
232-
}
233-
234-
/// Push a read type [`MemoryOp`] into the
217+
/// Push a read type [`MemoryWordOp`] into the
235218
/// [`OperationContainer`](crate::operation::OperationContainer) with the
236219
/// next [`RWCounter`](crate::operation::RWCounter) and `call_id`, and then
237220
/// adds a reference to the stored operation ([`OperationRef`]) inside
@@ -248,23 +231,6 @@ impl<'a> CircuitInputStateRef<'a> {
248231
Ok(())
249232
}
250233

251-
/// Push a write type [`MemoryOp`] into the
252-
/// [`OperationContainer`](crate::operation::OperationContainer) with the
253-
/// next [`RWCounter`](crate::operation::RWCounter) and `call_id`, and then
254-
/// adds a reference to the stored operation ([`OperationRef`]) inside
255-
/// the bus-mapping instance of the current [`ExecStep`]. Then increase
256-
/// the `block_ctx` [`RWCounter`](crate::operation::RWCounter) by one.
257-
pub fn memory_write(
258-
&mut self,
259-
step: &mut ExecStep,
260-
address: MemoryAddress,
261-
value: u8,
262-
) -> Result<(), Error> {
263-
let call_id = self.call()?.call_id;
264-
self.push_op(step, RW::WRITE, MemoryOp::new(call_id, address, value));
265-
Ok(())
266-
}
267-
268234
/// Push a write type [`MemoryWordOp`] into the
269235
/// [`OperationContainer`](crate::operation::OperationContainer) with the
270236
/// next [`RWCounter`](crate::operation::RWCounter) and `call_id`, and then

bus-mapping/src/evm/opcodes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ use swap::Swap;
132132
/// or multiple [`ExecStep`](crate::circuit_input_builder::ExecStep) depending
133133
/// of the [`OpcodeId`] it contains.
134134
pub trait Opcode: Debug {
135-
/// Generate the associated [`MemoryOp`](crate::operation::MemoryOp)s,
135+
/// Generate the associated [`MemoryWordOp`](crate::operation::MemoryWordOp)s,
136136
/// [`StackOp`](crate::operation::StackOp)s, and
137137
/// [`StorageOp`](crate::operation::StorageOp)s associated to the Opcode
138138
/// is implemented for.

bus-mapping/src/evm/opcodes/mload.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use log::trace;
99
/// Placeholder structure used to implement [`Opcode`] trait over it
1010
/// corresponding to the [`OpcodeId::MLOAD`](crate::evm::OpcodeId::MLOAD)
1111
/// `OpcodeId`. This is responsible of generating all of the associated
12-
/// [`crate::operation::StackOp`]s and [`crate::operation::MemoryOp`]s and place
12+
/// [`crate::operation::StackOp`]s and [`crate::operation::MemoryWordOp`]s and place
1313
/// them inside the trace's [`crate::operation::OperationContainer`].
1414
#[derive(Debug, Copy, Clone)]
1515
pub(crate) struct Mload;

bus-mapping/src/exec_trace.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ impl fmt::Debug for OperationRef {
1414
"OperationRef{{ {}, {} }}",
1515
match self.0 {
1616
Target::Start => "Start",
17-
Target::Memory => "Memory",
1817
Target::MemoryWord => "MemoryWord",
1918
Target::Stack => "Stack",
2019
Target::Storage => "Storage",

bus-mapping/src/operation.rs

+6-87
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Collection of structs and functions used to:
2-
//! - Define the internals of a [`MemoryOp`], [`StackOp`] and [`StorageOp`].
2+
//! - Define the internals of a [`MemoryWordOp`], [`StackOp`] and [`StorageOp`].
33
//! - Define the actual operation types and a wrapper over them (the [`Operation`] enum).
44
//! - Define structures that interact with operations such as [`OperationContainer`].
55
pub(crate) mod container;
@@ -86,8 +86,6 @@ impl RWCounter {
8686
pub enum Target {
8787
/// Start is a padding operation.
8888
Start,
89-
/// Means the target of the operation is the Memory.
90-
Memory,
9189
/// Means the target of the operation is the MemoryWord.
9290
MemoryWord,
9391
/// Means the target of the operation is the Stack.
@@ -120,83 +118,6 @@ pub trait Op: Clone + Eq + Ord {
120118
fn reverse(&self) -> Self;
121119
}
122120

123-
/// Represents a [`READ`](RW::READ)/[`WRITE`](RW::WRITE) into the memory implied
124-
/// by an specific [`OpcodeId`](eth_types::evm_types::opcode_ids::OpcodeId) of
125-
/// the [`ExecStep`](crate::circuit_input_builder::ExecStep).
126-
#[derive(Clone, PartialEq, Eq)]
127-
pub struct MemoryOp {
128-
/// Call ID
129-
pub call_id: usize,
130-
/// Memory Address
131-
pub address: MemoryAddress,
132-
/// Value
133-
pub value: u8,
134-
}
135-
136-
impl fmt::Debug for MemoryOp {
137-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
138-
f.write_str("MemoryOp { ")?;
139-
f.write_fmt(format_args!(
140-
"call_id: {:?}, addr: {:?}, value: 0x{:02x}",
141-
self.call_id, self.address, self.value
142-
))?;
143-
f.write_str(" }")
144-
}
145-
}
146-
147-
impl MemoryOp {
148-
/// Create a new instance of a `MemoryOp` from it's components.
149-
pub fn new(call_id: usize, address: MemoryAddress, value: u8) -> MemoryOp {
150-
MemoryOp {
151-
call_id,
152-
address,
153-
value,
154-
}
155-
}
156-
157-
/// Returns the [`Target`] (operation type) of this operation.
158-
pub const fn target(&self) -> Target {
159-
Target::Memory
160-
}
161-
162-
/// Returns the call id associated to this Operation.
163-
pub const fn call_id(&self) -> usize {
164-
self.call_id
165-
}
166-
167-
/// Returns the [`MemoryAddress`] associated to this Operation.
168-
pub const fn address(&self) -> &MemoryAddress {
169-
&self.address
170-
}
171-
172-
/// Returns the bytes read or written by this operation.
173-
pub fn value(&self) -> u8 {
174-
self.value
175-
}
176-
}
177-
178-
impl Op for MemoryOp {
179-
fn into_enum(self) -> OpEnum {
180-
OpEnum::Memory(self)
181-
}
182-
183-
fn reverse(&self) -> Self {
184-
unreachable!("MemoryOp can't be reverted")
185-
}
186-
}
187-
188-
impl PartialOrd for MemoryOp {
189-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
190-
Some(self.cmp(other))
191-
}
192-
}
193-
194-
impl Ord for MemoryOp {
195-
fn cmp(&self, other: &Self) -> Ordering {
196-
(&self.call_id, &self.address).cmp(&(&other.call_id, &other.address))
197-
}
198-
}
199-
200121
// new Memory ops for word value
201122
/// Represents a [`READ`](RW::READ)/[`WRITE`](RW::WRITE) into the memory implied
202123
/// by an specific [`OpcodeId`](eth_types::evm_types::opcode_ids::OpcodeId) of
@@ -223,7 +144,7 @@ impl fmt::Debug for MemoryWordOp {
223144
}
224145

225146
impl MemoryWordOp {
226-
/// Create a new instance of a `MemoryOp` from it's components.
147+
/// Create a new instance of a `MemoryWordOp` from it's components.
227148
pub fn new(call_id: usize, address: MemoryAddress, value: Word) -> MemoryWordOp {
228149
MemoryWordOp {
229150
call_id,
@@ -234,7 +155,7 @@ impl MemoryWordOp {
234155

235156
/// Returns the [`Target`] (operation type) of this operation.
236157
pub const fn target(&self) -> Target {
237-
Target::Memory
158+
Target::MemoryWord
238159
}
239160

240161
/// Returns the call id associated to this Operation.
@@ -259,7 +180,7 @@ impl Op for MemoryWordOp {
259180
}
260181

261182
fn reverse(&self) -> Self {
262-
unreachable!("MemoryOp can't be reverted")
183+
unreachable!("MemoryWordOp can't be reverted")
263184
}
264185
}
265186

@@ -985,13 +906,11 @@ impl Op for TxReceiptOp {
985906
}
986907

987908
/// Generic enum that wraps over all the operation types possible.
988-
/// In particular [`StackOp`], [`MemoryOp`] and [`StorageOp`].
909+
/// In particular [`StackOp`], [`MemoryWordOp`] and [`StorageOp`].
989910
#[derive(Debug, Clone)]
990911
pub enum OpEnum {
991912
/// Stack
992913
Stack(StackOp),
993-
/// Memory
994-
Memory(MemoryOp),
995914
/// Memory word
996915
MemoryWord(MemoryWordOp),
997916
/// Storage
@@ -1159,7 +1078,7 @@ mod operation_tests {
11591078

11601079
let stack_op_as_operation = Operation::new(RWCounter(1), RW::WRITE, stack_op.clone());
11611080

1162-
let memory_op = MemoryOp::new(1, MemoryAddress(0x40), 0x40);
1081+
let memory_op = MemoryWordOp::new(1, MemoryAddress(0x40), Word::from(0x40));
11631082

11641083
let memory_op_as_operation = Operation::new(RWCounter(1), RW::WRITE, memory_op.clone());
11651084

bus-mapping/src/operation/container.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{
2-
AccountOp, CallContextOp, MemoryOp, MemoryWordOp, Op, OpEnum, Operation, RWCounter, StackOp,
3-
StartOp, StorageOp, Target, TxAccessListAccountOp, TxAccessListAccountStorageOp, TxLogOp,
4-
TxReceiptOp, TxRefundOp, RW,
2+
AccountOp, CallContextOp, MemoryWordOp, Op, OpEnum, Operation, RWCounter, StackOp, StartOp,
3+
StorageOp, Target, TxAccessListAccountOp, TxAccessListAccountStorageOp, TxLogOp, TxReceiptOp,
4+
TxRefundOp, RW,
55
};
66
use crate::exec_trace::OperationRef;
77
use itertools::Itertools;
@@ -22,9 +22,7 @@ use itertools::Itertools;
2222
/// order to construct the State proof.
2323
#[derive(Debug, Clone, PartialEq, Eq)]
2424
pub struct OperationContainer {
25-
/// Operations of MemoryOp
26-
pub memory: Vec<Operation<MemoryOp>>,
27-
/// Operations of MemoryOp
25+
/// Operations of MemoryWordOp
2826
pub memory_word: Vec<Operation<MemoryWordOp>>,
2927
/// Operations of StackOp
3028
pub stack: Vec<Operation<StackOp>>,
@@ -59,7 +57,6 @@ impl OperationContainer {
5957
/// Generates a new instance of an `OperationContainer`.
6058
pub fn new() -> Self {
6159
Self {
62-
memory: Vec::new(),
6360
memory_word: Vec::new(),
6461
stack: Vec::new(),
6562
storage: Vec::new(),
@@ -97,10 +94,6 @@ impl OperationContainer {
9794
op_enum: OpEnum,
9895
) -> OperationRef {
9996
match op_enum {
100-
OpEnum::Memory(op) => {
101-
self.memory.push(Operation::new(rwc, rw, op));
102-
OperationRef::from((Target::Memory, self.memory.len() - 1))
103-
}
10497
OpEnum::MemoryWord(op) => {
10598
self.memory_word.push(Operation::new(rwc, rw, op));
10699
//TODO: use new Target type i.e. MemoryWord
@@ -175,10 +168,10 @@ impl OperationContainer {
175168
}
176169
}
177170

178-
/// Returns a sorted vector of all of the [`MemoryOp`]s contained inside of
171+
/// Returns a sorted vector of all of the [`MemoryWordOp`]s contained inside of
179172
/// the container.
180-
pub fn sorted_memory(&self) -> Vec<Operation<MemoryOp>> {
181-
self.memory.iter().sorted().cloned().collect()
173+
pub fn sorted_memory_word(&self) -> Vec<Operation<MemoryWordOp>> {
174+
self.memory_word.iter().sorted().cloned().collect()
182175
}
183176

184177
/// Returns a sorted vector of all of the [`StackOp`]s contained inside of
@@ -216,7 +209,7 @@ mod container_test {
216209
let memory_operation = Operation::new(
217210
global_counter.inc_pre(),
218211
RW::WRITE,
219-
MemoryOp::new(1, MemoryAddress::from(1), 1),
212+
MemoryWordOp::new(1, MemoryAddress::from(1), 1.into()),
220213
);
221214
let storage_operation = Operation::new(
222215
global_counter.inc_pre(),
@@ -235,10 +228,13 @@ mod container_test {
235228
let storage_ref = operation_container.insert(storage_operation.clone());
236229

237230
assert_eq!(operation_container.sorted_stack()[0], stack_operation);
238-
assert_eq!(operation_container.sorted_memory()[0], memory_operation);
231+
assert_eq!(
232+
operation_container.sorted_memory_word()[0],
233+
memory_operation
234+
);
239235
assert_eq!(operation_container.sorted_storage()[0], storage_operation);
240236
assert_eq!(stack_ref, OperationRef::from((Target::Stack, 0)));
241-
assert_eq!(memory_ref, OperationRef::from((Target::Memory, 0)));
237+
assert_eq!(memory_ref, OperationRef::from((Target::MemoryWord, 0)));
242238
assert_eq!(storage_ref, OperationRef::from((Target::Storage, 0)));
243239
}
244240
}

0 commit comments

Comments
 (0)