Starknet 백서

Starknet

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 73쪽 중 3쪽

null} pub extern fn felt252_div(lhs: felt252, rhs: NonZero) -> felt252 nopanic; ``` ## Examples ```rust theme={null} use core::felt252_div; // Division with 0 remainder works the same way as integer division. assert!(felt252_div(4, 2) == 2); // Division with non 0 remainder returns a field element n where n * 3 ≡ 4 (mod P) assert!(felt252_div(4, 3) == 1206167596222043737899107594365023368541035738443865566657697352045290673495); ``` # core::fmt::Debug Source: https://docs.starknet.io/build/corelib/core-fmt-Debug A trait for debug formatting, using the empty format (`{:?}`). ## Signature ```rust theme={null} pub trait Debug ``` ## Examples ```rust theme={null} let word: ByteArray = "123"; println!("{:?}", word); ``` ## Trait functions ### fmt #### Signature ```rust theme={null} fn fmt(self: @T, ref f: Formatter) -> Result ``` # core::fmt::Display Source: https://docs.starknet.io/build/corelib/core-fmt-Display A trait for standard formatting, using the empty format (""). ## Signature ```rust theme={null} pub trait Display ``` ## Examples ```rust theme={null} let word: ByteArray = "123"; println!("{}", word); ``` ## Trait functions ### fmt #### Signature ```rust theme={null} fn fmt(self: @T, ref f: Formatter) -> Result ``` # core::fmt::Error Source: https://docs.starknet.io/build/corelib/core-fmt-Error Dedicated type for representing formatting errors. ## Signature ```rust theme={null} #[derive(Drop)] pub struct Error {} ``` # core::fmt::Formatter Source: https://docs.starknet.io/build/corelib/core-fmt-Formatter Configuration for formatting. ## Signature ```rust theme={null} #[derive(Default, Drop)] pub struct Formatter { pub buffer: ByteArray, } ``` ## Members ### buffer The pending result of formatting. #### Signature ```rust theme={null} pub buffer: ByteArray ``` # core::fmt::LowerHex Source: https://docs.starknet.io/build/corelib/core-fmt-LowerHex A trait for hex formatting in lower case, using the empty format (`{:x}`). ## Signature ```rust theme={null} pub trait LowerHex ``` ## Trait functions ### fmt #### Signature ```rust theme={null} fn fmt(self: @T, ref f: Formatter) -> Result ``` # core::fmt::into_felt252_based Source: https://docs.starknet.io/build/corelib/core-fmt-into_felt252_based Implementations for `Debug` and `LowerHex` for types that can be converted into `felt252` using the `Into` trait. ## Examples ```rust theme={null} impl MyTypeDebug = crate::fmt::into_felt252_based::DebugImpl; impl MyTypeLowerHex = crate::fmt::into_felt252_based::LowerHexImpl; ``` # core::gas::BuiltinCosts Source: https://docs.starknet.io/build/corelib/core-gas-BuiltinCosts Type representing the table of the costs of the different builtin usages. ## Signature ```rust theme={null} pub extern type BuiltinCosts; ``` # core::gas::GasBuiltin Source: https://docs.starknet.io/build/corelib/core-gas-GasBuiltin The gas builtin. This type is used to handle gas in the Cairo code. Contains the amount of gas available for the current run. ## Signature ```rust theme={null} pub extern type GasBuiltin; ``` # core::gas::GasReserve Source: https://docs.starknet.io/build/corelib/core-gas-GasReserve Represents a gas reserve. Gas reserves can be created at any point using gas from the gas counter, and can be utilized at a later point in time. ## Signature ```rust theme={null} pub extern type GasReserve; ``` # core::gas::gas_reserve_create Source: https://docs.starknet.io/build/corelib/core-gas-gas_reserve_create Creates a new gas reserve by withdrawing the specified amount from the gas counter. Returns `Some(GasReserve)` if there is sufficient gas, otherwise returns `None`. ## Signature ```rust theme={null} pub extern fn gas_reserve_create(amount: u128) -> Option implicits(RangeCheck, GasBuiltin) nopanic; ``` # core::gas::gas_reserve_utilize Source: https://docs.starknet.io/build/corelib/core-gas-gas_reserve_utilize Adds the gas stored in the reserve back to the gas counter. The reserve is consumed in the process. ## Signature ```rust theme={null} pub extern fn gas_reserve_utilize(reserve: GasReserve) implicits(GasBuiltin) nopanic; ``` # core::gas::get_builtin_costs Source: https://docs.starknet.io/build/corelib/core-gas-get_builtin_costs Returns the `BuiltinCosts` table to be used in `withdraw_gas_all`. ## Signature ```rust theme={null} pub extern fn get_builtin_costs() -> BuiltinCosts nopanic; ``` # core::gas::redeposit_gas Source: https://docs.starknet.io/build/corelib/core-gas-redeposit_gas Returns unused gas into the gas builtin. Useful for cases where different branches take different amounts of gas, but gas withdrawal is the same for both. ## Signature ```rust theme={null} pub extern fn redeposit_gas() implicits(GasBuiltin) nopanic; ``` # core::gas::withdraw_gas Source: https://docs.starknet.io/build/corelib/core-gas-withdraw_gas Withdraws gas from the `GasBuiltin` to handle the success case flow. Returns `Some(())` if there is sufficient gas to handle the success case, otherwise returns `None`. ## Signature ```rust theme={null} pub extern fn withdraw_gas() -> Option implicits(RangeCheck, GasBuiltin) nopanic; ``` ## Examples ```rust theme={null} // The success branch is the following lines, the failure branch is the `panic` caused by the // `unwrap` call. withdraw_gas().unwrap(); ``` ```rust theme={null} // Direct handling of `withdraw_gas`. match withdraw_gas() { Some(()) => success_case(), None => cheap_not_enough_gas_case(), } ``` # core::gas::withdraw_gas_all Source: https://docs.starknet.io/build/corelib/core-gas-withdraw_gas_all Same as `withdraw_gas`, but directly receives `BuiltinCosts`, which enables optimizations by removing the need for repeated internal calls for fetching the table of constants that may internally happen in calls to `withdraw_gas`. Should be used with caution. ## Signature ```rust theme={null} pub extern fn withdraw_gas_all(costs: BuiltinCosts) -> Option implicits(RangeCheck, GasBuiltin) nopanic; ``` # core::hash::Hash Source: https://docs.starknet.io/build/corelib/core-hash-Hash A trait for values that can be hashed. This trait should be implemented for any type that can be included in a hash calculation. The most common way to implement this trait is by using `#[derive(Hash)]`. ## Signature ```rust theme={null} pub trait Hash> ``` ## Trait functions ### update\_state Updates the hash state with the given value and returns a new hash state. #### Signature ```rust theme={null} fn update_state, T, S, +HashStateTrait>(state: S, value: T) -> S ``` #### Examples ```rust theme={null} use core::pedersen::PedersenTrait; use core::hash::Hash; let mut state = PedersenTrait::new(0); let new_state = Hash::update_state(state, 1); ``` # core::hash::HashStateExTrait Source: https://docs.starknet.io/build/corelib/core-hash-HashStateExTrait Extension trait for hash state accumulators. This trait adds the `update_with` method to hash states, allowing you to directly hash values of any type T that implements `Hash`, rather than having to manually convert values to felt252 first. This provides a more ergonomic API when working with complex types. ## Signature ```rust theme={null} pub trait HashStateExTrait ``` ## Trait functions ### update\_with Updates the hash state with the given value and returns the updated state. #### Signature ```rust theme={null} fn update_with(self: S, value: T) -> S ``` #### Examples ```rust theme={null} use core::pedersen::PedersenTrait; use core::hash::HashStateExTrait; #[derive(Copy, Drop, Hash)] struct Point { x: u32, y: u32 } let point = Point { x: 1, y: 2 }; let hash = PedersenTrait::new(0) .update_with(point) .update_with(42) .finalize(); ``` # core::hash::HashStateTrait Source: https://docs.starknet.io/build/corelib/core-hash-HashStateTrait A trait for hash state accumulators. Provides methods to update a hash state with new values and finalize it into a hash result. ## Signature ```rust theme={null} pub trait HashStateTrait ``` ## Trait functions ### update Updates the current hash state `self` with the given `felt252` value and returns a new hash state. #### Signature ```rust theme={null} fn update(self: S, value: felt252) -> S ``` #### Examples ```rust theme={null} use core::pedersen::PedersenTrait; use core::hash::HashStateTrait; let mut state = PedersenTrait::new(0); state = state.update(1); ``` ### finalize Takes the current state `self` and returns the hash result. #### Signature ```rust theme={null} fn finalize(self: S) -> felt252 ``` #### Examples ```rust theme={null} use core::pedersen::PedersenTrait; use core::hash::HashStateTrait; let mut state = PedersenTrait::new(0); let hash = state.finalize(); ``` # core::hash::LegacyHash Source: https://docs.starknet.io/build/corelib/core-hash-LegacyHash A trait for hashing values using a `felt252` as hash state, used for backwards compatibility. NOTE: Implement `Hash` instead of this trait if possible. ## Signature ```rust theme={null} pub trait LegacyHash ``` ## Trait functions ### hash Takes a `felt252` state and a value of type `T` and returns the hash result. #### Signature ```rust theme={null} fn hash(state: felt252, value: T) -> felt252 ``` #### Examples ```rust theme={null} use core::pedersen::PedersenTrait; use core::hash::LegacyHash; let hash = LegacyHash::hash(0, 1); ``` # core::hash::into_felt252_based Source: https://docs.starknet.io/build/corelib/core-hash-into_felt252_based Implementation for `Hash` for types that can be converted into `felt252` using the `Into` trait. ## Examples ```rust theme={null} impl MyTypeHash, +Drop> = core::hash::into_felt252_based::HashImpl;` ``` # core::integer::Bitwise Source: https://docs.starknet.io/build/corelib/core-integer-Bitwise ## Signature ```rust theme={null} pub extern type Bitwise; ``` # core::integer::BoundedInt Source: https://docs.starknet.io/build/corelib/core-integer-BoundedInt Trait for getting the maximal and minimal values of an integer type. ## Signature ```rust theme={null} pub trait BoundedInt ``` ## Trait functions ### min Returns the minimal value of the type. #### Signature ```rust theme={null} fn min() -> T ``` ### max Returns the maximal value of the type. #### Signature ```rust theme={null} fn max() -> T ``` # core::integer::NumericLiteral Source: https://docs.starknet.io/build/corelib/core-integer-NumericLiteral ## Signature ```rust theme={null} pub trait NumericLiteral ``` # core::integer::U128MulGuarantee Source: https://docs.starknet.io/build/corelib/core-integer-U128MulGuarantee A type that contains 4 u128s (a, b, c, d) and guarantees that `a * b = 2**128 * c + d`. The guarantee is verified by `u128_mul_guarantee_verify`, which is the only way to destruct this type. This way, one can trust that the guarantee holds although it has not yet been verified. ## Signature ```rust theme={null} pub extern type U128MulGuarantee; ``` # core::integer::i128 Source: https://docs.starknet.io/build/corelib/core-integer-i128 The 128-bit signed integer type. ## Signature ```rust theme={null} pub extern type i128; ``` # core::integer::i128_diff Source: https://docs.starknet.io/build/corelib/core-integer-i128_diff If `lhs` >= `rhs` returns `Ok(lhs - rhs)` else returns `Err(2**128 + lhs - rhs)`. ## Signature ```rust theme={null} pub extern fn i128_diff(lhs: i128, rhs: i128) -> Result implicits(RangeCheck) nopanic; ``` # core::integer::i16 Source: https://docs.starknet.io/build/corelib/core-integer-i16 The 16-bit signed integer type. ## Signature ```rust theme={null} pub extern type i16; ``` # core::integer::i16_diff Source: https://docs.starknet.io/build/corelib/core-integer-i16_diff If `lhs` >= `rhs` returns `Ok(lhs - rhs)` else returns `Err(2**16 + lhs - rhs)`. ## Signature ```rust theme={null} pub extern fn i16_diff(lhs: i16, rhs: i16) -> Result implicits(RangeCheck) nopanic; ``` # core::integer::i16_wide_mul Source: https://docs.starknet.io/build/corelib/core-integer-i16_wide_mul ## Signature ```rust theme={null} pub extern fn i16_wide_mul(lhs: i16, rhs: i16) -> i32 nopanic; ``` # core::integer::i32 Source: https://docs.starknet.io/build/corelib/core-integer-i32 The 32-bit signed integer type. ## Signature ```rust theme={null} pub extern type i32; ``` # core::integer::i32_diff Source: https://docs.starknet.io/build/corelib/core-integer-i32_diff If `lhs` >= `rhs` returns `Ok(lhs - rhs)` else returns `Err(2**32 + lhs - rhs)`. ## Signature ```rust theme={null} pub extern fn i32_diff(lhs: i32, rhs: i32) -> Result implicits(RangeCheck) nopanic; ``` # core::integer::i32_wide_mul Source: https://docs.starknet.io/build/corelib/core-integer-i32_wide_mul ## Signature ```rust theme={null} pub extern fn i32_wide_mul(lhs: i32, rhs: i32) -> i64 nopanic; ``` # core::integer::i64 Source: https://docs.starknet.io/build/corelib/core-integer-i64 The 64-bit signed integer type. ## Signature ```rust theme={null} pub extern type i64; ``` # core::integer::i64_diff Source: https://docs.starknet.io/build/corelib/core-integer-i64_diff If `lhs` >= `rhs` returns `Ok(lhs - rhs)` else returns `Err(2**64 + lhs - rhs)`. ## Signature ```rust theme={null} pub extern fn i64_diff(lhs: i64, rhs: i64) -> Result implicits(RangeCheck) nopanic; ``` # core::integer::i64_wide_mul Source: https://docs.starknet.io/build/corelib/core-integer-i64_wide_mul ## Signature ```rust theme={null} pub extern fn i64_wide_mul(lhs: i64, rhs: i64) -> i128 nopanic; ``` # core::integer::i8 Source: https://docs.starknet.io/build/corelib/core-integer-i8 The 8-bit signed integer type. ## Signature ```rust theme={null} pub extern type i8; ``` # core::integer::i8_diff Source: https://docs.starknet.io/build/corelib/core-integer-i8_diff If `lhs` >= `rhs` returns `Ok(lhs - rhs)` else returns `Err(2**8 + lhs - rhs)`. ## Signature ```rust theme={null} pub extern fn i8_diff(lhs: i8, rhs: i8) -> Result implicits(RangeCheck) nopanic; ``` # core::integer::i8_wide_mul Source: https://docs.starknet.io/build/corelib/core-integer-i8_wide_mul ## Signature ```rust theme={null} pub extern fn i8_wide_mul(lhs: i8, rhs: i8) -> i16 nopanic; ``` # core::integer::u128 Source: https://docs.starknet.io/build/corelib/core-integer-u128 The 128-bit unsigned integer type. ## Signature ```rust theme={null} pub extern type u128; ``` # core::integer::u128_byte_reverse Source: https://docs.starknet.io/build/corelib/core-integer-u128_byte_reverse ## Signature ```rust theme={null} pub extern fn u128_byte_reverse(input: u128) -> u128 implicits(Bitwise) nopanic; ``` # core::integer::u128_overflowing_add Source: https://docs.starknet.io/build/corelib/core-integer-u128_overflowing_add ## Signature ```rust theme={null} pub extern fn u128_overflowing_add(lhs: u128, rhs: u128) -> Result implicits(RangeCheck) nopanic; ``` # core::integer::u128_overflowing_mul Source: https://docs.starknet.io/build/corelib/core-integer-u128_overflowing_mul ## Signature ```rust theme={null} pub fn u128_overflowing_mul(lhs: u128, rhs: u128) -> (u128, bool) ``` # core::integer::u128_overflowing_sub Source: https://docs.starknet.io/build/corelib/core-integer-u128_overflowing_sub ## Signature ```rust theme={null} pub extern fn u128_overflowing_sub(lhs: u128, rhs: u128) -> Result implicits(RangeCheck) nopanic; ``` # core::integer::u128_safe_divmod Source: https://docs.starknet.io/build/corelib/core-integer-u128_safe_divmod ## Signature ```rust theme={null} pub extern fn u128_safe_divmod(lhs: u128, rhs: NonZero) -> (u128, u128) implicits(RangeCheck) nopanic; ``` # core::integer::u128_sqrt Source: https://docs.starknet.io/build/corelib/core-integer-u128_sqrt ## Signature ```rust theme={null} pub extern fn u128_sqrt(value: u128) -> u64 implicits(RangeCheck) nopanic; ``` # core::integer::u128_wide_mul Source: https://docs.starknet.io/build/corelib/core-integer-u128_wide_mul Multiplies two u128s and returns `(high, low)` - the 128-bit parts of the result. ## Signature ```rust theme={null} pub fn u128_wide_mul(a: u128, b: u128) -> (u128, u128) ``` # core::integer::u128_wrapping_add Source: https://docs.starknet.io/build/corelib/core-integer-u128_wrapping_add ## Signature ```rust theme={null} pub fn u128_wrapping_add(lhs: u128, rhs: u128) -> u128 ``` # core::integer::u128_wrapping_sub Source: https://docs.starknet.io/build/corelib/core-integer-u128_wrapping_sub ## Signature ```rust theme={null} pub fn u128_wrapping_sub(a: u128, b: u128) -> u128 ``` # core::integer::u16 Source: https://docs.starknet.io/build/corelib/core-integer-u16 The 16-bit unsigned integer type. ## Signature ```rust theme={null} pub extern type u16; ``` # core::integer::u16_overflowing_add Source: https://docs.starknet.io/build/corelib/core-integer-u16_overflowing_add ## Signature ```rust theme={null} pub extern fn u16_overflowing_add(lhs: u16, rhs: u16) -> Result implicits(RangeCheck) nopanic; ``` # core::integer::u16_overflowing_sub Source: https://docs.starknet.io/build/corelib/core-integer-u16_overflowing_sub ## Signature ```rust theme={null} pub extern fn u16_overflowing_sub(lhs: u16, rhs: u16) -> Result implicits(RangeCheck) nopanic; ``` # core::integer::u16_safe_divmod Source: https://docs.starknet.io/build/corelib/core-integer-u16_safe_divmod ## Signature ```rust theme={null} pub extern fn u16_safe_divmod(lhs: u16, rhs: NonZero) -> (u16, u16) implicits(RangeCheck) nopanic; ``` # core::integer::u16_sqrt Source: https://docs.starknet.io/build/corelib/core-integer-u16_sqrt ## Signature ```rust theme={null} pub extern fn u16_sqrt(value: u16) -> u8 implicits(RangeCheck) nopanic; ``` # core::integer::u16_wide_mul Source: https://docs.starknet.io/build/corelib/core-integer-u16_wide_mul ## Signature ```rust theme={null} pub extern fn u16_wide_mul(lhs: u16, rhs: u16) -> u32 nopanic; ``` # core::integer::u16_wrapping_add Source: https://docs.starknet.io/build/corelib/core-integer-u16_wrapping_add ## Signature ```rust theme={null} pub fn u16_wrapping_add(lhs: u16, rhs: u16) -> u16 ``` # core::integer::u16_wrapping_sub Source: https://docs.starknet.io/build/corelib/core-integer-u16_wrapping_sub ## Signature ```rust theme={null} pub fn u16_wrapping_sub(lhs: u16, rhs: u16) -> u16 ``` # core::integer::u256 Source: https://docs.starknet.io/build/corelib/core-integer-u256 The 256-bit unsigned integer type. The `u256` type is composed of two 128-bit parts: the low part \[0, 128) and the high part \[128, 256\). ## Signature ```rust theme={null} #[derive(Copy, Drop, Hash, PartialEq, Serde)] pub struct u256 { pub low: u128, pub high: u128, } ``` ## Members ### low #### Signature ```rust theme={null} pub low: u128 ``` ### high #### Signature ```rust theme={null} pub high: u128 ``` # core::integer::u256_overflow_mul Source: https://docs.starknet.io/build/corelib/core-integer-u256_overflow_mul ## Signature ```rust theme={null} pub fn u256_overflow_mul(lhs: u256, rhs: u256) -> (u256, bool) ``` # core::integer::u256_overflow_sub Source: https://docs.starknet.io/build/corelib/core-integer-u256_overflow_sub ## Signature ```rust theme={null} pub fn u256_overflow_sub(lhs: u256, rhs: u256) -> (u256, bool) ``` # core::integer::u256_overflowing_add Source: https://docs.starknet.io/build/corelib/core-integer-u256_overflowing_add ## Signature ```rust theme={null} pub fn u256_overflowing_add(lhs: u256, rhs: u256) -> (u256, bool) ``` # core::integer::u256_overflowing_mul Source: https://docs.starknet.io/build/corelib/core-integer-u256_overflowing_mul ## Signature ```rust theme={null} pub fn u256_overflowing_mul(lhs: u256, rhs: u256) -> (u256, bool) ``` # core::integer::u256_overflowing_sub Source: https://docs.starknet.io/build/corelib/core-integer-u256_overflowing_sub ## Signature ```rust theme={null} pub fn u256_overflowing_sub(lhs: u256, rhs: u256) -> (u256, bool) ``` # core::integer::u256_sqrt Source: https://docs.starknet.io/build/corelib/core-integer-u256_sqrt
프로젝트로 돌아가기