Skip to content

Commit

Permalink
expose cycles statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
montekki committed Aug 21, 2024
1 parent 085a91e commit a65bbf7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/instruction_handlers/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ fn precompile_call<T: Tracer>(
let heaps = &mut vm.state.heaps;
match address_low {
KECCAK256_ROUND_FUNCTION_PRECOMPILE_ADDRESS => {
keccak256_rounds_function::<_, false>(0, query, heaps);
vm.state.keccak256_cycles +=
keccak256_rounds_function::<_, false>(0, query, heaps).0;
}
SHA256_ROUND_FUNCTION_PRECOMPILE_ADDRESS => {
sha256_rounds_function::<_, false>(0, query, heaps);
vm.state.sha256_cycles += sha256_rounds_function::<_, false>(0, query, heaps).0;
}
ECRECOVER_INNER_FUNCTION_PRECOMPILE_ADDRESS => {
ecrecover_function::<_, false>(0, query, heaps);
vm.state.ecrecover_cycles += ecrecover_function::<_, false>(0, query, heaps).0;
}
SECP256R1_VERIFY_PRECOMPILE_ADDRESS => {
secp256r1_verify_function::<_, false>(0, query, heaps);
vm.state.secp256v1_verify_cycles +=
secp256r1_verify_function::<_, false>(0, query, heaps).0;
}
_ => {
// A precompile call may be used just to burn gas
Expand Down
4 changes: 4 additions & 0 deletions src/single_instruction_test/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ impl<'a, T: Tracer> Arbitrary<'a> for VirtualMachine<T> {
heaps,
transaction_number: u.arbitrary()?,
context_u128: u.arbitrary()?,
keccak256_cycles: 0,
ecrecover_cycles: 0,
sha256_cycles: 0,
secp256v1_verify_cycles: 0,
},
settings: u.arbitrary()?,
world_diff: Default::default(),
Expand Down
12 changes: 12 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ pub struct State<T> {

pub transaction_number: u16,

pub keccak256_cycles: usize,

pub ecrecover_cycles: usize,

pub sha256_cycles: usize,

pub secp256v1_verify_cycles: usize,

pub(crate) context_u128: u128,
}

Expand Down Expand Up @@ -75,6 +83,10 @@ impl<T> State<T> {

transaction_number: 0,
context_u128: 0,
keccak256_cycles: 0,
ecrecover_cycles: 0,
sha256_cycles: 0,
secp256v1_verify_cycles: 0,
}
}

Expand Down

0 comments on commit a65bbf7

Please sign in to comment.