Skip to content

Commit

Permalink
adds code decommitter stats
Browse files Browse the repository at this point in the history
  • Loading branch information
montekki committed Aug 21, 2024
1 parent a65bbf7 commit 86dd871
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/decommit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,25 @@ impl WorldDiff {
world: &mut dyn World<T>,
decommit: UnpaidDecommit,
gas: &mut u32,
) -> Option<Program<T>> {
) -> Option<(Program<T>, usize)> {
if decommit.cost > *gas {
// Unlike all other gas costs, this one is not paid if low on gas.
return None;
}
*gas -= decommit.cost;
self.decommitted_hashes.insert(decommit.code_key, ());
Some(world.decommit(decommit.code_key))
let is_old = self
.decommitted_hashes
.insert(decommit.code_key, ())
.is_some();
let decommit = world.decommit(decommit.code_key);

let decommit_cycles = if !is_old {
(decommit.code_page().len() + 1) / 2
} else {
0
};

Some((decommit, decommit_cycles))
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/instruction_handlers/far_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ fn far_call<T: Tracer, M: TypeLevelCallingMode, const IS_STATIC: bool, const IS_
.expect("stipend must not cause overflow");

let new_frame_is_static = IS_STATIC || vm.state.current_frame.is_static;
vm.state.code_decommitter_cycles += program.1;
vm.push_frame::<M>(
u256_into_address(destination_address),
program,
program.0,
new_frame_gas,
stipend,
exception_handler,
Expand Down
1 change: 1 addition & 0 deletions src/single_instruction_test/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl<'a, T: Tracer> Arbitrary<'a> for VirtualMachine<T> {
ecrecover_cycles: 0,
sha256_cycles: 0,
secp256v1_verify_cycles: 0,
code_decommitter_cycles: 0,
},
settings: u.arbitrary()?,
world_diff: Default::default(),
Expand Down
3 changes: 3 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub struct State<T> {

pub secp256v1_verify_cycles: usize,

pub code_decommitter_cycles: usize,

pub(crate) context_u128: u128,
}

Expand Down Expand Up @@ -87,6 +89,7 @@ impl<T> State<T> {
ecrecover_cycles: 0,
sha256_cycles: 0,
secp256v1_verify_cycles: 0,
code_decommitter_cycles: 0,
}
}

Expand Down

0 comments on commit 86dd871

Please sign in to comment.