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

Commit

Permalink
fix: bug - os kzg resources is not zero in old versions (#1942)
Browse files Browse the repository at this point in the history
  • Loading branch information
avi-starkware authored Jun 3, 2024
1 parent e042a43 commit f770f03
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 6 additions & 0 deletions crates/blockifier/src/versioned_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ impl OsResources {
}

fn os_kzg_da_resources(&self, data_segment_length: usize) -> ExecutionResources {
// BACKWARD COMPATIBILITY: we set compute_os_kzg_commitment_info to empty in older versions
// where this was not yet computed.
let empty_resources = ExecutionResources::default();
if self.compute_os_kzg_commitment_info == empty_resources {
return empty_resources;
}
&(&self.compute_os_kzg_commitment_info * data_segment_length)
+ &poseidon_hash_many_cost(data_segment_length)
}
Expand Down
14 changes: 7 additions & 7 deletions crates/blockifier/src/versioned_constants_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ fn test_successful_gas_costs_parsing() {
assert_eq!(versioned_constants.os_constants.gas_costs.step_gas_cost, 2);
assert_eq!(versioned_constants.os_constants.gas_costs.entry_point_initial_budget, 2 * 3); // step_gas_cost * 3.

// entry_point_intial_budget * 4 + step_gas_cost * 5.
// entry_point_initial_budget * 4 + step_gas_cost * 5.
assert_eq!(versioned_constants.os_constants.gas_costs.entry_point_gas_cost, 6 * 4 + 2 * 5);
}

fn get_json_value_without_dafaults() -> serde_json::Value {
fn get_json_value_without_defaults() -> serde_json::Value {
let json_data = r#"
{
"invoke_tx_max_n_steps": 2,
Expand Down Expand Up @@ -77,21 +77,21 @@ fn get_json_value_without_dafaults() -> serde_json::Value {
// Remove defaults from OsConstants.
os_constants.as_object_mut().unwrap().remove("validate_rounding_consts");

let mut json_value_without_defualts: Value = serde_json::from_str(json_data).unwrap();
json_value_without_defualts
let mut json_value_without_defaults: Value = serde_json::from_str(json_data).unwrap();
json_value_without_defaults
.as_object_mut()
.unwrap()
.insert("os_constants".to_string(), os_constants);

json_value_without_defualts
json_value_without_defaults
}

#[test]
fn test_default_values() {
let json_value_without_defualts = get_json_value_without_dafaults();
let json_value_without_defaults = get_json_value_without_defaults();

let versioned_constants: VersionedConstants =
serde_json::from_value(json_value_without_defualts).unwrap();
serde_json::from_value(json_value_without_defaults).unwrap();

assert_eq!(versioned_constants.get_validate_block_number_rounding(), 1);
assert_eq!(versioned_constants.get_validate_timestamp_rounding(), 1);
Expand Down

0 comments on commit f770f03

Please sign in to comment.