-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathinspector.rs
27 lines (24 loc) · 925 Bytes
/
inspector.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::{HitMap, HitMaps};
use alloy_primitives::Bytes;
use revm::{interpreter::Interpreter, Database, EVMData, Inspector};
#[derive(Clone, Debug, Default)]
pub struct CoverageCollector {
/// Maps that track instruction hit data.
pub maps: HitMaps,
}
impl<DB: Database> Inspector<DB> for CoverageCollector {
#[inline]
fn initialize_interp(&mut self, interpreter: &mut Interpreter<'_>, _: &mut EVMData<'_, DB>) {
let hash = interpreter.contract.hash;
self.maps.entry(hash).or_insert_with(|| {
HitMap::new(Bytes::copy_from_slice(
interpreter.contract.bytecode.original_bytecode_slice(),
))
});
}
#[inline]
fn step(&mut self, interpreter: &mut Interpreter<'_>, _: &mut EVMData<'_, DB>) {
let hash = interpreter.contract.hash;
self.maps.entry(hash).and_modify(|map| map.hit(interpreter.program_counter()));
}
}