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