arnaucube
arnaucube/miden-cryptoPublic Self-hosted repository
miden-crypto/src/lib.rs
src/lib.rsRaw
 1#![cfg_attr(not(feature = "std"), no_std)]
 2
 3#[cfg(not(feature = "std"))]
 4#[cfg_attr(test, macro_use)]
 5extern crate alloc;
 6
 7pub mod hash;
 8pub mod merkle;
 9
10// RE-EXPORTS
11// ================================================================================================
12
13pub use winter_crypto::{RandomCoin, RandomCoinError};
14pub use winter_math::{fields::f64::BaseElement as Felt, FieldElement, StarkField};
15pub mod utils {
16    pub use winter_utils::{
17        collections, string, uninit_vector, ByteReader, ByteWriter, Deserializable,
18        DeserializationError, Serializable, SliceReader,
19    };
20}
21
22// TYPE ALIASES
23// ================================================================================================
24
25/// A group of four field elements in the Miden base field.
26pub type Word = [Felt; WORD_SIZE];
27
28// CONSTANTS
29// ================================================================================================
30
31/// Number of field elements in a word.
32pub const WORD_SIZE: usize = 4;
33
34/// Field element representing ZERO in the Miden base filed.
35pub const ZERO: Felt = Felt::ZERO;
36
37/// Field element representing ONE in the Miden base filed.
38pub const ONE: Felt = Felt::ONE;
39
40// TESTS
41// ================================================================================================
42
43#[test]
44#[should_panic]
45fn debug_assert_is_checked() {
46    // enforce the release checks to always have `RUSTFLAGS="-C debug-assertions".
47    //
48    // some upstream tests are performed with `debug_assert`, and we want to assert its correctness
49    // downstream.
50    //
51    // for reference, check
52    // https://github.com/0xPolygonMiden/miden-vm/issues/433
53    debug_assert!(false);
54}
55
56#[test]
57#[should_panic]
58#[allow(arithmetic_overflow)]
59fn overflow_panics_for_test() {
60    // overflows might be disabled if tests are performed in release mode. these are critical,
61    // mandatory checks as overflows might be attack vectors.
62    //
63    // to enable overflow checks in release mode, ensure `RUSTFLAGS="-C overflow-checks"`
64    let a = 1_u64;
65    let b = 64;
66    assert_ne!(a << b, 0);
67}