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