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