Skip to content

Commit

Permalink
feat: use starknet_api builtin for name trait
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Jun 30, 2024
1 parent e82f53b commit d572302
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
17 changes: 12 additions & 5 deletions crates/gateway/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use cairo_lang_starknet_classes::casm_contract_class::{
};
use starknet_api::core::CompiledClassHash;
use starknet_api::rpc_transaction::{RPCDeclareTransaction, RPCTransaction};
use starknet_api::transaction::TransactionHash;
use starknet_api::transaction::{Builtin, TransactionHash};
use starknet_mempool_types::communication::SharedMempoolClient;
use starknet_mempool_types::mempool_types::{Account, MempoolInput};
use starknet_sierra_compile::compile::{compile_sierra_to_casm, CompilationUtilError};
Expand All @@ -25,7 +25,7 @@ use crate::starknet_api_test_utils::get_sender_address;
use crate::state_reader::StateReaderFactory;
use crate::stateful_transaction_validator::StatefulTransactionValidator;
use crate::stateless_transaction_validator::StatelessTransactionValidator;
use crate::utils::{external_tx_to_thin_tx, is_subsequence};
use crate::utils::{external_tx_to_thin_tx, is_subsequence, NameExt};

#[cfg(test)]
#[path = "gateway_test.rs"]
Expand Down Expand Up @@ -185,9 +185,16 @@ pub fn compile_contract_class(declare_tx: &RPCDeclareTransaction) -> GatewayResu

// TODO(Arni): Add to a config.
fn get_supported_builtins() -> Vec<String> {
let builtins =
["pedersen", "range_check", "ecdsa", "bitwise", "ec_op", "poseidon", "segment_arena"];
builtins.iter().map(|builtin| builtin.to_string()).collect()
let builtins = [
Builtin::Pedersen,
Builtin::RangeCheck,
Builtin::Ecdsa,
Builtin::Bitwise,
Builtin::EcOp,
Builtin::Poseidon,
Builtin::SegmentArena,
];
builtins.iter().map(|builtin| builtin.name().to_string()).collect()
}

// TODO(Arni): Add test.
Expand Down
34 changes: 32 additions & 2 deletions crates/gateway/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use starknet_api::rpc_transaction::{
RPCDeclareTransaction, RPCDeployAccountTransaction, RPCInvokeTransaction, RPCTransaction,
};
use starknet_api::transaction::{
DeclareTransaction, DeclareTransactionV3, DeployAccountTransaction, DeployAccountTransactionV3,
InvokeTransaction, InvokeTransactionV3, Tip, TransactionHash, TransactionHasher,
Builtin, DeclareTransaction, DeclareTransactionV3, DeployAccountTransaction,
DeployAccountTransactionV3, InvokeTransaction, InvokeTransactionV3, Tip, TransactionHash,
TransactionHasher,
};
use starknet_mempool_types::mempool_types::ThinTransaction;

Expand Down Expand Up @@ -160,3 +161,32 @@ pub fn is_subsequence(subsequence: &[String], sequence: &[String]) -> bool {
}
true
}

// TODO(Arni): Remove the trait NameExt once it is implemented in starknet API.
const RANGE_CHACK_BUILTIN_NAME: &str = "range_check";
const PEDERSEN_BUILTIN_NAME: &str = "pedersen";
const POSEIDON_BUILTIN_NAME: &str = "poseidon";
const EC_OP_BUILTIN_NAME: &str = "ec_op";
const ECDSA_BUILTIN_NAME: &str = "ecdsa";
const BITWISE_BUILTIN_NAME: &str = "bitwise";
const KECCAK_BUILTIN_NAME: &str = "keccak";
const SEGMENT_ARENA_BUILTIN_NAME: &str = "segment_arena";

impl NameExt for Builtin {
fn name(&self) -> &'static str {
match self {
Builtin::RangeCheck => RANGE_CHACK_BUILTIN_NAME,
Builtin::Pedersen => PEDERSEN_BUILTIN_NAME,
Builtin::Poseidon => POSEIDON_BUILTIN_NAME,
Builtin::EcOp => EC_OP_BUILTIN_NAME,
Builtin::Ecdsa => ECDSA_BUILTIN_NAME,
Builtin::Bitwise => BITWISE_BUILTIN_NAME,
Builtin::Keccak => KECCAK_BUILTIN_NAME,
Builtin::SegmentArena => SEGMENT_ARENA_BUILTIN_NAME,
}
}
}

pub trait NameExt {
fn name(&self) -> &'static str;
}

0 comments on commit d572302

Please sign in to comment.