Skip to content

Commit

Permalink
add safety comment on new_unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
tdelabro committed Jan 8, 2024
1 parent 687433a commit eab582e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ impl StarkFelt {
Err(StarknetApiError::OutOfRange { string: hex_str_from_bytes::<32, true>(bytes) })
}

/// Returns a new *unchecked* [`StarkFelt`]
///
/// # Safety
///
/// The internal representation of the `StarkFelt` type is 256 bits.
/// The `StarkFelt` type max value is 2^251 + 17 ∗ 21^92 + 1, which is less than `U256::MAX`.
/// The `StarkFelt::new` method make sure that you can't initialize a `StarkFelt` greater than
/// it's specification maximum. This method does not not. It's your responsability make sure
/// it's okay to call this method.
///
/// # Usage
///
/// Most of the time you should use `new` instead, but it comes handy for a few case:
/// - creating instances of `StarkFelt` at compile time
/// - implementing `From<T> for StarkFelt` on types that have a smaller binary representation
/// than `StarkFelt`
pub const fn new_unchecked(bytes: [u8; 32]) -> StarkFelt {
Self(bytes)
}
Expand Down

0 comments on commit eab582e

Please sign in to comment.