Skip to content

Commit

Permalink
chore: remove supported builtins validation as it is enforced by the …
Browse files Browse the repository at this point in the history
…compilation to casm
  • Loading branch information
ArniStarkware committed Jul 23, 2024
1 parent fc5813a commit ea16b37
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 136 deletions.
38 changes: 1 addition & 37 deletions crates/gateway/src/compilation.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::panic;
use std::sync::OnceLock;

use blockifier::execution::contract_class::{ClassInfo, ContractClass, ContractClassV1};
use cairo_lang_starknet_classes::casm_contract_class::{
CasmContractClass, CasmContractEntryPoints,
};
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use cairo_lang_starknet_classes::contract_class::ContractClass as CairoLangContractClass;
use starknet_api::core::CompiledClassHash;
use starknet_api::rpc_transaction::RPCDeclareTransaction;
Expand All @@ -14,7 +11,6 @@ use starknet_sierra_compile::utils::into_contract_class_for_compilation;

use crate::config::GatewayCompilerConfig;
use crate::errors::{GatewayError, GatewayResult};
use crate::utils::is_subsequence;

#[cfg(test)]
#[path = "compilation_test.rs"]
Expand Down Expand Up @@ -42,7 +38,6 @@ impl GatewayCompiler {
let casm_contract_class = self.compile(cairo_lang_contract_class)?;

validate_compiled_class_hash(&casm_contract_class, &tx.compiled_class_hash)?;
validate_casm_class(&casm_contract_class)?;

Ok(ClassInfo::new(
&ContractClass::V1(ContractClassV1::try_from(casm_contract_class)?),
Expand All @@ -65,37 +60,6 @@ impl GatewayCompiler {
}
}

// TODO(Arni): Add test.
fn validate_casm_class(contract_class: &CasmContractClass) -> Result<(), GatewayError> {
let CasmContractEntryPoints { external, l1_handler, constructor } =
&contract_class.entry_points_by_type;
let entry_points_iterator = external.iter().chain(l1_handler.iter()).chain(constructor.iter());

for entry_point in entry_points_iterator {
let builtins = &entry_point.builtins;
if !is_subsequence(builtins, supported_builtins()) {
return Err(GatewayError::UnsupportedBuiltins {
builtins: builtins.clone(),
supported_builtins: 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>>()
})
}

/// Validates that the compiled class hash of the compiled contract class matches the supplied
/// compiled class hash.
fn validate_compiled_class_hash(
Expand Down
21 changes: 0 additions & 21 deletions crates/gateway/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ use starknet_mempool_types::mempool_types::ThinTransaction;

use crate::errors::StatefulTransactionValidatorResult;

#[cfg(test)]
#[path = "utils_test.rs"]
mod utils_test;

macro_rules! implement_ref_getters {
($(($member_name:ident, $member_type:ty));* $(;)?) => {
$(fn $member_name(&self) -> &$member_type {
Expand Down Expand Up @@ -160,20 +156,3 @@ pub fn get_tx_hash(tx: &AccountTransaction) -> TransactionHash {
AccountTransaction::Invoke(tx) => tx.tx_hash,
}
}

/// Checks whether 'subsequence' is a subsequence of 'sequence'.
pub fn is_subsequence<T: Eq>(subsequence: &[T], sequence: &[T]) -> bool {
let mut offset = 0;

for item in sequence {
if offset == subsequence.len() {
return true;
}

if item == &subsequence[offset] {
offset += 1;
}
}

offset == subsequence.len()
}
78 changes: 0 additions & 78 deletions crates/gateway/src/utils_test.rs

This file was deleted.

0 comments on commit ea16b37

Please sign in to comment.