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/// Array of field elements representing word of ZEROs in the Miden base field.
36pub const EMPTY_WORD: [Felt; 4] = [ZERO; WORD_SIZE];
37
38// TESTS
39// ================================================================================================
40
41#[test]
42#[should_panic]
43fn debug_assert_is_checked() {
44 // enforce the release checks to always have `RUSTFLAGS="-C debug-assertions".
45 //
46 // some upstream tests are performed with `debug_assert`, and we want to assert its correctness
47 // downstream.
48 //
49 // for reference, check
50 // https://github.com/0xPolygonMiden/miden-vm/issues/433
51 debug_assert!(false);
52}
53
54#[test]
55#[should_panic]
56#[allow(arithmetic_overflow)]
57fn overflow_panics_for_test() {
58 // overflows might be disabled if tests are performed in release mode. these are critical,
59 // mandatory checks as overflows might be attack vectors.
60 //
61 // to enable overflow checks in release mode, ensure `RUSTFLAGS="-C overflow-checks"`
62 let a = 1_u64;
63 let b = 64;
64 assert_ne!(a << b, 0);
65}