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

Commit

Permalink
Identity (dataCopy) precompile (#1628)
Browse files Browse the repository at this point in the history
### 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]>
  • Loading branch information
3 people authored Dec 12, 2023
1 parent 66788d7 commit fe9beeb
Show file tree
Hide file tree
Showing 49 changed files with 2,773 additions and 527 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*.png
.DS_Store
.vscode
.idea
.idea
*.log
22 changes: 19 additions & 3 deletions bus-mapping/src/circuit_input_builder/execution.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//! Execution step related module.

use crate::{
circuit_input_builder::CallContext, error::ExecError, exec_trace::OperationRef,
circuit_input_builder::CallContext,
error::{ExecError, OogError},
exec_trace::OperationRef,
operation::RWCounter,
precompile::PrecompileCalls,
};
use eth_types::{evm_types::OpcodeId, GethExecStep, Word, H256};
use gadgets::impl_expr;
Expand Down Expand Up @@ -60,6 +63,7 @@ impl ExecStep {
ExecStep {
exec_state: ExecState::Op(step.op),
pc: step.pc,

stack_size: step.stack.0.len(),
memory_size: call_ctx.memory.len(),
gas_left: step.gas,
Expand Down Expand Up @@ -117,13 +121,25 @@ impl ExecStep {
assert_eq!(memory_size % n_bytes_word, 0);
memory_size / n_bytes_word
}

/// Returns `true` if this is an execution step of Precompile.
pub fn is_precompiled(&self) -> bool {
matches!(self.exec_state, ExecState::Precompile(_))
}

/// Returns `true` if `error` is oog in precompile calls
pub fn is_precompile_oog_err(&self) -> bool {
matches!(self.error, Some(ExecError::OutOfGas(OogError::Precompile)))
}
}

/// Execution state
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ExecState {
/// EVM Opcode ID
Op(OpcodeId),
/// Precompile call
Precompile(PrecompileCalls),
/// Virtual step Begin Tx
BeginTx,
/// Virtual step End Tx
Expand Down Expand Up @@ -279,14 +295,14 @@ impl CopyEvent {
// increase in rw counter from the start of the copy event to step index
fn rw_counter_increase(&self, step_index: usize) -> u64 {
let source_rw_increase = match self.src_type {
CopyDataType::Bytecode | CopyDataType::TxCalldata => 0,
CopyDataType::Bytecode | CopyDataType::TxCalldata | CopyDataType::RlcAcc => 0,
CopyDataType::Memory => std::cmp::min(
u64::try_from(step_index + 1).unwrap() / 2,
self.src_addr_end
.checked_sub(self.src_addr)
.unwrap_or_default(),
),
CopyDataType::RlcAcc | CopyDataType::TxLog | CopyDataType::Padding => unreachable!(),
CopyDataType::TxLog | CopyDataType::Padding => unreachable!(),
};
let destination_rw_increase = match self.dst_type {
CopyDataType::RlcAcc | CopyDataType::Bytecode => 0,
Expand Down
Loading

0 comments on commit fe9beeb

Please sign in to comment.