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
 7mod bit;
 8pub mod hash;
 9pub mod merkle;
10
11// RE-EXPORTS
12// ================================================================================================
13
14pub use winter_crypto::{RandomCoin, RandomCoinError};
15pub use winter_math::{fields::f64::BaseElement as Felt, FieldElement, StarkField};
16pub mod utils {
17    pub use winter_utils::{
18        collections, string, uninit_vector, ByteReader, ByteWriter, Deserializable,
19        DeserializationError, Serializable, SliceReader,
20    };
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// TESTS
42// ================================================================================================
43
44#[test]
45#[should_panic]
46fn debug_assert_is_checked() {
47    // enforce the release checks to always have `RUSTFLAGS="-C debug-assertions".
48    //
49    // some upstream tests are performed with `debug_assert`, and we want to assert its correctness
50    // downstream.
51    //
52    // for reference, check
53    // https://github.com/0xPolygonMiden/miden-vm/issues/433
54    debug_assert!(false);
55}
56
57#[test]
58#[should_panic]
59#[allow(arithmetic_overflow)]
60fn overflow_panics_for_test() {
61    // overflows might be disabled if tests are performed in release mode. these are critical,
62    // mandatory checks as overflows might be attack vectors.
63    //
64    // to enable overflow checks in release mode, ensure `RUSTFLAGS="-C overflow-checks"`
65    let a = 1_u64;
66    let b = 64;
67    assert_ne!(a << b, 0);
68}