diff --git a/src/decommit.rs b/src/decommit.rs index 81496f14..0f9407d2 100644 --- a/src/decommit.rs +++ b/src/decommit.rs @@ -86,7 +86,12 @@ impl WorldDiff { code_hash: U256, ) -> (Vec, bool) { let is_new = !self.decommitted_hashes.add(code_hash); - (world.decommit_code(code_hash), is_new) + let code = world.decommit_code(code_hash); + if is_new { + // Decommitter can process two words per cycle + self.decommit_cycles += (code.len() as u32 + 63) / 64; + } + (code, is_new) } pub(crate) fn pay_for_decommit>( @@ -94,7 +99,7 @@ impl WorldDiff { world: &mut W, decommit: UnpaidDecommit, gas: &mut u32, - ) -> Option<(Program, usize)> { + ) -> Option> { // We intentionally record a decommitment event even if actual decommitment never happens because of an out-of-gas error. // This is how the old VM behaves. let is_new = !self.decommitted_hashes.add(decommit.code_key); @@ -106,13 +111,11 @@ impl WorldDiff { *gas -= decommit.cost; let decommit = world.decommit(decommit.code_key); - let decommit_cycles = if is_new { - (decommit.code_page().len() + 1) / 2 - } else { - 0 - }; + if is_new { + self.decommit_cycles += (decommit.code_page().len() as u32 + 1) / 2; + } - Some((decommit, decommit_cycles)) + Some(decommit) } } diff --git a/src/instruction_handlers/far_call.rs b/src/instruction_handlers/far_call.rs index 154b586b..a473fe65 100644 --- a/src/instruction_handlers/far_call.rs +++ b/src/instruction_handlers/far_call.rs @@ -120,10 +120,9 @@ fn far_call< .expect("stipend must not cause overflow"); let new_frame_is_static = IS_STATIC || vm.state.current_frame.is_static; - vm.state.cycle_counts.code_decommitter_cycles += program.1; vm.push_frame::( u256_into_address(destination_address), - program.0, + program, new_frame_gas, stipend, exception_handler, diff --git a/src/state.rs b/src/state.rs index 372be8b6..f06fed96 100644 --- a/src/state.rs +++ b/src/state.rs @@ -203,7 +203,6 @@ pub struct CycleCounts { pub ecrecover_cycles: usize, pub sha256_cycles: usize, pub secp256v1_verify_cycles: usize, - pub code_decommitter_cycles: usize, } impl PartialEq for CycleCounts { diff --git a/src/world_diff.rs b/src/world_diff.rs index 49d91e33..fbbaaa37 100644 --- a/src/world_diff.rs +++ b/src/world_diff.rs @@ -34,6 +34,7 @@ pub struct WorldDiff { storage_initial_values: BTreeMap<(H160, U256), Option>, pub storage_application_cycles: u32, + pub decommit_cycles: u32, } #[derive(Debug)]