Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Add os resources to versioned constants
Browse files Browse the repository at this point in the history
- Move hardcoded os resources json into the versioned constants json,
  move `OsResources` into into `OsResources` module.
- Delete os_usage.rs: all logic is now called from methods in
  `VersionedConstants`(todo: extract into submodules, currently
  just a big module).
- Delete os_usage_test.rs: these are not post-deserialize validations of
  `OsResources`.
- the rest are getters and patching things up.
  • Loading branch information
Gilad Chase committed Jan 29, 2024
1 parent 717e323 commit 7430754
Show file tree
Hide file tree
Showing 9 changed files with 392 additions and 108 deletions.
250 changes: 250 additions & 0 deletions crates/blockifier/resources/versioned_constants.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,254 @@
{
"os_resources": {
"execute_syscalls": {
"CallContract": {
"builtin_instance_counter": {
"range_check_builtin": 20
},
"n_memory_holes": 4,
"n_steps": 760
},
"DelegateCall": {
"builtin_instance_counter": {
"range_check_builtin": 19
},
"n_memory_holes": 0,
"n_steps": 713
},
"DelegateL1Handler": {
"builtin_instance_counter": {
"range_check_builtin": 15
},
"n_memory_holes": 0,
"n_steps": 692
},
"Deploy": {
"builtin_instance_counter": {
"pedersen_builtin": 7,
"range_check_builtin": 19
},
"n_memory_holes": 13,
"n_steps": 1010
},
"EmitEvent": {
"builtin_instance_counter": {
"range_check_builtin": 1
},
"n_memory_holes": 0,
"n_steps": 61
},
"GetBlockHash": {
"builtin_instance_counter": {
"range_check_builtin": 2
},
"n_memory_holes": 0,
"n_steps": 74
},
"GetBlockNumber": {
"builtin_instance_counter": {},
"n_memory_holes": 0,
"n_steps": 40
},
"GetBlockTimestamp": {
"builtin_instance_counter": {},
"n_memory_holes": 0,
"n_steps": 38
},
"GetCallerAddress": {
"builtin_instance_counter": {
"range_check_builtin": 1
},
"n_memory_holes": 0,
"n_steps": 62
},
"GetContractAddress": {
"builtin_instance_counter": {
"range_check_builtin": 1
},
"n_memory_holes": 0,
"n_steps": 62
},
"GetExecutionInfo": {
"builtin_instance_counter": {
"range_check_builtin": 1
},
"n_memory_holes": 0,
"n_steps": 62
},
"GetSequencerAddress": {
"builtin_instance_counter": {},
"n_memory_holes": 0,
"n_steps": 34
},
"GetTxInfo": {
"builtin_instance_counter": {
"range_check_builtin": 1
},
"n_memory_holes": 0,
"n_steps": 62
},
"GetTxSignature": {
"builtin_instance_counter": {},
"n_memory_holes": 0,
"n_steps": 44
},
"Keccak": {
"builtin_instance_counter": {
"bitwise_builtin": 6,
"keccak_builtin": 1,
"range_check_builtin": 56
},
"n_memory_holes": 0,
"n_steps": 381
},
"LibraryCall": {
"builtin_instance_counter": {
"range_check_builtin": 20
},
"n_memory_holes": 4,
"n_steps": 751
},
"LibraryCallL1Handler": {
"builtin_instance_counter": {
"range_check_builtin": 15
},
"n_memory_holes": 0,
"n_steps": 659
},
"ReplaceClass": {
"builtin_instance_counter": {
"range_check_builtin": 1
},
"n_memory_holes": 0,
"n_steps": 98
},
"Secp256k1Add": {
"builtin_instance_counter": {
"range_check_builtin": 29
},
"n_memory_holes": 0,
"n_steps": 406
},
"Secp256k1GetPointFromX": {
"builtin_instance_counter": {
"range_check_builtin": 30
},
"n_memory_holes": 18,
"n_steps": 391
},
"Secp256k1GetXy": {
"builtin_instance_counter": {
"range_check_builtin": 11
},
"n_memory_holes": 40,
"n_steps": 239
},
"Secp256k1Mul": {
"builtin_instance_counter": {
"range_check_builtin": 7045
},
"n_memory_holes": 2,
"n_steps": 76501
},
"Secp256k1New": {
"builtin_instance_counter": {
"range_check_builtin": 35
},
"n_memory_holes": 40,
"n_steps": 475
},
"Secp256r1Add": {
"builtin_instance_counter": {
"range_check_builtin": 57
},
"n_memory_holes": 0,
"n_steps": 589
},
"Secp256r1GetPointFromX": {
"builtin_instance_counter": {
"range_check_builtin": 44
},
"n_memory_holes": 20,
"n_steps": 510
},
"Secp256r1GetXy": {
"builtin_instance_counter": {
"range_check_builtin": 11
},
"n_memory_holes": 40,
"n_steps": 241
},
"Secp256r1Mul": {
"builtin_instance_counter": {
"range_check_builtin": 13961
},
"n_memory_holes": 2,
"n_steps": 125340
},
"Secp256r1New": {
"builtin_instance_counter": {
"range_check_builtin": 49
},
"n_memory_holes": 40,
"n_steps": 594
},
"SendMessageToL1": {
"builtin_instance_counter": {
"range_check_builtin": 1
},
"n_memory_holes": 0,
"n_steps": 139
},
"StorageRead": {
"builtin_instance_counter": {
"range_check_builtin": 1
},
"n_memory_holes": 0,
"n_steps": 87
},
"StorageWrite": {
"builtin_instance_counter": {
"range_check_builtin": 1
},
"n_memory_holes": 0,
"n_steps": 89
}
},
"execute_txs_inner": {
"Declare": {
"builtin_instance_counter": {
"pedersen_builtin": 15,
"range_check_builtin": 63
},
"n_memory_holes": 66,
"n_steps": 2843
},
"DeployAccount": {
"builtin_instance_counter": {
"pedersen_builtin": 23,
"range_check_builtin": 83
},
"n_memory_holes": 82,
"n_steps": 3798
},
"InvokeFunction": {
"builtin_instance_counter": {
"pedersen_builtin": 16,
"range_check_builtin": 80
},
"n_memory_holes": 68,
"n_steps": 3549
},
"L1Handler": {
"builtin_instance_counter": {
"pedersen_builtin": 11,
"range_check_builtin": 17
},
"n_memory_holes": 0,
"n_steps": 1157
}
}
},
"starknet_os_constants": {
"nop_entry_point_offset": -1,
"entry_point_type_external": 0,
Expand Down
9 changes: 6 additions & 3 deletions crates/blockifier/src/execution/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::execution::common_hints::ExecutionMode;
use crate::execution::deprecated_syscalls::hint_processor::SyscallCounter;
use crate::execution::errors::{EntryPointExecutionError, PreExecutionError};
use crate::execution::execution_utils::execute_entry_point_call;
use crate::fee::os_resources::OS_RESOURCES;
use crate::state::state_api::State;
use crate::transaction::objects::{HasRelatedFeeType, TransactionExecutionResult, TransactionInfo};
use crate::transaction::transaction_types::TransactionType;
Expand Down Expand Up @@ -287,7 +286,7 @@ impl EntryPointExecutionContext {
.map(|call_info| call_info.vm_resources.n_steps)
.unwrap_or_default();

let overhead_steps = OS_RESOURCES.resources_for_tx_type(tx_type).n_steps;
let overhead_steps = self.versioned_constants().resources_for_tx_type(tx_type).n_steps;
self.subtract_steps(validate_steps + overhead_steps)
}

Expand All @@ -308,8 +307,12 @@ impl EntryPointExecutionContext {
.join("\n")
}

pub fn versioned_constants(&self) -> &VersionedConstants {
&self.tx_context.block_context.versioned_constants
}

pub fn get_gas_cost(&self, name: &str) -> u64 {
self.tx_context.block_context.versioned_constants.gas_cost(name)
self.versioned_constants().gas_cost(name)
}
}

Expand Down
2 changes: 0 additions & 2 deletions crates/blockifier/src/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ pub mod eth_gas_constants;
pub mod fee_checks;
pub mod fee_utils;
pub mod gas_usage;
pub mod os_resources;
pub mod os_usage;
1 change: 1 addition & 0 deletions crates/blockifier/src/fee/actual_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ impl<'a> ActualCostBuilder<'a> {
)?;

let mut actual_resources = calculate_tx_resources(
&self.tx_context.block_context.versioned_constants,
execution_resources,
l1_gas_and_blob_gas_usage,
self.tx_type,
Expand Down
3 changes: 1 addition & 2 deletions crates/blockifier/src/fee/gas_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::abi::constants;
use crate::context::BlockContext;
use crate::execution::call_info::{CallInfo, MessageL1CostInfo};
use crate::fee::eth_gas_constants;
use crate::fee::os_resources::OS_RESOURCES;
use crate::state::cached_state::StateChangesCount;
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::objects::{
Expand Down Expand Up @@ -195,7 +194,7 @@ pub fn estimate_minimal_l1_gas(
tx: &AccountTransaction,
) -> TransactionPreValidationResult<GasAndBlobGasUsages> {
// TODO(Dori, 1/8/2023): Give names to the constant VM step estimates and regression-test them.
let os_steps_for_type = OS_RESOURCES.resources_for_tx_type(&tx.tx_type()).n_steps;
let os_steps_for_type = versioned_constants.resources_for_tx_type(&tx.tx_type()).n_steps;
let gas_cost: usize = match tx {
// We consider the following state changes: sender balance update (storage update) + nonce
// increment (contract modification) (we exclude the sequencer balance update and the ERC20
Expand Down
57 changes: 0 additions & 57 deletions crates/blockifier/src/fee/os_usage.rs

This file was deleted.

Loading

0 comments on commit 7430754

Please sign in to comment.