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

Commit

Permalink
feat: add more constants toVersionedConstants
Browse files Browse the repository at this point in the history
- Add gateway constants, these are only for transparency, and aren't
  used directly by the Blockifier whatsoever.
- Pass `validate_max_n_steps` into the blockifier via native_blockifier,
  to override versioned constants defaults.
- Sort json
  • Loading branch information
Gilad Chase committed Jan 29, 2024
1 parent fe0dad0 commit 37ce931
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
25 changes: 14 additions & 11 deletions crates/blockifier/resources/versioned_constants.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"gateway": {
"max_calldata_length": 4000,
"max_contract_bytecode_size": 61440
},
"invoke_tx_max_n_steps": 3000000,
"max_recursion_depth": 50,
"validate_max_n_steps": 1000000,
"vm_resource_fee_cost": {

"bitwise_builtin":0.32,
"ec_op_builtin":5.12,
"ecdsa_builtin":10.24,
"keccak_builtin":10.24,
"bitwise_builtin": 0.32,
"ec_op_builtin": 5.12,
"ecdsa_builtin": 10.24,
"keccak_builtin": 10.24,
"n_steps": 0.005,
"output_builtin": 0,
"pedersen_builtin": 0.16,
"poseidon_builtin":0.16,
"range_check_builtin":0.08
},
"invoke_tx_max_n_steps": 3000000,
"max_recursion_depth": 50,
"validate_max_n_steps": 1000000
"poseidon_builtin": 0.16,
"range_check_builtin": 0.08
}
}
3 changes: 3 additions & 0 deletions crates/blockifier/src/versioned_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ static DEFAULT_CONSTANTS: Lazy<VersionedConstants> = Lazy::new(|| {
.expect("Versioned constants json file is malformed")
});

/// Contains constants for the Blockifier that may vary between versions.
/// Additional constants in the JSON file, not used by Blockifier but included for transparency, are
/// automatically ignored during deserialization.
#[derive(Clone, Debug, Default, Deserialize)]
pub struct VersionedConstants {
// Fee related.
Expand Down
6 changes: 4 additions & 2 deletions crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ pub struct PyBlockExecutor {
#[pymethods]
impl PyBlockExecutor {
#[new]
#[pyo3(signature = (general_config, max_recursion_depth, global_contract_cache_size, target_storage_config))]
#[pyo3(signature = (general_config, validate_max_n_steps, max_recursion_depth, global_contract_cache_size, target_storage_config))]
pub fn create(
general_config: PyGeneralConfig,
validate_max_n_steps: u32,
max_recursion_depth: usize,
global_contract_cache_size: usize,
target_storage_config: StorageConfig,
) -> Self {
log::debug!("Initializing Block Executor...");
let storage =
PapyrusStorage::new(target_storage_config).expect("Failed to initialize storage");
let versioned_constants = versioned_constants_with_overrides(max_recursion_depth);
let versioned_constants =
versioned_constants_with_overrides(validate_max_n_steps, max_recursion_depth);
log::debug!("Initialized Block Executor.");

Self {
Expand Down
11 changes: 9 additions & 2 deletions crates/native_blockifier/src/py_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ where
Ok(obj.getattr(attr)?.extract()?)
}

pub fn versioned_constants_with_overrides(max_recursion_depth: usize) -> VersionedConstants {
VersionedConstants { max_recursion_depth, ..VersionedConstants::latest_constants().clone() }
pub fn versioned_constants_with_overrides(
validate_max_n_steps: u32,
max_recursion_depth: usize,
) -> VersionedConstants {
VersionedConstants {
validate_max_n_steps,
max_recursion_depth,
..VersionedConstants::latest_constants().clone()
}
}
7 changes: 4 additions & 3 deletions crates/native_blockifier/src/py_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@ pub struct PyValidator {
#[pymethods]
impl PyValidator {
#[new]
#[pyo3(signature = (general_config, state_reader_proxy, next_block_info, max_recursion_depth, global_contract_cache_size, max_nonce_for_validation_skip))]
#[pyo3(signature = (general_config, state_reader_proxy, next_block_info, validate_max_n_steps, max_recursion_depth, global_contract_cache_size, max_nonce_for_validation_skip))]
pub fn create(
general_config: PyGeneralConfig,
state_reader_proxy: &PyAny,
next_block_info: PyBlockInfo,
validate_max_n_steps: u32,
max_recursion_depth: usize,
global_contract_cache_size: usize,
max_nonce_for_validation_skip: PyFelt,
) -> NativeBlockifierResult<Self> {
let versioned_constants = versioned_constants_with_overrides(max_recursion_depth);
let versioned_constants =
versioned_constants_with_overrides(validate_max_n_steps, max_recursion_depth);

let tx_executor = TransactionExecutor::new(
PyStateReader::new(state_reader_proxy),
&general_config,
// TODO(Gilad): add max_validate_n_steps override argument and override here.
&versioned_constants,
next_block_info,
GlobalContractCache::new(global_contract_cache_size),
Expand Down

0 comments on commit 37ce931

Please sign in to comment.