Skip to content

Commit

Permalink
Stop decoding instructions after finding an invalid opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed Jan 10, 2025
1 parent 00d9527 commit 9a022ba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/edr_solidity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ alloy-sol-types = { version = "0.7.4", default-features = false, features = ["st
edr_eth = { version = "0.3.5", path = "../edr_eth" }
edr_evm = { version = "0.3.5", path = "../edr_evm" }
indexmap = { version = "2", features = ["serde"] }
log = { version = "0.4.17", default-features = false }
parking_lot = { version = "0.12.1", default-features = false }
serde = { version = "1.0.158", default-features = false, features = ["std"] }
serde_json = { version = "1.0.89", features = ["preserve_order"] }
Expand Down
10 changes: 7 additions & 3 deletions crates/edr_solidity/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use std::sync::Arc;

use edr_evm::interpreter::OpCode;
use log::debug;

use crate::build_model::{BuildModel, Instruction, JumpType, SourceLocation};

Expand Down Expand Up @@ -159,9 +160,12 @@ pub fn decode_instructions(
let source_map = &source_maps[instructions.len()];

let pc = bytes_index;
let opcode = match OpCode::new(bytecode[pc]) {
Some(opcode) => opcode,
None => continue,
let opcode = if let Some(opcode) = OpCode::new(bytecode[pc]) { opcode } else {
debug!("Invalid opcode {} at pc: {}", bytecode[pc], pc);

// We assume this happens because the source maps point to the metadata region of the bytecode.
// That means that the actual instructions have already been decoded and we can stop here.
return instructions;
};

let push_data = if opcode.is_push() {
Expand Down

0 comments on commit 9a022ba

Please sign in to comment.