Skip to content

Commit

Permalink
Disable SELFDESTRUCT for feature scroll. (scroll-tech#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
silathdiir authored Apr 12, 2023
1 parent 23c3f9c commit 4122042
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bus-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ rand = "0.8"
[features]
default = ["test"]
test = ["mock", "rand"]
scroll = []
scroll = ["eth-types/scroll"]
8 changes: 4 additions & 4 deletions bus-mapping/src/circuit_input_builder/input_state_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,14 +1242,14 @@ impl<'a> CircuitInputStateRef<'a> {
step: &GethExecStep,
next_step: Option<&GethExecStep>,
) -> Result<Option<ExecError>, Error> {
if let Some(error) = &step.error {
return Ok(Some(get_step_reported_error(&step.op, error)));
}

if matches!(step.op, OpcodeId::INVALID(_)) {
return Ok(Some(ExecError::InvalidOpcode));
}

if let Some(error) = &step.error {
return Ok(Some(get_step_reported_error(&step.op, error)));
}

let call = self.call()?;

if matches!(next_step, None) {
Expand Down
1 change: 1 addition & 0 deletions eth-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ poseidon-circuit = { git = "https://github.com/scroll-tech/poseidon-circuit.git"
[features]
default = ["warn-unimplemented"]
warn-unimplemented = []
scroll = []
4 changes: 4 additions & 0 deletions eth-types/src/evm_types/opcode_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,7 @@ impl From<u8> for OpcodeId {
0xf2u8 => OpcodeId::CALLCODE,
0xf4u8 => OpcodeId::DELEGATECALL,
0xfau8 => OpcodeId::STATICCALL,
#[cfg(not(feature = "scroll"))]
0xffu8 => OpcodeId::SELFDESTRUCT,
b => OpcodeId::INVALID(b),
}
Expand Down Expand Up @@ -1200,6 +1201,9 @@ impl FromStr for OpcodeId {
"CALLCODE" => OpcodeId::CALLCODE,
"DELEGATECALL" => OpcodeId::DELEGATECALL,
"STATICCALL" => OpcodeId::STATICCALL,
#[cfg(feature = "scroll")]
"SELFDESTRUCT" => OpcodeId::INVALID(0xffu8),
#[cfg(not(feature = "scroll"))]
"SELFDESTRUCT" => OpcodeId::SELFDESTRUCT,
"CHAINID" => OpcodeId::CHAINID,
"BASEFEE" => OpcodeId::BASEFEE,
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ serde_json = "1.0.78"
[features]
default = ["test", "test-circuits", "enable-sign-verify"]
test = ["ethers-signers", "mock", "bus-mapping/test"]
scroll = ["bus-mapping/scroll", "zktrie", "enable-sign-verify", "reject-eip2718", "poseidon-codehash"]
scroll = ["bus-mapping/scroll", "eth-types/scroll", "zktrie", "enable-sign-verify", "reject-eip2718", "poseidon-codehash"]
test-circuits = []
warn-unimplemented = ["eth-types/warn-unimplemented"]
onephase = [] # debug only
Expand Down
7 changes: 6 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ pub(crate) struct ExecutionConfig<F> {
returndatacopy_gadget: Box<ReturnDataCopyGadget<F>>,
create_gadget: Box<CreateGadget<F, false, { ExecutionState::CREATE }>>,
create2_gadget: Box<CreateGadget<F, true, { ExecutionState::CREATE2 }>>,
#[cfg(not(feature = "scroll"))]
selfdestruct_gadget: Box<DummyGadget<F, 1, 0, { ExecutionState::SELFDESTRUCT }>>,
signed_comparator_gadget: Box<SignedComparatorGadget<F>>,
signextend_gadget: Box<SignextendGadget<F>>,
Expand Down Expand Up @@ -566,6 +567,7 @@ impl<F: Field> ExecutionConfig<F> {
returndatacopy_gadget: configure_gadget!(),
create_gadget: configure_gadget!(),
create2_gadget: configure_gadget!(),
#[cfg(not(feature = "scroll"))]
selfdestruct_gadget: configure_gadget!(),
shl_shr_gadget: configure_gadget!(),
signed_comparator_gadget: configure_gadget!(),
Expand Down Expand Up @@ -1363,7 +1365,10 @@ impl<F: Field> ExecutionConfig<F> {
ExecutionState::CREATE2 => assign_exec_step!(self.create2_gadget),
// dummy gadgets
ExecutionState::EXTCODECOPY => assign_exec_step!(self.extcodecopy_gadget),
ExecutionState::SELFDESTRUCT => assign_exec_step!(self.selfdestruct_gadget),
ExecutionState::SELFDESTRUCT => {
#[cfg(not(feature = "scroll"))]
assign_exec_step!(self.selfdestruct_gadget)
}
// end of dummy gadgets
ExecutionState::SHA3 => assign_exec_step!(self.sha3_gadget),
ExecutionState::SHL_SHR => assign_exec_step!(self.shl_shr_gadget),
Expand Down
15 changes: 13 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/error_invalid_opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ impl<F: Field> ExecutionGadget<F> for ErrorInvalidOpcodeGadget<F> {
call: &Call,
step: &ExecStep,
) -> Result<(), Error> {
let opcode = F::from(step.opcode.unwrap().as_u64());
self.opcode.assign(region, offset, Value::known(opcode))?;
let opcode = step.opcode.unwrap().as_u64();
self.opcode
.assign(region, offset, Value::known(F::from(opcode)))?;

log::debug!("ErrorInvalidOpcode - opcode = {}", opcode);

self.common_error_gadget
.assign(region, offset, block, call, step, 2)?;
Expand Down Expand Up @@ -98,6 +101,14 @@ mod test {
}
}

#[cfg(feature = "scroll")]
#[test]
fn invalid_opcode_selfdestruct_for_scroll() {
let selfdestruct_opcode = 0xff_u8;
test_root_ok(&[selfdestruct_opcode]);
test_internal_ok(0x20, 0x00, &[selfdestruct_opcode]);
}

fn test_root_ok(invalid_code: &[u8]) {
let mut code = Bytecode::default();
invalid_code.iter().for_each(|b| {
Expand Down

0 comments on commit 4122042

Please sign in to comment.