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