diff --git a/Cargo.lock b/Cargo.lock index 85357f624f..069fcafe91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -386,7 +386,7 @@ dependencies = [ [[package]] name = "blockifier" -version = "0.5.0-rc.1" +version = "0.5.0-rc.2" dependencies = [ "anyhow", "ark-ec", @@ -2108,7 +2108,7 @@ dependencies = [ [[package]] name = "native_blockifier" -version = "0.5.0-rc.1" +version = "0.5.0-rc.2" dependencies = [ "blockifier", "cached", diff --git a/Cargo.toml b/Cargo.toml index b7544512d2..b2b5436e9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ resolver = "2" members = ["crates/blockifier", "crates/native_blockifier"] [workspace.package] -version = "0.5.0-rc.1" +version = "0.5.0-rc.2" edition = "2021" repository = "https://github.com/starkware-libs/blockifier/" license = "Apache-2.0" diff --git a/crates/blockifier/resources/versioned_constants.json b/crates/blockifier/resources/versioned_constants.json index 1d1f9ccb73..a106d9da7e 100644 --- a/crates/blockifier/resources/versioned_constants.json +++ b/crates/blockifier/resources/versioned_constants.json @@ -1,7 +1,7 @@ { - "event_size_limit": { - "max_data_length": 40, - "max_keys_length": 40, + "tx_event_limits": { + "max_data_length": 300, + "max_keys_length": 50, "max_n_emitted_events": 1000 }, "gateway": { @@ -166,289 +166,283 @@ "os_resources": { "execute_syscalls": { "CallContract": { + "n_steps": 760, "builtin_instance_counter": { "range_check_builtin": 20 }, - "n_memory_holes": 0, - "n_steps": 760 + "n_memory_holes": 0 }, "DelegateCall": { + "n_steps": 713, "builtin_instance_counter": { "range_check_builtin": 19 }, - "n_memory_holes": 0, - "n_steps": 713 + "n_memory_holes": 0 }, "DelegateL1Handler": { + "n_steps": 692, "builtin_instance_counter": { "range_check_builtin": 15 }, - "n_memory_holes": 0, - "n_steps": 692 + "n_memory_holes": 0 }, "Deploy": { + "n_steps": 1012, "builtin_instance_counter": { "pedersen_builtin": 7, "range_check_builtin": 19 }, - "n_memory_holes": 0, - "n_steps": 1012 + "n_memory_holes": 0 }, "EmitEvent": { + "n_steps": 61, "builtin_instance_counter": { "range_check_builtin": 1 }, - "n_memory_holes": 0, - "n_steps": 61 + "n_memory_holes": 0 }, "GetBlockHash": { + "n_steps": 104, "builtin_instance_counter": { "range_check_builtin": 2 }, - "n_memory_holes": 0, - "n_steps": 104 + "n_memory_holes": 0 }, "GetBlockNumber": { + "n_steps": 40, "builtin_instance_counter": {}, - "n_memory_holes": 0, - "n_steps": 40 + "n_memory_holes": 0 }, "GetBlockTimestamp": { + "n_steps": 38, "builtin_instance_counter": {}, - "n_memory_holes": 0, - "n_steps": 38 + "n_memory_holes": 0 }, "GetCallerAddress": { + "n_steps": 64, "builtin_instance_counter": { "range_check_builtin": 1 }, - "n_memory_holes": 0, - "n_steps": 64 + "n_memory_holes": 0 }, "GetContractAddress": { + "n_steps": 64, "builtin_instance_counter": { "range_check_builtin": 1 }, - "n_memory_holes": 0, - "n_steps": 64 + "n_memory_holes": 0 }, "GetExecutionInfo": { + "n_steps": 64, "builtin_instance_counter": { "range_check_builtin": 1 }, - "n_memory_holes": 0, - "n_steps": 64 + "n_memory_holes": 0 }, "GetSequencerAddress": { + "n_steps": 34, "builtin_instance_counter": {}, - "n_memory_holes": 0, - "n_steps": 34 + "n_memory_holes": 0 }, "GetTxInfo": { + "n_steps": 64, "builtin_instance_counter": { "range_check_builtin": 1 }, - "n_memory_holes": 0, - "n_steps": 64 + "n_memory_holes": 0 }, "GetTxSignature": { + "n_steps": 44, "builtin_instance_counter": {}, - "n_memory_holes": 0, - "n_steps": 44 + "n_memory_holes": 0 }, "Keccak": { + "n_steps": 381, "builtin_instance_counter": { "bitwise_builtin": 6, "keccak_builtin": 1, "range_check_builtin": 56 }, - "n_memory_holes": 0, - "n_steps": 381 + "n_memory_holes": 0 }, "LibraryCall": { + "n_steps": 751, "builtin_instance_counter": { "range_check_builtin": 20 }, - "n_memory_holes": 0, - "n_steps": 751 + "n_memory_holes": 0 }, "LibraryCallL1Handler": { + "n_steps": 659, "builtin_instance_counter": { "range_check_builtin": 15 }, - "n_memory_holes": 0, - "n_steps": 659 + "n_memory_holes": 0 }, "ReplaceClass": { + "n_steps": 98, "builtin_instance_counter": { "range_check_builtin": 1 }, - "n_memory_holes": 0, - "n_steps": 98 + "n_memory_holes": 0 }, "Secp256k1Add": { + "n_steps": 408, "builtin_instance_counter": { "range_check_builtin": 29 }, - "n_memory_holes": 0, - "n_steps": 408 + "n_memory_holes": 0 }, "Secp256k1GetPointFromX": { + "n_steps": 393, "builtin_instance_counter": { "range_check_builtin": 30 }, - "n_memory_holes": 0, - "n_steps": 393 + "n_memory_holes": 0 }, "Secp256k1GetXy": { + "n_steps": 205, "builtin_instance_counter": { "range_check_builtin": 11 }, - "n_memory_holes": 0, - "n_steps": 205 + "n_memory_holes": 0 }, "Secp256k1Mul": { + "n_steps": 76503, "builtin_instance_counter": { "range_check_builtin": 7045 }, - "n_memory_holes": 0, - "n_steps": 76503 + "n_memory_holes": 0 }, "Secp256k1New": { + "n_steps": 459, "builtin_instance_counter": { "range_check_builtin": 35 }, - "n_memory_holes": 0, - "n_steps": 459 + "n_memory_holes": 0 }, "Secp256r1Add": { + "n_steps": 591, "builtin_instance_counter": { "range_check_builtin": 57 }, - "n_memory_holes": 0, - "n_steps": 591 + "n_memory_holes": 0 }, "Secp256r1GetPointFromX": { + "n_steps": 512, "builtin_instance_counter": { "range_check_builtin": 44 }, - "n_memory_holes": 0, - "n_steps": 512 + "n_memory_holes": 0 }, "Secp256r1GetXy": { + "n_steps": 207, "builtin_instance_counter": { "range_check_builtin": 11 }, - "n_memory_holes": 0, - "n_steps": 207 + "n_memory_holes": 0 }, "Secp256r1Mul": { + "n_steps": 125342, "builtin_instance_counter": { "range_check_builtin": 13961 }, - "n_memory_holes": 0, - "n_steps": 125342 + "n_memory_holes": 0 }, "Secp256r1New": { + "n_steps": 578, "builtin_instance_counter": { "range_check_builtin": 49 }, - "n_memory_holes": 0, - "n_steps": 578 + "n_memory_holes": 0 }, "SendMessageToL1": { + "n_steps": 139, "builtin_instance_counter": { "range_check_builtin": 1 }, - "n_memory_holes": 0, - "n_steps": 139 + "n_memory_holes": 0 }, "StorageRead": { + "n_steps": 87, "builtin_instance_counter": { "range_check_builtin": 1 }, - "n_memory_holes": 0, - "n_steps": 87 + "n_memory_holes": 0 }, "StorageWrite": { + "n_steps": 89, "builtin_instance_counter": { "range_check_builtin": 1 }, - "n_memory_holes": 0, - "n_steps": 89 + "n_memory_holes": 0 } }, "execute_txs_inner": { "Declare": { "constant": { + "n_steps": 2839, "builtin_instance_counter": { "pedersen_builtin": 16, "range_check_builtin": 63 }, - "n_memory_holes": 0, - "n_steps": 2839 + "n_memory_holes": 0 }, "calldata_factor": { - "builtin_instance_counter": { - "pedersen_builtin": 0, - "range_check_builtin": 0 - }, - "n_memory_holes": 0, - "n_steps": 0 + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 } }, "DeployAccount": { "constant": { + "n_steps": 3792, "builtin_instance_counter": { "pedersen_builtin": 23, "range_check_builtin": 83 }, - "n_memory_holes": 0, - "n_steps": 3792 + "n_memory_holes": 0 }, "calldata_factor": { + "n_steps": 21, "builtin_instance_counter": { - "pedersen_builtin": 2, - "range_check_builtin": 0 + "pedersen_builtin": 2 }, - "n_memory_holes": 0, - "n_steps": 21 + "n_memory_holes": 0 } }, "InvokeFunction": { "constant": { + "n_steps": 3546, "builtin_instance_counter": { "pedersen_builtin": 14, "range_check_builtin": 80 }, - "n_memory_holes": 0, - "n_steps": 3546 + "n_memory_holes": 0 }, "calldata_factor": { + "n_steps": 8, "builtin_instance_counter": { - "pedersen_builtin": 1, - "range_check_builtin": 0 + "pedersen_builtin": 1 }, - "n_memory_holes": 0, - "n_steps": 8 + "n_memory_holes": 0 } }, "L1Handler": { "constant": { + "n_steps": 1146, "builtin_instance_counter": { "pedersen_builtin": 11, "range_check_builtin": 17 }, - "n_memory_holes": 0, - "n_steps": 1146 + "n_memory_holes": 0 }, "calldata_factor": { + "n_steps": 13, "builtin_instance_counter": { - "pedersen_builtin": 1, - "range_check_builtin": 0 + "pedersen_builtin": 1 }, - "n_memory_holes": 0, - "n_steps": 13 + "n_memory_holes": 0 } } }, diff --git a/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs b/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs index 1bdb7ed646..40be6b335e 100644 --- a/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs +++ b/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs @@ -527,7 +527,7 @@ fn test_emit_event() { ); // Negative flow, the data length exceeds the limit. - let max_event_data_length = versioned_constants.event_size_limit.max_data_length; + let max_event_data_length = versioned_constants.tx_event_limits.max_data_length; let data_too_long = vec![stark_felt!(2_u16); max_event_data_length + 1]; let error = emit_events(&n_emitted_events, &keys, &data_too_long).unwrap_err(); let expected_error = EmitEventError::ExceedsMaxDataLength { @@ -537,7 +537,7 @@ fn test_emit_event() { assert!(error.to_string().contains(format!("{}", expected_error).as_str())); // Negative flow, the keys length exceeds the limit. - let max_event_keys_length = versioned_constants.event_size_limit.max_keys_length; + let max_event_keys_length = versioned_constants.tx_event_limits.max_keys_length; let keys_too_long = vec![stark_felt!(1_u16); max_event_keys_length + 1]; let error = emit_events(&n_emitted_events, &keys_too_long, &data).unwrap_err(); let expected_error = EmitEventError::ExceedsMaxKeysLength { @@ -547,7 +547,7 @@ fn test_emit_event() { assert!(error.to_string().contains(format!("{}", expected_error).as_str())); // Negative flow, the number of events exceeds the limit. - let max_n_emitted_events = versioned_constants.event_size_limit.max_n_emitted_events; + let max_n_emitted_events = versioned_constants.tx_event_limits.max_n_emitted_events; let n_emitted_events_too_big = vec![stark_felt!( u16::try_from(max_n_emitted_events + 1).expect("Failed to convert usize to u16.") )]; diff --git a/crates/blockifier/src/execution/syscalls/mod.rs b/crates/blockifier/src/execution/syscalls/mod.rs index 3de87a3d24..c75111a394 100644 --- a/crates/blockifier/src/execution/syscalls/mod.rs +++ b/crates/blockifier/src/execution/syscalls/mod.rs @@ -29,7 +29,7 @@ use crate::execution::execution_utils::{ }; use crate::execution::syscalls::hint_processor::{INVALID_INPUT_LENGTH_ERROR, OUT_OF_GAS_ERROR}; use crate::transaction::transaction_utils::update_remaining_gas; -use crate::versioned_constants::VersionedConstants; +use crate::versioned_constants::{EventLimits, VersionedConstants}; pub mod hint_processor; mod secp; @@ -293,19 +293,18 @@ pub fn exceeds_event_size_limit( n_emitted_events: usize, event: &EventContent, ) -> Result<(), EmitEventError> { - let max_n_emitted_events = versioned_constants.event_size_limit.max_n_emitted_events; + let EventLimits { max_data_length, max_keys_length, max_n_emitted_events } = + versioned_constants.tx_event_limits; if n_emitted_events > max_n_emitted_events { return Err(EmitEventError::ExceedsMaxNumberOfEmittedEvents { n_emitted_events, max_n_emitted_events, }); } - let max_keys_length = versioned_constants.event_size_limit.max_keys_length; let keys_length = event.keys.len(); - if keys_length > versioned_constants.event_size_limit.max_keys_length { + if keys_length > max_keys_length { return Err(EmitEventError::ExceedsMaxKeysLength { keys_length, max_keys_length }); } - let max_data_length = versioned_constants.event_size_limit.max_data_length; let data_length = event.data.0.len(); if data_length > max_data_length { return Err(EmitEventError::ExceedsMaxDataLength { data_length, max_data_length }); diff --git a/crates/blockifier/src/execution/syscalls/syscalls_test.rs b/crates/blockifier/src/execution/syscalls/syscalls_test.rs index 622e2946da..99a65f9da5 100644 --- a/crates/blockifier/src/execution/syscalls/syscalls_test.rs +++ b/crates/blockifier/src/execution/syscalls/syscalls_test.rs @@ -135,7 +135,7 @@ fn test_emit_event() { ); // Negative flow, the data length exceeds the limit. - let max_event_data_length = versioned_constants.event_size_limit.max_data_length; + let max_event_data_length = versioned_constants.tx_event_limits.max_data_length; let data_too_long = vec![stark_felt!(2_u16); max_event_data_length + 1]; let error = emit_events(&n_emitted_events, &keys, &data_too_long).unwrap_err(); let expected_error = EmitEventError::ExceedsMaxDataLength { @@ -145,7 +145,7 @@ fn test_emit_event() { assert!(error.to_string().contains(format!("{}", expected_error).as_str())); // Negative flow, the keys length exceeds the limit. - let max_event_keys_length = versioned_constants.event_size_limit.max_keys_length; + let max_event_keys_length = versioned_constants.tx_event_limits.max_keys_length; let keys_too_long = vec![stark_felt!(1_u16); max_event_keys_length + 1]; let error = emit_events(&n_emitted_events, &keys_too_long, &data).unwrap_err(); let expected_error = EmitEventError::ExceedsMaxKeysLength { @@ -155,7 +155,7 @@ fn test_emit_event() { assert!(error.to_string().contains(format!("{}", expected_error).as_str())); // Negative flow, the number of events exceeds the limit. - let max_n_emitted_events = versioned_constants.event_size_limit.max_n_emitted_events; + let max_n_emitted_events = versioned_constants.tx_event_limits.max_n_emitted_events; let n_emitted_events_too_big = vec![stark_felt!( u16::try_from(max_n_emitted_events + 1).expect("Failed to convert usize to u16.") )]; diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index bf31d8cfeb..bab1be110e 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -1840,15 +1840,15 @@ fn test_execute_tx_with_invalid_transaction_version() { } fn max_n_emitted_events() -> usize { - VERSIONED_CONSTANTS.event_size_limit.max_n_emitted_events + VERSIONED_CONSTANTS.tx_event_limits.max_n_emitted_events } fn max_event_keys() -> usize { - VERSIONED_CONSTANTS.event_size_limit.max_keys_length + VERSIONED_CONSTANTS.tx_event_limits.max_keys_length } fn max_event_data() -> usize { - VERSIONED_CONSTANTS.event_size_limit.max_data_length + VERSIONED_CONSTANTS.tx_event_limits.max_data_length } #[test_case( diff --git a/crates/blockifier/src/versioned_constants.rs b/crates/blockifier/src/versioned_constants.rs index 987cb1c89a..77ac130aad 100644 --- a/crates/blockifier/src/versioned_constants.rs +++ b/crates/blockifier/src/versioned_constants.rs @@ -36,8 +36,8 @@ static DEFAULT_CONSTANTS: Lazy = Lazy::new(|| { #[derive(Clone, Debug, Default, Deserialize)] pub struct VersionedConstants { // Limits. - #[serde(default = "EventSizeLimit::max")] - pub event_size_limit: EventSizeLimit, + #[serde(default = "EventLimits::max")] + pub tx_event_limits: EventLimits, pub invoke_tx_max_n_steps: u32, #[serde(default)] pub l2_resource_gas_costs: L2ResourceGasCosts, @@ -171,14 +171,14 @@ pub struct L2ResourceGasCosts { pub milligas_per_code_byte: u128, } -#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)] -pub struct EventSizeLimit { +#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq)] +pub struct EventLimits { pub max_data_length: usize, pub max_keys_length: usize, pub max_n_emitted_events: usize, } -impl EventSizeLimit { +impl EventLimits { fn max() -> Self { Self { max_data_length: usize::MAX, diff --git a/crates/blockifier/src/versioned_constants_test.rs b/crates/blockifier/src/versioned_constants_test.rs index 70d3ddfc05..c7992d6492 100644 --- a/crates/blockifier/src/versioned_constants_test.rs +++ b/crates/blockifier/src/versioned_constants_test.rs @@ -67,7 +67,7 @@ fn test_default_values() { assert_eq!(versioned_constants.get_validate_block_number_rounding(), 1); assert_eq!(versioned_constants.get_validate_timestamp_rounding(), 1); - assert_eq!(versioned_constants.event_size_limit, EventSizeLimit::max()); + assert_eq!(versioned_constants.tx_event_limits, EventLimits::max()); assert_eq!(versioned_constants.l2_resource_gas_costs, L2ResourceGasCosts::default()); // Calldata factor was initialized as 0, and did not affect the expected result, even if