Skip to content

Commit 1f422e9

Browse files
authored
fix(l1): fix illegal instructions in certain ARM processors (#5143)
**Motivation** During ARM testing, ethrex would crash on certain ARM CPUs. The backtrace of the program was in the blake2b precompile in `crates/common/crypto/blake2f/aarch64.rs`. The specific instruction that crashed was the [XAR instruction](https://developer.arm.com/documentation/ddi0602/2022-03/SIMD-FP-Instructions/XAR--Exclusive-OR-and-Rotate-), which the documentation states that "This instruction is implemented only when FEAT_SHA3 is implemented." **Description** - Added check to `BLAKE2_FUNC` lazy evaluator to check for the `sha3` feature in the user's cpu at runtime. **Notes on testing** On an ARM CPU without the feature `sha3` the commit `fba993c9b337ab2a89664f0f39260b40e25ac4c8` includes a failing unit test. After `21fb29e439261de5c9f275f54a9de218759daa2f` the test should work.
1 parent bc46f8a commit 1f422e9

File tree

1 file changed

+34
-1
lines changed
  • crates/common/crypto/blake2f

1 file changed

+34
-1
lines changed

crates/common/crypto/blake2f/mod.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ type Blake2Func = fn(usize, &mut [u64; 8], &[u64; 16], &[u64; 2], bool);
1010

1111
static BLAKE2_FUNC: LazyLock<Blake2Func> = LazyLock::new(|| {
1212
#[cfg(target_arch = "aarch64")]
13-
if std::arch::is_aarch64_feature_detected!("neon") {
13+
if std::arch::is_aarch64_feature_detected!("neon")
14+
&& std::arch::is_aarch64_feature_detected!("sha3")
15+
{
1416
return self::aarch64::blake2b_f;
1517
}
1618

@@ -25,3 +27,34 @@ static BLAKE2_FUNC: LazyLock<Blake2Func> = LazyLock::new(|| {
2527
pub fn blake2b_f(rounds: usize, h: &mut [u64; 8], m: &[u64; 16], t: &[u64; 2], f: bool) {
2628
BLAKE2_FUNC(rounds, h, m, t, f)
2729
}
30+
31+
#[cfg(test)]
32+
mod tests {
33+
use super::*;
34+
#[test]
35+
fn blake2b_smoke() {
36+
let mut h = [1, 2, 3, 4, 5, 6, 7, 8];
37+
blake2b_f(
38+
12,
39+
&mut h,
40+
&[
41+
101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
42+
],
43+
&[1000, 1001],
44+
true,
45+
);
46+
assert_eq!(
47+
h,
48+
[
49+
16719151077261791083,
50+
2946084527549390899,
51+
18258373236029374890,
52+
15305391278487550604,
53+
16233503039257535911,
54+
17654926667207417465,
55+
12194914407095793501,
56+
13409096818966589674
57+
]
58+
);
59+
}
60+
}

0 commit comments

Comments
 (0)