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

Commit fe9beeb

Browse files
darth-cyroynalnarutolispc
authored
Identity (dataCopy) precompile (#1628)
### Description This is a follow-up PR for [PR#1396](#1396) from @roynalnaruto. After merging in 1396's changes to a fresh fork, the branch is compared with Scroll's develop head to incorporate latest patterns on precompile-related development. ### Issue Link [Aggregating precompile issue 924](#924) ### 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 ### Design choices See [documentation](https://www.notion.so/scrollzkp/PR-1396-Follow-up-Precompile-Identity-for-Upstream-3624af055d9b4820a0354e9af4fa7918) --------- Co-authored-by: Rohit Narurkar <[email protected]> Co-authored-by: Zhang Zhuo <[email protected]>
1 parent 66788d7 commit fe9beeb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2773
-527
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
*.png
33
.DS_Store
44
.vscode
5-
.idea
5+
.idea
6+
*.log

bus-mapping/src/circuit_input_builder/execution.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
//! Execution step related module.
22
33
use crate::{
4-
circuit_input_builder::CallContext, error::ExecError, exec_trace::OperationRef,
4+
circuit_input_builder::CallContext,
5+
error::{ExecError, OogError},
6+
exec_trace::OperationRef,
57
operation::RWCounter,
8+
precompile::PrecompileCalls,
69
};
710
use eth_types::{evm_types::OpcodeId, GethExecStep, Word, H256};
811
use gadgets::impl_expr;
@@ -60,6 +63,7 @@ impl ExecStep {
6063
ExecStep {
6164
exec_state: ExecState::Op(step.op),
6265
pc: step.pc,
66+
6367
stack_size: step.stack.0.len(),
6468
memory_size: call_ctx.memory.len(),
6569
gas_left: step.gas,
@@ -117,13 +121,25 @@ impl ExecStep {
117121
assert_eq!(memory_size % n_bytes_word, 0);
118122
memory_size / n_bytes_word
119123
}
124+
125+
/// Returns `true` if this is an execution step of Precompile.
126+
pub fn is_precompiled(&self) -> bool {
127+
matches!(self.exec_state, ExecState::Precompile(_))
128+
}
129+
130+
/// Returns `true` if `error` is oog in precompile calls
131+
pub fn is_precompile_oog_err(&self) -> bool {
132+
matches!(self.error, Some(ExecError::OutOfGas(OogError::Precompile)))
133+
}
120134
}
121135

122136
/// Execution state
123137
#[derive(Clone, Debug, Eq, PartialEq)]
124138
pub enum ExecState {
125139
/// EVM Opcode ID
126140
Op(OpcodeId),
141+
/// Precompile call
142+
Precompile(PrecompileCalls),
127143
/// Virtual step Begin Tx
128144
BeginTx,
129145
/// Virtual step End Tx
@@ -279,14 +295,14 @@ impl CopyEvent {
279295
// increase in rw counter from the start of the copy event to step index
280296
fn rw_counter_increase(&self, step_index: usize) -> u64 {
281297
let source_rw_increase = match self.src_type {
282-
CopyDataType::Bytecode | CopyDataType::TxCalldata => 0,
298+
CopyDataType::Bytecode | CopyDataType::TxCalldata | CopyDataType::RlcAcc => 0,
283299
CopyDataType::Memory => std::cmp::min(
284300
u64::try_from(step_index + 1).unwrap() / 2,
285301
self.src_addr_end
286302
.checked_sub(self.src_addr)
287303
.unwrap_or_default(),
288304
),
289-
CopyDataType::RlcAcc | CopyDataType::TxLog | CopyDataType::Padding => unreachable!(),
305+
CopyDataType::TxLog | CopyDataType::Padding => unreachable!(),
290306
};
291307
let destination_rw_increase = match self.dst_type {
292308
CopyDataType::RlcAcc | CopyDataType::Bytecode => 0,

0 commit comments

Comments
 (0)