From 1c48823f6619506442fdc866c8f40d6f84ac102b Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Sun, 7 Jul 2024 15:09:53 +0300 Subject: [PATCH] chore: set config pointers for size validation --- crates/gateway/src/lib.rs | 1 + crates/gateway/src/pointers.rs | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 crates/gateway/src/pointers.rs diff --git a/crates/gateway/src/lib.rs b/crates/gateway/src/lib.rs index b9f60e709..853086e4d 100644 --- a/crates/gateway/src/lib.rs +++ b/crates/gateway/src/lib.rs @@ -5,6 +5,7 @@ pub mod compiler_version; pub mod config; pub mod errors; pub mod gateway; +pub mod pointers; pub mod rpc_objects; pub mod rpc_state_reader; pub mod state_reader; diff --git a/crates/gateway/src/pointers.rs b/crates/gateway/src/pointers.rs new file mode 100644 index 000000000..cda8f4947 --- /dev/null +++ b/crates/gateway/src/pointers.rs @@ -0,0 +1,43 @@ +/// Deal with config pointers. +use std::sync::OnceLock; + +use papyrus_config::dumping::ser_pointer_target_param; +use papyrus_config::{ParamPath, SerializedParam}; + +type ConfigPointers = Vec<((ParamPath, SerializedParam), Vec)>; + +const MAX_BYTECODE_SIZE: usize = 50_000; +const MAX_RAW_CLASS_SIZE: usize = 1_000_000; + +pub fn config_pointers() -> ConfigPointers { + static CONFIG_POINTERS: OnceLock = OnceLock::new(); + CONFIG_POINTERS + .get_or_init(|| { + vec![ + ( + ser_pointer_target_param( + "max_bytecode_size", + &MAX_BYTECODE_SIZE, + "The maximum bytecode size allowed for a contract.", + ), + vec![ + "gateway_config.stateless_tx_validator_config.max_bytecode_size".to_owned(), + "gateway_config.gateway_compiler_config.max_bytecode_size".to_owned(), + ], + ), + ( + ser_pointer_target_param( + "max_raw_class_size", + &MAX_RAW_CLASS_SIZE, + "The maximum raw class size allowed for a contract.", + ), + vec![ + "gateway_config.stateless_tx_validator_config.max_raw_class_size" + .to_owned(), + "gateway_config.gateway_compiler_config.max_raw_class_size".to_owned(), + ], + ), + ] + }) + .to_vec() +}