Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(blockifier): fix some u128 gas cost remainings #2204

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions crates/blockifier/src/execution/native/syscall_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl<'state> StarknetSyscallHandler for &mut NativeSyscallHandler<'state> {

match syscall_base::get_block_hash_base(self.context, block_number, self.state) {
Ok(value) => Ok(value),
Err(e) => Err(self.handle_error(remaining_gas, e.into())),
Err(e) => Err(self.handle_error(remaining_gas, e)),
}
}

Expand Down Expand Up @@ -411,8 +411,7 @@ impl<'state> StarknetSyscallHandler for &mut NativeSyscallHandler<'state> {
storage_address: self.call.storage_address,
caller_address: self.call.caller_address,
call_type: CallType::Delegate,
initial_gas: u64::try_from(*remaining_gas)
.expect("Failed to convert gas (u128 -> u64)"),
initial_gas: *remaining_gas,
};

Ok(self.execute_inner_call(entry_point, remaining_gas)?.0)
Expand Down Expand Up @@ -450,8 +449,7 @@ impl<'state> StarknetSyscallHandler for &mut NativeSyscallHandler<'state> {
storage_address: contract_address,
caller_address: self.call.caller_address,
call_type: CallType::Call,
initial_gas: u64::try_from(*remaining_gas)
.expect("Failed to convert gas from u128 to u64."),
initial_gas: *remaining_gas,
};

Ok(self.execute_inner_call(entry_point, remaining_gas)?.0)
Expand Down Expand Up @@ -578,9 +576,8 @@ impl<'state> StarknetSyscallHandler for &mut NativeSyscallHandler<'state> {

// TODO(Ori, 1/2/2024): Write an indicative expect message explaining why the conversion
// works.
let n_rounds_as_u128 = u64::try_from(n_rounds).expect("Failed to convert usize to u128.");
let gas_cost =
n_rounds_as_u128 * u64::from(self.context.gas_costs().keccak_round_cost_gas_cost);
let n_rounds = u64::try_from(n_rounds).expect("Failed to convert usize to u64.");
let gas_cost = n_rounds * self.context.gas_costs().keccak_round_cost_gas_cost;

if gas_cost > *remaining_gas {
return Err(self.handle_error(
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/fee/gas_usage_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn starknet_resources() -> StarknetResources {
.map(|call_info| call_info.with_some_class_hash())
.collect();
let execution_summary =
CallInfo::summarize_many(call_infos.iter(), &VersionedConstants::latest_constants());
CallInfo::summarize_many(call_infos.iter(), VersionedConstants::latest_constants());
let state_resources = StateResources::new_for_testing(StateChangesCount {
n_storage_updates: 7,
n_class_hash_updates: 11,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/fee/receipt_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ fn test_calculate_tx_gas_usage(
let execution_call_info =
&tx_execution_info.execute_call_info.expect("Execution call info should exist.");
let execution_summary =
CallInfo::summarize_many(vec![execution_call_info].into_iter(), &versioned_constants);
CallInfo::summarize_many(vec![execution_call_info].into_iter(), versioned_constants);
let starknet_resources = StarknetResources::new(
calldata_length,
signature_length,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/test_utils/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl FeatureContract {
#[cfg(feature = "cairo_native")]
if CairoVersion::Native == self.cairo_version() {
let native_contract_class =
NativeContractClassV1::compile_or_get_cached(&self.get_compiled_path()).into();
NativeContractClassV1::compile_or_get_cached(&self.get_compiled_path());
return RunnableContractClass::V1Native(native_contract_class);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/objects_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn test_events_counter_in_tx_execution_info(
};

assert_eq!(
tx_execution_info.summarize(&VersionedConstants::latest_constants()).event_summary.n_events,
tx_execution_info.summarize(VersionedConstants::latest_constants()).event_summary.n_events,
n_validate_events + n_execute_events + n_fee_transfer_events + n_inner_calls
);
}
Expand Down
Loading