Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: set config pointers for size validation #384

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod compiler_version;
pub mod config;
pub mod errors;
pub mod gateway;
pub mod pointers;
mod rpc_objects;
mod rpc_state_reader;
#[cfg(test)]
Expand Down
44 changes: 44 additions & 0 deletions crates/gateway/src/pointers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/// Deals 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<ParamPath>)>;

const MAX_BYTECODE_SIZE: usize = 81_920;
const MAX_RAW_CLASS_SIZE: usize = 4_089_446; // (3.9 * 2_f32.pow(20)) as usize;

// TODO(Arni): Use this to code dedup.
pub fn config_pointers() -> ConfigPointers {
static CONFIG_POINTERS: OnceLock<ConfigPointers> = 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()
}
Loading