This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 857
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
circuit for invalid creation code (#1292)
### Description circuit for invalid creation code error in create, markdown spec privacy-scaling-explorations/zkevm-specs#400 ### Issue Link issue #1291 ### Type of change - [x] New feature (non-breaking change which adds functionality) ### Rationale Get first byte of code to store , check it is 0xef This PR contains: - buss mapping: at the return opcode in create, get the first byte . - add circuit & test - add tx deploy trace test . --------- Co-authored-by: Steven Gu <[email protected]>
- Loading branch information
1 parent
a884ae0
commit 3733326
Showing
11 changed files
with
446 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
bus-mapping/src/evm/opcodes/error_invalid_creation_code.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::{ | ||
circuit_input_builder::{CircuitInputStateRef, ExecStep}, | ||
error::ExecError, | ||
evm::Opcode, | ||
Error, | ||
}; | ||
use eth_types::{evm_types::INVALID_INIT_CODE_FIRST_BYTE, GethExecStep}; | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
pub struct ErrorCreationCode; | ||
|
||
impl Opcode for ErrorCreationCode { | ||
fn gen_associated_ops( | ||
state: &mut CircuitInputStateRef, | ||
geth_steps: &[GethExecStep], | ||
) -> Result<Vec<ExecStep>, Error> { | ||
let geth_step = &geth_steps[0]; | ||
let mut exec_step = state.new_step(geth_step)?; | ||
exec_step.error = Some(ExecError::InvalidCreationCode); | ||
|
||
let offset = geth_step.stack.nth_last(0)?; | ||
let length = geth_step.stack.nth_last(1)?; | ||
state.stack_read(&mut exec_step, geth_step.stack.nth_last_filled(0), offset)?; | ||
state.stack_read(&mut exec_step, geth_step.stack.nth_last_filled(1), length)?; | ||
|
||
let call = state.call()?; | ||
assert!(call.is_create() && !length.is_zero()); | ||
|
||
// Read the first byte of init code and check it must be 0xef for this error. | ||
let init_code_first_byte = state.call_ctx()?.memory.0[offset.as_usize()]; | ||
state.memory_read(&mut exec_step, offset.try_into()?, init_code_first_byte)?; | ||
assert_eq!(init_code_first_byte, INVALID_INIT_CODE_FIRST_BYTE); | ||
|
||
state.handle_return(&mut exec_step, geth_steps, true)?; | ||
Ok(vec![exec_step]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.