Skip to content

Commit

Permalink
Add compile time warning for constants generation
Browse files Browse the repository at this point in the history
Added a compile time warning that checks if `assets/arc.bin` has enough
bytes to store the constants needed for the hades permutation.
  • Loading branch information
moCello committed Jan 31, 2024
1 parent d34c587 commit 56c7ccb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/hades/round_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ use crate::hades::{FULL_ROUNDS, PARTIAL_ROUNDS, WIDTH};

const ROUNDS: usize = FULL_ROUNDS + PARTIAL_ROUNDS;

/// `ROUND_CONSTANTS` constists on a static reference that points to the
/// `ROUND_CONSTANTS` consists on a static reference that points to the
/// pre-loaded 335 constant scalar of the bls12_381 curve.
///
/// These 335 `BlsScalar` constants are loaded from `assets/arc.bin`.
///
/// Check `assets/HOWTO.md` to see how we generated the constants.
pub const ROUND_CONSTANTS: [[BlsScalar; WIDTH]; ROUNDS] = {
let bytes = include_bytes!("../../assets/arc.bin");

// make sure that there are enough bytes for (WIDTH * ROUNDS) BlsScalar
// stored under 'assets/arc.bin'
if bytes.len() < WIDTH * ROUNDS * 32 {
panic!("There are not enough round constants stored in 'assets/arc.bin', have a look at the HOWTO to generate enough constants.");
}

let mut cnst = [[BlsScalar::zero(); WIDTH]; ROUNDS];

let mut i = 0;
Expand Down

0 comments on commit 56c7ccb

Please sign in to comment.