Skip to content

Commit

Permalink
chore: add supported builtins config
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Jul 10, 2024
1 parent 152b7ca commit 63eae8e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
18 changes: 2 additions & 16 deletions crates/gateway/src/compilation.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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<String> {
static SUPPORTED_BUILTINS: OnceLock<Vec<String>> = 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::<Vec<String>>()
})
}
27 changes: 24 additions & 3 deletions crates/gateway/src/compilation_config.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
}

impl Default for GatewayCompilerConfig {
fn default() -> Self {
Self { supported_builtins: supported_builtins().clone() }
}
}

impl SerializeConfig for GatewayCompilerConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
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<String> {
static SUPPORTED_BUILTINS: OnceLock<Vec<String>> = 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::<Vec<String>>()
})
}

0 comments on commit 63eae8e

Please sign in to comment.