Skip to content

Commit

Permalink
Extend gas cost analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Apr 25, 2024
1 parent be9e967 commit 1b68719
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions evm-tests/jsontests/tests/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn run(dir: &str) {
verbose: true,
very_verbose: true,
verbose_failed: true,
print_state: true,
};
for entry in fs::read_dir(dest).unwrap() {
let entry = entry.unwrap();
Expand Down
21 changes: 12 additions & 9 deletions gasometer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ macro_rules! event {
}
#[cfg(feature = "force-debug")]
macro_rules! log_gas {
($self:expr, $($arg:tt)*) => (log::trace!(target: "evm", "Gasometer {} [Gas used: {}, Gas left: {}]", format_args!($($arg)*),
$self.total_used_gas(), $self.gas()));
($self:expr, $($arg:tt)*) => (
log::trace!(target: "evm", "Gasometer {} [Gas used: {}, Gas left: {}]", format_args!($($arg)*),
$self.total_used_gas(), $self.gas());
println!(" Gasometer {} [Gas used: {}, Gas left: {}]", format_args!($($arg)*), $self.total_used_gas(), $self.gas());
);
}

#[cfg(not(feature = "force-debug"))]
Expand Down Expand Up @@ -243,6 +246,13 @@ impl<'config> Gasometer<'config> {
return Err(ExitError::OutOfGas);
}

let after_gas = self.gas_limit - all_gas_cost;
try_or_fail!(self.inner, inner_mut.extra_check(cost, after_gas));

inner_mut.used_gas += gas_cost;
inner_mut.memory_gas = memory_gas;
inner_mut.refunded_gas += gas_refund;

log_gas!(
self,
"Record dynamic cost {} - memory_gas {} - gas_refund {}",
Expand All @@ -251,13 +261,6 @@ impl<'config> Gasometer<'config> {
gas_refund
);

let after_gas = self.gas_limit - all_gas_cost;
try_or_fail!(self.inner, inner_mut.extra_check(cost, after_gas));

inner_mut.used_gas += gas_cost;
inner_mut.memory_gas = memory_gas;
inner_mut.refunded_gas += gas_refund;

Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,6 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
access_list: &[(H160, Vec<H256>)],
) -> Result<(), ExitError> {
let transaction_cost = gasometer::create_transaction_cost(init_code, access_list);
// TODOFEE
println!("record_create_transaction_cost: {record_create_transaction_cost:?}");
let gasometer = &mut self.state.metadata_mut().gasometer;
gasometer.record_transaction(transaction_cost)
}
Expand Down Expand Up @@ -1171,6 +1169,8 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> Interprete
});
}

// TODOFEE
println!("OPCODE: {opcode:?}");
if let Some(cost) = gasometer::static_opcode_cost(opcode) {
self.state
.metadata_mut()
Expand Down

0 comments on commit 1b68719

Please sign in to comment.