This repository implements a Fuzzy Logic-based FSM (Finite State Machine) for detecting Side-Channel Attack based on four key signal features:
- Energy
- Peak Power
- Mean Power
- Hamming Distance
The fuzzy inference mechanism uses triangular membership functions (TMFs) to calculate the degree of membership for each input feature across multiple linguistic categories (Low, Medium, High). These degrees are then used in a multi-stage FSM to infer whether an attack is detected or not.
This module implements the Triangular Membership Function (TMF), a common fuzzy logic function used to express how much an input value belongs to a fuzzy set.
Given parameters ( a < b < c ), and input ( x ):
μ(x) = {
0 , x ≤ a
(x - a) / (b - a) , a < x ≤ b
(c - x) / (c - b) , b < x < c
0 , x ≥ c
}
where μ(x) is the membership function for each linguistic variable for the extracted features.
- Uses fixed-point Q3.7 representation with 10-bit width (i.e., ( x \in [0, 1023] )).
- Performs left-shift by 7 (
<<< 7) to scale up for fixed-point division. - Ensures no division by zero.
- Outputs 11-bit membership degree
y.
This module instantiates TMFs for all combinations of features and linguistic categories. The following are the raw values which are to be converted into Q3.7 Fixed-Point Binary Format for using in the Verilog Code.
| Feature | Low | Medium | High |
|---|---|---|---|
| Energy | (0, 2.3, 2.8) | (2.7, 3.35, 4.0) | (3.8, 4.5, 6) |
| Peak Power | (0, 0.065, 0.11) | (0.10, 0.13, 0.16) | (0.15, 0.18, 0.2) |
| Mean Power | (0, 0.048, 0.052) | (0.051, 0.055, 0.059) | (0.058, 0.061, 0.065) |
| Hamming Distance | (0, 1, 1) | (2, 3, 3) | (3, 4, 15) |
Each set of parameters corresponds to a fuzzy rule's membership function.
- For each feature and level (Low/Med/High), outputs an 11-bit fuzzy degree signal.
This is the main FSM that takes the fuzzy degrees and evaluates them in stages to infer an attack. The FSM transitions through the following states:
| State | Description |
|---|---|
S_START |
Initialization |
S_HAMMING |
Evaluate hamming_dist degrees |
S_ENERGY |
Evaluate energy degrees |
S_PEAK |
Evaluate peak_power degrees |
S_MEAN |
Evaluate mean_power degrees |
S_ATTACK |
Attack Detected |
S_NORMAL |
Normal Condition |
- In each stage, the FSM compares degrees (
low,med,high) for the respective feature. - A degree is considered significant if it exceeds the threshold (
DEGREE_THRESH = 8). - Priority is given to the category with the highest degree that surpasses the threshold.
attack_detected = 1→ If FSM reachesS_ATTACK.attack_detected = 0→ If FSM reachesS_NORMALor on reset.
A .csv file is provided in this repository containing test cases of the following features:
- Hamming Distance
- Energy
- Peak Power
- Mean Power
Each feature is assumed to be in floating-point format. For use in the Verilog testbench, each value must be converted to Q3.7 unsigned fixed-point representation.
- Multiply the value by 128 (i.e., ( 2^7 )).
- Round off the result to the nearest integer.
- Ensure the final result fits within the required bit-width (10 bits for Energy, Peak, and Mean; 8 bits for Hamming).
| Feature | Float Value | Q3.7 Conversion |
|---|---|---|
| Energy | 3.24 | 3.24 * 128 = 414.72 ~ 415 |
| Peak Power | 0.12 | 0.12 * 128 = 15.36 ~ 15 |
| Mean Power | 0.08 | 0.08 * 128 = 10.24 ~ 10 |
Use the converted integers as direct 10-bit/8-bit inputs in your testbench for simulation.
- Convert dataset values using the Q3.7 method as described.
- Write a testbench module that applies the converted values to the
fuzzy_attack_fsmmodule. - Simulate using your preferred simulator (ModelSim, Icarus Verilog, Vivado, etc.).
- Monitor
attack_detectedoutput for each test case.
The design is synthesized with a 100 MHz clock. A constraints file (.xdc) is included to define this clock input. It is essential to include this during synthesis and implementation in tools like Vivado or Quartus.
├── triangular_mf.v // Triangular Membership Function Module
├── fuzzifier.v // Fuzzification logic
├── fuzzy_attack_fsm.v // Fuzzy logic FSM for attack detection
├── Fuzzy_Classification_Result.csv // Dataset for testbench input generation
├── testbench.v // (To be created by user using dataset instructions)
├── constraints.xdc // 100 MHz clock constraint file