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