cairo_lang_sierra/extensions/modules/starknet/
interoperability.rsuse num_bigint::BigInt;
use super::felt252_span_ty;
use super::syscalls::SyscallGenericLibfunc;
use crate::extensions::consts::{ConstGenLibfunc, WrapConstGenLibfunc};
use crate::extensions::felt252::Felt252Type;
use crate::extensions::lib_func::{LibfuncSignature, SignatureSpecializationContext};
use crate::extensions::modules::get_bool_type;
use crate::extensions::try_from_felt252::TryFromFelt252;
use crate::extensions::utils::reinterpret_cast_signature;
use crate::extensions::{
NamedType, NoGenericArgsGenericLibfunc, NoGenericArgsGenericType, SpecializationError,
};
use crate::ids::GenericTypeId;
#[derive(Default)]
pub struct ContractAddressType {}
impl NoGenericArgsGenericType for ContractAddressType {
const ID: GenericTypeId = GenericTypeId::new_inline("ContractAddress");
const STORABLE: bool = true;
const DUPLICATABLE: bool = true;
const DROPPABLE: bool = true;
const ZERO_SIZED: bool = false;
}
#[derive(Default)]
pub struct ContractAddressConstLibfuncWrapped {}
impl ConstGenLibfunc for ContractAddressConstLibfuncWrapped {
const STR_ID: &'static str = "contract_address_const";
const GENERIC_TYPE_ID: GenericTypeId = <ContractAddressType as NoGenericArgsGenericType>::ID;
fn bound() -> BigInt {
BigInt::from(2).pow(251)
}
}
pub type ContractAddressConstLibfunc = WrapConstGenLibfunc<ContractAddressConstLibfuncWrapped>;
#[derive(Default)]
pub struct ContractAddressTryFromFelt252Libfunc;
impl TryFromFelt252 for ContractAddressTryFromFelt252Libfunc {
const STR_ID: &'static str = "contract_address_try_from_felt252";
const GENERIC_TYPE_ID: GenericTypeId = <ContractAddressType as NoGenericArgsGenericType>::ID;
}
#[derive(Default)]
pub struct ContractAddressToFelt252Libfunc {}
impl NoGenericArgsGenericLibfunc for ContractAddressToFelt252Libfunc {
const STR_ID: &'static str = "contract_address_to_felt252";
fn specialize_signature(
&self,
context: &dyn SignatureSpecializationContext,
) -> Result<LibfuncSignature, SpecializationError> {
Ok(reinterpret_cast_signature(
context.get_concrete_type(ContractAddressType::id(), &[])?,
context.get_concrete_type(Felt252Type::id(), &[])?,
))
}
}
#[derive(Default)]
pub struct ClassHashType {}
impl NoGenericArgsGenericType for ClassHashType {
const ID: GenericTypeId = GenericTypeId::new_inline("ClassHash");
const STORABLE: bool = true;
const DUPLICATABLE: bool = true;
const DROPPABLE: bool = true;
const ZERO_SIZED: bool = false;
}
#[derive(Default)]
pub struct ClassHashConstLibfuncWrapped {}
impl ConstGenLibfunc for ClassHashConstLibfuncWrapped {
const STR_ID: &'static str = "class_hash_const";
const GENERIC_TYPE_ID: GenericTypeId = <ClassHashType as NoGenericArgsGenericType>::ID;
fn bound() -> BigInt {
BigInt::from(2).pow(251)
}
}
pub type ClassHashConstLibfunc = WrapConstGenLibfunc<ClassHashConstLibfuncWrapped>;
#[derive(Default)]
pub struct ClassHashTryFromFelt252Trait;
impl TryFromFelt252 for ClassHashTryFromFelt252Trait {
const STR_ID: &'static str = "class_hash_try_from_felt252";
const GENERIC_TYPE_ID: GenericTypeId = <ClassHashType as NoGenericArgsGenericType>::ID;
}
#[derive(Default)]
pub struct ClassHashToFelt252Libfunc {}
impl NoGenericArgsGenericLibfunc for ClassHashToFelt252Libfunc {
const STR_ID: &'static str = "class_hash_to_felt252";
fn specialize_signature(
&self,
context: &dyn SignatureSpecializationContext,
) -> Result<LibfuncSignature, SpecializationError> {
Ok(reinterpret_cast_signature(
context.get_concrete_type(ClassHashType::id(), &[])?,
context.get_concrete_type(Felt252Type::id(), &[])?,
))
}
}
#[derive(Default)]
pub struct CallContractLibfunc {}
impl SyscallGenericLibfunc for CallContractLibfunc {
const STR_ID: &'static str = "call_contract_syscall";
fn input_tys(
context: &dyn SignatureSpecializationContext,
) -> Result<Vec<crate::ids::ConcreteTypeId>, SpecializationError> {
Ok(vec![
context.get_concrete_type(ContractAddressType::id(), &[])?,
context.get_concrete_type(Felt252Type::id(), &[])?,
felt252_span_ty(context)?,
])
}
fn success_output_tys(
context: &dyn SignatureSpecializationContext,
) -> Result<Vec<crate::ids::ConcreteTypeId>, SpecializationError> {
Ok(vec![felt252_span_ty(context)?])
}
}
#[derive(Default)]
pub struct DeployLibfunc {}
impl SyscallGenericLibfunc for DeployLibfunc {
const STR_ID: &'static str = "deploy_syscall";
fn input_tys(
context: &dyn SignatureSpecializationContext,
) -> Result<Vec<crate::ids::ConcreteTypeId>, SpecializationError> {
Ok(vec![
context.get_concrete_type(ClassHashType::id(), &[])?,
context.get_concrete_type(Felt252Type::id(), &[])?,
felt252_span_ty(context)?,
get_bool_type(context)?,
])
}
fn success_output_tys(
context: &dyn SignatureSpecializationContext,
) -> Result<Vec<crate::ids::ConcreteTypeId>, SpecializationError> {
Ok(vec![
context.get_concrete_type(ContractAddressType::id(), &[])?,
felt252_span_ty(context)?,
])
}
}
#[derive(Default)]
pub struct LibraryCallLibfunc {}
impl SyscallGenericLibfunc for LibraryCallLibfunc {
const STR_ID: &'static str = "library_call_syscall";
fn input_tys(
context: &dyn SignatureSpecializationContext,
) -> Result<Vec<crate::ids::ConcreteTypeId>, SpecializationError> {
Ok(vec![
context.get_concrete_type(ClassHashType::id(), &[])?,
context.get_concrete_type(Felt252Type::id(), &[])?,
felt252_span_ty(context)?,
])
}
fn success_output_tys(
context: &dyn SignatureSpecializationContext,
) -> Result<Vec<crate::ids::ConcreteTypeId>, SpecializationError> {
Ok(vec![felt252_span_ty(context)?])
}
}
#[derive(Default)]
pub struct SendMessageToL1Libfunc {}
impl SyscallGenericLibfunc for SendMessageToL1Libfunc {
const STR_ID: &'static str = "send_message_to_l1_syscall";
fn input_tys(
context: &dyn SignatureSpecializationContext,
) -> Result<Vec<crate::ids::ConcreteTypeId>, SpecializationError> {
Ok(vec![
context.get_concrete_type(Felt252Type::id(), &[])?,
felt252_span_ty(context)?,
])
}
fn success_output_tys(
_context: &dyn SignatureSpecializationContext,
) -> Result<Vec<crate::ids::ConcreteTypeId>, SpecializationError> {
Ok(vec![])
}
}