From ea67d3c5b9c4584a31e2546cb9fc878cd28e0520 Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Sun, 7 Jul 2024 12:48:35 +0300 Subject: [PATCH] chore: add supported builtins config --- crates/gateway/src/compilation.rs | 18 ++-------------- crates/gateway/src/compilation_config.rs | 27 +++++++++++++++++++++--- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/crates/gateway/src/compilation.rs b/crates/gateway/src/compilation.rs index 58ec1869b..d3ce5cd6c 100644 --- a/crates/gateway/src/compilation.rs +++ b/crates/gateway/src/compilation.rs @@ -1,5 +1,4 @@ use std::panic; -use std::sync::OnceLock; use blockifier::execution::contract_class::{ClassInfo, ContractClass, ContractClassV1}; use cairo_lang_starknet_classes::casm_contract_class::{ @@ -76,26 +75,13 @@ impl GatewayCompiler { for entry_point in entry_points_iterator { let builtins = &entry_point.builtins; - if !is_subsequence(builtins, supported_builtins()) { + if !is_subsequence(builtins, &self.config.supported_builtins) { return Err(GatewayError::UnsupportedBuiltins { builtins: builtins.clone(), - supported_builtins: supported_builtins().to_vec(), + supported_builtins: self.config.supported_builtins.to_vec(), }); } } Ok(()) } } - -// TODO(Arni): Add to a config. -// TODO(Arni): Use the Builtin enum from Starknet-api, and explicitly tag each builtin as supported -// or unsupported so that the compiler would alert us on new builtins. -fn supported_builtins() -> &'static Vec { - static SUPPORTED_BUILTINS: OnceLock> = OnceLock::new(); - SUPPORTED_BUILTINS.get_or_init(|| { - // The OS expects this order for the builtins. - const SUPPORTED_BUILTIN_NAMES: [&str; 7] = - ["pedersen", "range_check", "ecdsa", "bitwise", "ec_op", "poseidon", "segment_arena"]; - SUPPORTED_BUILTIN_NAMES.iter().map(|builtin| builtin.to_string()).collect::>() - }) -} diff --git a/crates/gateway/src/compilation_config.rs b/crates/gateway/src/compilation_config.rs index 155b81cda..146553cff 100644 --- a/crates/gateway/src/compilation_config.rs +++ b/crates/gateway/src/compilation_config.rs @@ -1,15 +1,36 @@ use std::collections::BTreeMap; +use std::sync::OnceLock; use papyrus_config::dumping::SerializeConfig; use papyrus_config::{ParamPath, SerializedParam}; use serde::{Deserialize, Serialize}; use validator::Validate; -#[derive(Clone, Debug, Default, Serialize, Deserialize, Validate, PartialEq)] -pub struct GatewayCompilerConfig {} +#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)] +pub struct GatewayCompilerConfig { + pub supported_builtins: Vec, +} + +impl Default for GatewayCompilerConfig { + fn default() -> Self { + Self { supported_builtins: supported_builtins().clone() } + } +} impl SerializeConfig for GatewayCompilerConfig { fn dump(&self) -> BTreeMap { - BTreeMap::new() + todo!("Impelement GatewayCompilerConfig::dump"); } } + +// TODO(Arni): Use the Builtin enum from Starknet-api, and explicitly tag each builtin as supported +// or unsupported so that the compiler would alert us on new builtins. +fn supported_builtins() -> &'static Vec { + static SUPPORTED_BUILTINS: OnceLock> = OnceLock::new(); + SUPPORTED_BUILTINS.get_or_init(|| { + // The OS expects this order for the builtins. + const SUPPORTED_BUILTIN_NAMES: [&str; 7] = + ["pedersen", "range_check", "ecdsa", "bitwise", "ec_op", "poseidon", "segment_arena"]; + SUPPORTED_BUILTIN_NAMES.iter().map(|builtin| builtin.to_string()).collect::>() + }) +}