Starknet 백서

Starknet

원문

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

# core::RangeCheck Source: https://docs.starknet.io/build/corelib/core-RangeCheck General purpose implicits. ## Signature ```rust theme={null} pub extern type RangeCheck; ``` # core::SegmentArena Source: https://docs.starknet.io/build/corelib/core-SegmentArena ## Signature ```rust theme={null} pub extern type SegmentArena; ``` # core::assert Source: https://docs.starknet.io/build/corelib/core-assert Panics if `cond` is false with the given `felt252` as error message. ## Signature ```rust theme={null} pub fn assert(cond: bool, err_code: felt252) ``` ## Examples ```rust theme={null} assert(false, 'error message'); ``` # core::blake::blake2s_compress Source: https://docs.starknet.io/build/corelib/core-blake-blake2s_compress The blake2s compress function, which takes a state, a byte count, and a message, and returns a new state. `byte_count` should be the total number of bytes hashed after hashing the current `msg`. ## Signature ```rust theme={null} pub extern fn blake2s_compress(state: Box, byte_count: u32, msg: Box) -> Box nopanic; ``` # core::blake::blake2s_finalize Source: https://docs.starknet.io/build/corelib/core-blake-blake2s_finalize A variant of `blake2s_compress` for the final block of the message. The input `msg` must always be exactly 16 `u32` elements, padded with zeros if necessary, regardless of the value of `byte_count`. Using any padding scheme other than zero-padding will produce a different hash output. ## Signature ```rust theme={null} pub extern fn blake2s_finalize(state: Box, byte_count: u32, msg: Box) -> Box nopanic; ``` # core::bool Source: https://docs.starknet.io/build/corelib/core-bool `bool` enum representing either `false` or `true`. ## Signature ```rust theme={null} pub enum bool { False, True, } ``` ## Variants ### False #### Signature ```rust theme={null} False ``` ### True #### Signature ```rust theme={null} True ``` # core::boolean::BoolTrait Source: https://docs.starknet.io/build/corelib/core-boolean-BoolTrait ## Signature ```rust theme={null} pub trait BoolTrait> ``` ## Trait functions ### then\_some Returns `Some(t)` if the `bool` is `true`, `None` otherwise. #### Signature ```rust theme={null} fn then_some, T, +Drop>(self: bool, t: T) -> Option ``` #### Examples ```rust theme={null} assert!(false.then_some(0) == None); assert!(true.then_some(0) == Some(0)); ``` # core::box::Box Source: https://docs.starknet.io/build/corelib/core-box-Box A `Box` is a type that points to a wrapped value. It allows for cheap moving around of the value, as its size is small, and may wrap a large size. ## Signature ```rust theme={null} pub extern type Box; ``` # core::box::BoxTrait Source: https://docs.starknet.io/build/corelib/core-box-BoxTrait ## Signature ```rust theme={null} pub trait BoxTrait ``` ## Trait functions ### new Creates a new `Box` with the given value. Allocates space in the boxed segment for the provided value and returns a `Box` that points to it. #### Signature ```rust theme={null} fn new(value: T) -> Box ``` #### Examples ```rust theme={null} let x = 42; let boxed_x = BoxTrait::new(x); ``` ### unbox Unboxes the given `Box` and returns the wrapped value. #### Signature ```rust theme={null} fn unbox(self: Box) -> T ``` #### Examples ```rust theme={null} let boxed = BoxTrait::new(42); assert!(boxed.unbox() == 42); ``` ### as\_snapshot Converts the given snapshot of a `Box` into a `Box` of a snapshot. Useful for structures that aren't copyable. #### Signature ```rust theme={null} fn as_snapshot(self: @Box) -> Box ``` #### Examples ```rust theme={null} let snap_boxed_arr = @BoxTraits::new(array![1, 2, 3]); let boxed_snap_arr = snap_boxed_arr.as_snapshot(); let snap_arr = boxed_snap_arr.unbox(); ``` # core::byte_array::BYTE_ARRAY_MAGIC Source: https://docs.starknet.io/build/corelib/core-byte_array-BYTE_ARRAY_MAGIC A magic constant for identifying serialization of `ByteArray` variables. An array of `felt252` with this magic value as one of the `felt252` indicates that you should expect right after it a serialized `ByteArray`. This is currently used mainly for prints and panics. ## Signature ```rust theme={null} pub const BYTE_ARRAY_MAGIC: felt252 = 1997209042069643135709344952807065910992472029923670688473712229447419591075; ``` # core::byte_array::ByteArray Source: https://docs.starknet.io/build/corelib/core-byte_array-ByteArray Byte array type. ## Signature ```rust theme={null} #[derive(Drop, Clone, PartialEq, Serde, Default)] pub struct ByteArray { pub(crate) data: Array, pub(crate) pending_word: felt252, pub(crate) pending_word_len: u32, } ``` # core::byte_array::ByteArrayImpl Source: https://docs.starknet.io/build/corelib/core-byte_array-ByteArrayImpl Functions associated with the `ByteArray` type. ## Signature ```rust theme={null} pub impl ByteArrayImpl of ByteArrayTrait; ``` ## Impl functions ### append\_word Appends a single word of `len` bytes to the end of the `ByteArray`. This function assumes that: 1. `word` could be validly converted to a `bytes31` which has no more than `len` bytes of data. 2. len ByteArray ```` ### append_byte Appends a single byte to the end of the `ByteArray`. #### Signature ```rust fn append_byte(ref self: ByteArray, byte: u8) ```` #### Examples ```rust theme={null} let mut ba = ""; ba.append_byte(0); assert!(ba == "0"); ``` ### len Returns the length of the `ByteArray`. #### Signature ```rust theme={null} fn len(self: ByteArray) -> u32 ``` #### Examples ```rust theme={null} let ba: ByteArray = "byte array"; let len = ba.len(); assert!(len == 10); ``` ### at Returns an option of the byte at the given index of `self` or `None` if the index is out of bounds. #### Signature ```rust theme={null} fn at(self: ByteArray, index: u32) -> Option ``` #### Examples ```rust theme={null} let ba: ByteArray = "byte array"; let byte = ba.at(0).unwrap(); assert!(byte == 98); ``` ### rev Returns a `ByteArray` with the reverse order of `self`. #### Signature ```rust theme={null} fn rev(self: ByteArray) -> ByteArray ``` #### Examples ```rust theme={null} let ba: ByteArray = "123"; let rev_ba = ba.rev(); assert!(rev_ba == "321"); ``` ### append\_word\_rev Appends the reverse of the given word to the end of `self`. This function assumes that: 1. len \< 31 2. word is validly convertible to bytes31 of length `len`. #### Signature ```rust theme={null} fn append_word_rev(ref self: ByteArray, word: felt252, len: u32) ``` #### Examples ```rust theme={null} let mut ba: ByteArray = ""; ba.append_word_rev('123', 3); assert!(ba == "321"); ``` # core::byte_array::ByteArrayIter Source: https://docs.starknet.io/build/corelib/core-byte_array-ByteArrayIter An iterator struct over a ByteArray. ## Signature ```rust theme={null} #[derive(Drop, Clone)] pub struct ByteArrayIter { ba: ByteArray, current_index: IntRange, } ``` # core::byte_array::ByteArrayTrait Source: https://docs.starknet.io/build/corelib/core-byte_array-ByteArrayTrait ## Signature ```rust theme={null} pub trait ByteArrayTrait ``` ## Trait functions ### append\_word Appends a single word of `len` bytes to the end of the `ByteArray`. This function assumes that: 1. `word` could be validly converted to a `bytes31` which has no more than `len` bytes of data. 2. len ByteArray ```` ### append_byte Appends a single byte to the end of the `ByteArray`. #### Signature ```rust fn append_byte(ref self: ByteArray, byte: u8) ```` #### Examples ```rust theme={null} let mut ba = ""; ba.append_byte(0); assert!(ba == "0"); ``` ### len Returns the length of the `ByteArray`. #### Signature ```rust theme={null} fn len(self: ByteArray) -> u32 ``` #### Examples ```rust theme={null} let ba: ByteArray = "byte array"; let len = ba.len(); assert!(len == 10); ``` ### at Returns an option of the byte at the given index of `self` or `None` if the index is out of bounds. #### Signature ```rust theme={null} fn at(self: ByteArray, index: u32) -> Option ``` #### Examples ```rust theme={null} let ba: ByteArray = "byte array"; let byte = ba.at(0).unwrap(); assert!(byte == 98); ``` ### rev Returns a `ByteArray` with the reverse order of `self`. #### Signature ```rust theme={null} fn rev(self: ByteArray) -> ByteArray ``` #### Examples ```rust theme={null} let ba: ByteArray = "123"; let rev_ba = ba.rev(); assert!(rev_ba == "321"); ``` ### append\_word\_rev Appends the reverse of the given word to the end of `self`. This function assumes that: 1. len \< 31 2. word is validly convertible to bytes31 of length `len`. #### Signature ```rust theme={null} fn append_word_rev(ref self: ByteArray, word: felt252, len: u32) ``` #### Examples ```rust theme={null} let mut ba: ByteArray = ""; ba.append_word_rev('123', 3); assert!(ba == "321"); ``` # core::bytes_31::Bytes31Impl Source: https://docs.starknet.io/build/corelib/core-bytes_31-Bytes31Impl A trait for accessing a specific byte of a `bytes31` type. ## Signature ```rust theme={null} pub impl Bytes31Impl of Bytes31Trait; ``` ## Impl functions ### at Returns the byte at the given index (LSB's index is 0). Assumes that \`index u8 ``` ``` # core::bytes_31::Bytes31Trait Source: https://docs.starknet.io/build/corelib/core-bytes_31-Bytes31Trait ## Signature ```rust theme={null} pub trait Bytes31Trait ``` ## Trait functions ### at Returns the byte at the given index (LSB's index is 0). Assumes that \`index u8 ``` ``` # core::bytes_31::bytes31 Source: https://docs.starknet.io/build/corelib/core-bytes_31-bytes31 Represents a 31-byte fixed-size byte type. ## Signature ```rust theme={null} pub extern type bytes31; ``` # core::circuit::AddInputResult Source: https://docs.starknet.io/build/corelib/core-circuit-AddInputResult The result of filling an input in the circuit instance's data. This enum represents the state of input filling process, indicating whether all inputs have been provided or more are needed. ## Signature ```rust theme={null} pub enum AddInputResult { Done: CircuitData, More: CircuitInputAccumulator, } ``` ## Variants ### Done All inputs have been filled and the circuit data is complete. #### Signature ```rust theme={null} Done: CircuitData ``` ### More More inputs are needed to complete the circuit instance's data. #### Signature ```rust theme={null} More: CircuitInputAccumulator ``` # core::circuit::AddInputResultTrait Source: https://docs.starknet.io/build/corelib/core-circuit-AddInputResultTrait ## Signature ```rust theme={null} pub trait AddInputResultTrait ``` ## Trait functions ### next Adds an input value to the circuit instance. #### Arguments * `value` - The value to add as input, must be convertible to circuit input value #### Returns A new `AddInputResult` that can be used to add more inputs or finalize #### Panics Panics if all inputs have already been filled #### Signature ```rust theme={null} fn next, +Drop>( self: AddInputResult, value: Value, ) -> AddInputResult ``` ### done Finalizes the input process and returns the circuit data. #### Returns The complete circuit data ready for evaluation #### Panics Panics if not all required inputs have been filled #### Signature ```rust theme={null} fn done(self: AddInputResult) -> CircuitData ``` # core::circuit::AddMod Source: https://docs.starknet.io/build/corelib/core-circuit-AddMod Builtin for modular addition operations. ## Signature ```rust theme={null} pub extern type AddMod; ``` # core::circuit::Circuit Source: https://docs.starknet.io/build/corelib/core-circuit-Circuit A type that creates a circuit from a tuple of outputs. This type represents a complete circuit instance, constructed from its output gates. The type parameter `Outputs` defines the structure of the circuit's outputs. ## Signature ```rust theme={null} pub extern type Circuit; ``` # core::circuit::CircuitDefinition Source: https://docs.starknet.io/build/corelib/core-circuit-CircuitDefinition A trait for defining a circuit's structure and behavior. This trait is used to define the structure of a circuit, including its inputs, gates, and outputs. It provides the foundation for circuit evaluation. The `CES` type parameter represents a tuple of `CircuitElement`s that together define the circuit's structure. ## Signature ```rust theme={null} pub trait CircuitDefinition ``` ## Trait types ### CircuitType The internal circuit type representing a tuple of `CircuitElement`s. #### Signature ```rust theme={null} type CircuitType; ``` # core::circuit::CircuitElement Source: https://docs.starknet.io/build/corelib/core-circuit-CircuitElement A wrapper for circuit elements, used to construct circuits. This type provides a generic wrapper around different circuit components (inputs, gates) and enables composition of circuit elements through arithmetic operations. The type parameter `T` defines the specific role of the element in the circuit. ## Signature ```rust theme={null} pub struct CircuitElement {} ``` # core::circuit::CircuitElementCopy Source: https://docs.starknet.io/build/corelib/core-circuit-CircuitElementCopy ## Signature ```rust theme={null} pub impl CircuitElementCopy of Copy>; ``` # core::circuit::CircuitElementDrop Source: https://docs.starknet.io/build/corelib/core-circuit-CircuitElementDrop ## Signature ```rust theme={null} pub impl CircuitElementDrop of Drop>; ``` # core::circuit::CircuitElementTrait Source: https://docs.starknet.io/build/corelib/core-circuit-CircuitElementTrait A marker trait for keeping track of which types are valid circuit elements. This trait is implemented for all valid circuit components including inputs and gates. It provides type safety when composing circuit elements. ## Signature ```rust theme={null} pub trait CircuitElementTrait ``` # core::circuit::CircuitInput Source: https://docs.starknet.io/build/corelib/core-circuit-CircuitInput Defines an input for a circuit. Represents an input signal in the circuit, indexed by `N`. Each input must be assigned a value before circuit evaluation. ## Signature ```rust theme={null} pub extern type CircuitInput; ``` # core::circuit::CircuitInputs Source: https://docs.starknet.io/build/corelib/core-circuit-CircuitInputs ## Signature ```rust theme={null} pub trait CircuitInputs ``` ## Trait functions ### new\_inputs Initializes a new circuit instance with inputs. This function creates a new input accumulator for the circuit, which can then be used to add input values sequentially. #### Signature ```rust theme={null} fn new_inputs, +Drop>( self: CES, ) -> AddInputResult ``` #### Returns An `AddInputResult` that can be used to add input values to the circuit # core::circuit::CircuitModulus Source: https://docs.starknet.io/build/corelib/core-circuit-CircuitModulus A type that can be used as a circuit modulus (a u384 that is not zero or one). The modulus defines the finite field over which the circuit operates. It must be: * A 384-bit number (represented as four 96-bit limbs) * Not zero or one * Typically a prime number for cryptographic applications ## Signature ```rust theme={null} pub extern type CircuitModulus; ``` # core::circuit::CircuitOutputsTrait Source: https://docs.starknet.io/build/corelib/core-circuit-CircuitOutputsTrait A trait for retrieving output values from a circuit evaluation. This trait provides methods to access the output values of a circuit after successful evaluation. ## Signature ```rust theme={null} pub trait CircuitOutputsTrait ``` ## Examples ```rust theme={null} let a = CircuitElement::> {}; let b = CircuitElement::> {}; let modulus = TryInto::::try_into([2, 0, 0, 0]).unwrap(); let circuit = (a,b).new_inputs() .next([10, 0, 0, 0]) .next([11, 0, 0, 0]) .done() .eval(modulus) .unwrap(); let a_mod_2 = circuit.get_output(a); // Returns the output value of `a mod 2` let b_mod_2 = circuit.get_output(b); // Returns the output value of `b mod 2` assert!(a_mod_2 == 0.into()); assert!(b_mod_2 == 1.into()); ``` ## Trait functions ### get\_output Gets the output value for a specific circuit element. #### Signature ```rust theme={null} fn get_output( self: Outputs, output: OutputElement, ) -> u384 ``` #### Arguments * `output` - The circuit element to get the output for #### Returns The output value as a u384 # core::circuit::ConstOne Source: https://docs.starknet.io/build/corelib/core-circuit-ConstOne ## Signature ```rust theme={null} pub type ConstOne = BoundedInt; ``` # core::circuit::ConstZero Source: https://docs.starknet.io/build/corelib/core-circuit-ConstZero Expose the const required by the libfunc to allow the compiler const reusage. ## Signature ```rust theme={null} pub type ConstZero = BoundedInt; ``` # core::circuit::DestructFailureGuarantee Source: https://docs.starknet.io/build/corelib/core-circuit-DestructFailureGuarantee ## Signature ```rust theme={null} pub impl DestructFailureGuarantee of Destruct; ``` ## Impl functions ### destruct #### Signature ```rust theme={null} fn destruct(self: CircuitFailureGuarantee) ``` # core::circuit::EvalCircuitTrait Source: https://docs.starknet.io/build/corelib/core-circuit-EvalCircuitTrait ## Signature ```rust theme={null} pub trait EvalCircuitTrait ``` ## Trait functions ### eval Evaluates the circuit with the given modulus. #### Arguments * `modulus` - The modulus to use for arithmetic operations #### Returns Result containing either the circuit outputs or a failure indication #### Signature ```rust theme={null} fn eval( self: CircuitData, modulus: CircuitModulus, ) -> Result, (CircuitPartialOutputs, CircuitFailureGuarantee)> ``` ### eval\_ex Evaluates the circuit with an explicit descriptor and modulus. #### Arguments * `descriptor` - The circuit descriptor * `modulus` - The modulus to use for arithmetic operations #### Returns Result containing either the circuit outputs or a failure indication #### Signature ```rust theme={null} fn eval_ex( self: CircuitData, descriptor: CircuitDescriptor, modulus: CircuitModulus, ) -> Result, (CircuitPartialOutputs, CircuitFailureGuarantee)> ``` # core::circuit::MulMod Source: https://docs.starknet.io/build/corelib/core-circuit-MulMod Builtin for modular multiplication operations. ## Signature ```rust theme={null} pub extern type MulMod; ``` # core::circuit::RangeCheck96 Source: https://docs.starknet.io/build/corelib/core-circuit-RangeCheck96 Range check builtin for 96-bit operations. ## Signature ```rust theme={null} pub extern type RangeCheck96; ``` # core::circuit::circuit_add Source: https://docs.starknet.io/build/corelib/core-circuit-circuit_add Creates a new circuit element representing addition modulo p of two input circuits. This function combines two circuit elements using modular addition, creating a new circuit element that represents their sum modulo the circuit's modulus. ## Signature ```rust theme={null} pub fn circuit_add, +CircuitElementTrait>( lhs: CircuitElement, rhs: CircuitElement, ) -> CircuitElement> ``` #### Arguments * `lhs` - Left-hand side circuit element * `rhs` - Right-hand side circuit element #### Returns A new circuit element representing `(lhs + rhs) mod p` ## Examples ```rust theme={null} let a = CircuitElement::> {}; let b = CircuitElement::> {}; let sum = circuit_add(a, b); ``` # core::circuit::circuit_inverse Source: https://docs.starknet.io/build/corelib/core-circuit-circuit_inverse Creates a new circuit element representing the multiplicative inverse modulo p of an input circuit. This function creates a new circuit element representing the multiplicative inverse of the input element modulo the circuit's modulus. The operation will fail during evaluation if the input is not invertible (not coprime with the modulus). ## Signature ```rust theme={null} pub fn circuit_inverse>( input: CircuitElement, ) -> CircuitElement> ``` #### Arguments * `input` - Circuit element to compute the inverse of #### Returns A new circuit element represent
프로젝트로 돌아가기