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