bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 73쪽 중 2쪽
ing `input^(-1) mod p`
## Examples
```rust theme={null}
let a = CircuitElement::> {};
let inv_a = circuit_inverse(a);
```
# core::circuit::circuit_mul
Source: https://docs.starknet.io/build/corelib/core-circuit-circuit_mul
Creates a new circuit element representing multiplication modulo p of two input circuits.
This function combines two circuit elements using modular multiplication, creating a new circuit
element that represents their product modulo the circuit's modulus.
## Signature
```rust theme={null}
pub fn circuit_mul, +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 product = circuit_mul(a, b);
```
# core::circuit::circuit_sub
Source: https://docs.starknet.io/build/corelib/core-circuit-circuit_sub
Creates a new circuit element representing subtraction modulo p of two input circuits.
This function combines two circuit elements using modular subtraction, creating a new circuit
element that represents their difference modulo the circuit's modulus.
## Signature
```rust theme={null}
pub fn circuit_sub, +CircuitElementTrait>(
lhs: CircuitElement, rhs: CircuitElement,
) -> CircuitElement>
```
#### Arguments
* `lhs` - Left-hand side circuit element (minuend)
* `rhs` - Right-hand side circuit element (subtrahend)
#### Returns
A new circuit element representing `(lhs - rhs) mod p`
## Examples
```rust theme={null}
let a = CircuitElement::> {};
let b = CircuitElement::> {};
let diff = circuit_sub(a, b);
```
# core::circuit::u384
Source: https://docs.starknet.io/build/corelib/core-circuit-u384
A 384-bit unsigned integer, used for circuit values.
## Signature
```rust theme={null}
#[derive(Copy, Drop, Debug, PartialEq)]
pub struct u384 {
pub limb0: BoundedInt,
pub limb1: BoundedInt,
pub limb2: BoundedInt,
pub limb3: BoundedInt,
}
```
## Members
### limb0
The least significant 96 bits
#### Signature
```rust theme={null}
pub limb0: BoundedInt
```
### limb1
Bits 96-191
#### Signature
```rust theme={null}
pub limb1: BoundedInt
```
### limb2
Bits 192-287
#### Signature
```rust theme={null}
pub limb2: BoundedInt
```
### limb3
The most significant 96 bits
#### Signature
```rust theme={null}
pub limb3: BoundedInt
```
# core::circuit::u96
Source: https://docs.starknet.io/build/corelib/core-circuit-u96
A 96-bit unsigned integer type used as the basic building block for multi-limb arithmetic.
## Signature
```rust theme={null}
pub type u96 = BoundedInt;
```
# core::clone::Clone
Source: https://docs.starknet.io/build/corelib/core-clone-Clone
A common trait for the ability to explicitly duplicate an object.
Differs from `Copy` in that `Copy` is implicit and inexpensive, while
`Clone` is always explicit and may or may not be expensive.
Since `Clone` is more general than `Copy`, you can automatically make anything
`Copy` be `Clone` as well.
## Signature
```rust theme={null}
pub trait Clone
```
## Derivable
This trait can be used with `#[derive]` if all fields are `Clone`. The `derive`d
implementation of `Clone` calls `clone` on each field.
## Trait functions
### clone
Returns a copy of the value.
#### Signature
```rust theme={null}
fn clone(self: @T) -> T
```
#### Examples
```rust theme={null}
let arr = array![1, 2, 3];
assert!(arr == arr.clone());
```
# core::cmp::max
Source: https://docs.starknet.io/build/corelib/core-cmp-max
Takes two comparable values `a` and `b` and returns
the greater of the two values.
## Signature
```rust theme={null}
pub fn max, +Drop, +Copy>(a: T, b: T) -> T
```
## Examples
```rust theme={null}
use core::cmp::max;
assert!(max(0, 1) == 1);
```
# core::cmp::min
Source: https://docs.starknet.io/build/corelib/core-cmp-min
Takes two comparable values `a` and `b` and returns
the smaller of the two values.
## Signature
```rust theme={null}
pub fn min, +Drop, +Copy>(a: T, b: T) -> T
```
## Examples
```rust theme={null}
use core::cmp::min;
assert!(min(0, 1) == 0);
```
# core::cmp::minmax
Source: https://docs.starknet.io/build/corelib/core-cmp-minmax
Takes two comparable values `a` and `b` and returns
a tuple with the smaller value and the greater value.
## Signature
```rust theme={null}
pub fn minmax, +Drop, +Copy>(a: T, b: T) -> (T, T)
```
## Examples
```rust theme={null}
use core::cmp::minmax;
assert!(minmax(0, 1) == (0, 1));
assert!(minmax(1, 0) == (0, 1));
```
# core::debug::print_byte_array_as_string
Source: https://docs.starknet.io/build/corelib/core-debug-print_byte_array_as_string
Prints a `ByteArray` as a string.
## Signature
```rust theme={null}
pub fn print_byte_array_as_string(self: ByteArray)
```
## Examples
```rust theme={null}
let ba: ByteArray = "123";
print_byte_array_as_string(@ba);
```
# core::ec::EcOp
Source: https://docs.starknet.io/build/corelib/core-ec-EcOp
## Signature
```rust theme={null}
pub extern type EcOp;
```
# core::ec::EcPoint
Source: https://docs.starknet.io/build/corelib/core-ec-EcPoint
A point on the STARK curve.
Points can be created using `EcPointTrait::new` or `EcPointTrait::new_from_x`.
The zero point represents the point at infinity.
## Signature
```rust theme={null}
pub extern type EcPoint;
```
# core::ec::EcPointImpl
Source: https://docs.starknet.io/build/corelib/core-ec-EcPointImpl
## Signature
```rust theme={null}
pub impl EcPointImpl of EcPointTrait;
```
## Impl functions
### new
Creates a new EC point from its (x, y) coordinates.
#### Arguments
* `x` - The x-coordinate of the point
* `y` - The y-coordinate of the point
#### Returns
Returns `None` if the point (x, y) is not on the curve.
#### Examples
```rust theme={null}
let point = EcPointTrait::new(
x: 336742005567258698661916498343089167447076063081786685068305785816009957563,
y: 1706004133033694959518200210163451614294041810778629639790706933324248611779,
).unwrap();
```
#### Signature
```rust theme={null}
fn new(x: felt252, y: felt252) -> Option
```
### new\_nz
Creates a new NonZero EC point from its (x, y) coordinates.
#### Signature
```rust theme={null}
fn new_nz(x: felt252, y: felt252) -> Option>
```
### new\_from\_x
Creates a new EC point from its x coordinate.
#### Arguments
* `x` - The x-coordinate of the point
#### Returns
Returns `None` if no point with the given x-coordinate exists on the curve.
#### Panics
Panics if `x` is 0, as this would be the point at infinity.
#### Examples
```rust theme={null}
let valid = EcPointTrait::new_from_x(1);
assert!(valid.is_some());
let invalid = EcPointTrait::new_from_x(0);
assert!(invalid.is_none());
```
#### Signature
```rust theme={null}
fn new_from_x(x: felt252) -> Option
```
### new\_nz\_from\_x
Creates a new NonZero EC point from its x coordinate.
#### Signature
```rust theme={null}
fn new_nz_from_x(x: felt252) -> Option>
```
### coordinates
Returns the coordinates of the EC point.
#### Returns
A tuple containing the (x, y) coordinates of the point.
#### Panics
Panics if the point is the point at infinity.
#### Examples
```rust theme={null}
let point_nz = EcPointTrait::new_nz_from_x(1).unwrap();
let (x, _y) = point_nz.coordinates();
assert!(x == 1);
```
#### Signature
```rust theme={null}
fn coordinates(self: NonZero) -> (felt252, felt252)
```
### x
Returns the x coordinate of the EC point.
#### Panics
Panics if the point is the point at infinity.
#### Examples
```rust theme={null}
let point_nz = EcPointTrait::new_nz_from_x(1).unwrap();
let x = point_nz.x();
assert!(x == 1);
```
#### Signature
```rust theme={null}
fn x(self: NonZero) -> felt252
```
### y
Returns the y coordinate of the EC point.
#### Panics
Panics if the point is the point at infinity.
#### Examples
```rust theme={null}
let gen_point =
EcPointTrait::new_nz_from_x(0x1ef15c18599971b7beced415a40f0c7deacfd9b0d1819e03d723d8bc943cfca).unwrap();
let y = gen_point.y();
assert!(y == 0x5668060aa49730b7be4801df46ec62de53ecd11abe43a32873000c36e8dc1f);
```
#### Signature
```rust theme={null}
fn y(self: NonZero) -> felt252
```
### mul
Computes the product of an EC point by the given scalar.
#### Arguments
* `scalar` - The scalar to multiply the point by
#### Returns
The resulting point after scalar multiplication.
#### Signature
```rust theme={null}
fn mul(self: EcPoint, scalar: felt252) -> EcPoint
```
# core::ec::EcPointTrait
Source: https://docs.starknet.io/build/corelib/core-ec-EcPointTrait
## Signature
```rust theme={null}
pub trait EcPointTrait
```
## Trait functions
### new
Creates a new EC point from its (x, y) coordinates.
#### Arguments
* `x` - The x-coordinate of the point
* `y` - The y-coordinate of the point
#### Returns
Returns `None` if the point (x, y) is not on the curve.
#### Examples
```rust theme={null}
let point = EcPointTrait::new(
x: 336742005567258698661916498343089167447076063081786685068305785816009957563,
y: 1706004133033694959518200210163451614294041810778629639790706933324248611779,
).unwrap();
```
#### Signature
```rust theme={null}
fn new(x: felt252, y: felt252) -> Option
```
### new\_nz
Creates a new NonZero EC point from its (x, y) coordinates.
#### Signature
```rust theme={null}
fn new_nz(x: felt252, y: felt252) -> Option>
```
### new\_from\_x
Creates a new EC point from its x coordinate.
#### Arguments
* `x` - The x-coordinate of the point
#### Returns
Returns `None` if no point with the given x-coordinate exists on the curve.
#### Panics
Panics if `x` is 0, as this would be the point at infinity.
#### Examples
```rust theme={null}
let valid = EcPointTrait::new_from_x(1);
assert!(valid.is_some());
let invalid = EcPointTrait::new_from_x(0);
assert!(invalid.is_none());
```
#### Signature
```rust theme={null}
fn new_from_x(x: felt252) -> Option
```
### new\_nz\_from\_x
Creates a new NonZero EC point from its x coordinate.
#### Signature
```rust theme={null}
fn new_nz_from_x(x: felt252) -> Option>
```
### coordinates
Returns the coordinates of the EC point.
#### Returns
A tuple containing the (x, y) coordinates of the point.
#### Panics
Panics if the point is the point at infinity.
#### Examples
```rust theme={null}
let point_nz = EcPointTrait::new_nz_from_x(1).unwrap();
let (x, _y) = point_nz.coordinates();
assert!(x == 1);
```
#### Signature
```rust theme={null}
fn coordinates(self: NonZero) -> (felt252, felt252)
```
### x
Returns the x coordinate of the EC point.
#### Panics
Panics if the point is the point at infinity.
#### Examples
```rust theme={null}
let point_nz = EcPointTrait::new_nz_from_x(1).unwrap();
let x = point_nz.x();
assert!(x == 1);
```
#### Signature
```rust theme={null}
fn x(self: NonZero) -> felt252
```
### y
Returns the y coordinate of the EC point.
#### Panics
Panics if the point is the point at infinity.
#### Examples
```rust theme={null}
let gen_point =
EcPointTrait::new_nz_from_x(0x1ef15c18599971b7beced415a40f0c7deacfd9b0d1819e03d723d8bc943cfca).unwrap();
let y = gen_point.y();
assert!(y == 0x5668060aa49730b7be4801df46ec62de53ecd11abe43a32873000c36e8dc1f);
```
#### Signature
```rust theme={null}
fn y(self: NonZero) -> felt252
```
### mul
Computes the product of an EC point by the given scalar.
#### Arguments
* `scalar` - The scalar to multiply the point by
#### Returns
The resulting point after scalar multiplication.
#### Signature
```rust theme={null}
fn mul(self: EcPoint, scalar: felt252) -> EcPoint
```
# core::ec::EcState
Source: https://docs.starknet.io/build/corelib/core-ec-EcState
Elliptic curve state.
Use this to perform multiple point operations efficiently.
Initialize with `EcStateTrait::init`, add points with `EcStateTrait::add`
or `EcStateTrait::add_mul`, and finalize with `EcStateTrait::finalize`.
## Signature
```rust theme={null}
pub extern type EcState;
```
# core::ec::EcStateImpl
Source: https://docs.starknet.io/build/corelib/core-ec-EcStateImpl
## Signature
```rust theme={null}
pub impl EcStateImpl of EcStateTrait;
```
## Impl functions
### init
Initializes an EC computation with the zero point.
#### Signature
```rust theme={null}
fn init() -> EcState
```
#### Examples
```rust theme={null}
let mut state = EcStateTrait::init();
```
### add
Adds a point to the computation.
#### Arguments
* `p` - The non-zero point to add
#### Signature
```rust theme={null}
fn add(ref self: EcState, p: NonZero)
```
### sub
Subtracts a point to the computation.
#### Arguments
* `p` - The non-zero point to subtract
#### Signature
```rust theme={null}
fn sub(ref self: EcState, p: NonZero)
```
### add\_mul
Adds the product `p * scalar` to the state.
#### Arguments
* `scalar` - The scalar to multiply the point by
* `p` - The non-zero point to multiply and add
#### Signature
```rust theme={null}
fn add_mul(ref self: EcState, scalar: felt252, p: NonZero)
```
### finalize\_nz
Finalizes the EC computation and returns the result as a non-zero point.
#### Returns
* `Option` - The resulting point, or None if the result is the zero point
#### Panics
Panics if the result is the point at infinity.
#### Signature
```rust theme={null}
fn finalize_nz(self: EcState) -> Option>
```
### finalize
Finalizes the EC computation and returns the result.
Returns the zero point if the computation results in the point at infinity.
#### Signature
```rust theme={null}
fn finalize(self: EcState) -> EcPoint
```
# core::ec::EcStateTrait
Source: https://docs.starknet.io/build/corelib/core-ec-EcStateTrait
## Signature
```rust theme={null}
pub trait EcStateTrait
```
## Trait functions
### init
Initializes an EC computation with the zero point.
#### Signature
```rust theme={null}
fn init() -> EcState
```
#### Examples
```rust theme={null}
let mut state = EcStateTrait::init();
```
### add
Adds a point to the computation.
#### Arguments
* `p` - The non-zero point to add
#### Signature
```rust theme={null}
fn add(ref self: EcState, p: NonZero)
```
### sub
Subtracts a point to the computation.
#### Arguments
* `p` - The non-zero point to subtract
#### Signature
```rust theme={null}
fn sub(ref self: EcState, p: NonZero)
```
### add\_mul
Adds the product `p * scalar` to the state.
#### Arguments
* `scalar` - The scalar to multiply the point by
* `p` - The non-zero point to multiply and add
#### Signature
```rust theme={null}
fn add_mul(ref self: EcState, scalar: felt252, p: NonZero)
```
### finalize\_nz
Finalizes the EC computation and returns the result as a non-zero point.
#### Returns
* `Option` - The resulting point, or None if the result is the zero point
#### Panics
Panics if the result is the point at infinity.
#### Signature
```rust theme={null}
fn finalize_nz(self: EcState) -> Option>
```
### finalize
Finalizes the EC computation and returns the result.
Returns the zero point if the computation results in the point at infinity.
#### Signature
```rust theme={null}
fn finalize(self: EcState) -> EcPoint
```
# core::ec::NonZeroEcPoint
Source: https://docs.starknet.io/build/corelib/core-ec-NonZeroEcPoint
A non-zero point on the STARK curve (cannot be the point at infinity).
## Signature
```rust theme={null}
pub type NonZeroEcPoint = NonZero;
```
# core::ec::ec_point_unwrap
Source: https://docs.starknet.io/build/corelib/core-ec-ec_point_unwrap
Unwraps a non-zero point into its (x, y) coordinates.
## Signature
```rust theme={null}
pub extern fn ec_point_unwrap(p: NonZero) -> (felt252, felt252) nopanic;
```
# core::ec::stark_curve::ALPHA
Source: https://docs.starknet.io/build/corelib/core-ec-stark_curve-ALPHA
The STARK Curve is defined by the equation y² ≡ x³ + α·x + β (mod p).
## Signature
```rust theme={null}
pub const ALPHA: felt252 = 1;
```
# core::ec::stark_curve::BETA
Source: https://docs.starknet.io/build/corelib/core-ec-stark_curve-BETA
The STARK Curve is defined by the equation y² ≡ x³ + α·x + β (mod p).
## Signature
```rust theme={null}
pub const BETA: felt252 = 3141592653589793238462643383279502884197169399375105820974944592307816406665;
```
# core::ec::stark_curve::GEN_X
Source: https://docs.starknet.io/build/corelib/core-ec-stark_curve-GEN_X
The x coordinate of the generator point used in the ECDSA signature.
## Signature
```rust theme={null}
pub const GEN_X: felt252 = 874739451078007766457464989774322083649278607533249481151382481072868806602;
```
# core::ec::stark_curve::GEN_Y
Source: https://docs.starknet.io/build/corelib/core-ec-stark_curve-GEN_Y
The y coordinate of the generator point used in the ECDSA signature.
## Signature
```rust theme={null}
pub const GEN_Y: felt252 = 152666792071518830868575557812948353041420400780739481342941381225525861407;
```
# core::ec::stark_curve::ORDER
Source: https://docs.starknet.io/build/corelib/core-ec-stark_curve-ORDER
The order (number of points) of the STARK Curve.
## Signature
```rust theme={null}
pub const ORDER: felt252 = 3618502788666131213697322783095070105526743751716087489154079457884512865583;
```
# core::ecdsa::check_ecdsa_signature
Source: https://docs.starknet.io/build/corelib/core-ecdsa-check_ecdsa_signature
Verifies an ECDSA signature against a message hash and public key.
Note: the verification algorithm implemented by this function slightly deviates from the
standard ECDSA.
While this does not allow to create valid signatures if one does not possess the private key,
it means that the signature algorithm used should be modified accordingly.
This function validates that `s` and `r` are not 0 or equal to the curve order,
but does not check that \`r, s bool
```
```
# core::ecdsa::recover_public_key
Source: https://docs.starknet.io/build/corelib/core-ecdsa-recover_public_key
Recovers the public key from an ECDSA signature and message hash.
Given a valid ECDSA signature, the original message hash, and the y-coordinate parity of point
R, this function recovers the signer's public key. This is useful in scenarios where you need to
verify a message has been signed by a specific public key.
## Signature
```rust theme={null}
pub fn recover_public_key(
message_hash: felt252, signature_r: felt252, signature_s: felt252, y_parity: bool,
) -> Option
```
#### Arguments
* `message_hash` - The hash of the signed message
* `signature_r` - The r component of the ECDSA signature (x-coordinate of point R)
* `signature_s` - The s component of the ECDSA signature
* `y_parity` - The parity of the y-coordinate of point R (`true` for odd, `false` for even)
#### Returns
Returns `Some(public_key)` containing the x-coordinate of the recovered public key point if
the signature is valid, `None` otherwise.
## Examples
```rust theme={null}
use core::ecdsa::recover_public_key;
let message_hash = 0x503f4bea29baee10b22a7f10bdc82dda071c977c1f25b8f3973d34e6b03b2c;
let signature_r = 0xbe96d72eb4f94078192c2e84d5230cde2a70f4b45c8797e2c907acff5060bb;
let signature_s = 0x677ae6bba6daf00d2631fab14c8acf24be6579f9d9e98f67aa7f2770e57a1f5;
assert!(
recover_public_key(:message_hash, :signature_r, :signature_s, y_parity: false)
.unwrap() == 0x7b7454acbe7845da996377f85eb0892044d75ae95d04d3325a391951f35d2ec,
)
```
# core::felt252
Source: https://docs.starknet.io/build/corelib/core-felt252
`felt252` is the basic field element used in Cairo.
It corresponds to an integer in the range 0 ≤ x \< P where P is
a very large prime number currently equal to 2^251 + 17⋅2^192 + 1.
Any operation that uses `felt252` will be computed modulo P.
## Signature
```rust theme={null}
pub extern type felt252;
```
# core::felt252_div
Source: https://docs.starknet.io/build/corelib/core-felt252_div
Performs division on `felt252` values in Cairo's finite field.
Unlike regular integer division, `felt252` division returns a field element n that satisfies
the equation: n \* rhs ≡ lhs (mod P), where P is the `felt252` prime.
## Signature
```rust theme={프로젝트로 돌아가기