AI-powered hardware Trojan detection · side-channel power analysis

Catch the Trojan by the power it draws.

A hardware Trojan can pass every functional test, but it cannot hide the extra current it pulls when its payload runs. RAQIB measures an ESP32-S3's supply current through a single 1 Ω shunt, digitises it with a 24-bit ADS1256 on a Raspberry Pi 4, and separates normal from Trojan behaviour with unsupervised clustering — no golden chip, no labelled Trojan data.

ADC ADS1256 24-bit
Sample rate 30,000 SPS
Shunt · gain 1 Ω · PGA 64
Live device NOT CONNECTED
1.84× Rise in mean supply current when the Trojan payload runs (1.24 → 2.27 mA)
100% Of 2,099 windows clustered into the right state, Normal vs Trojan (ARI 1.00)
0 Labelled Trojan examples used — the model picks its own clusters
≈$210 Total hardware cost (about 80 BHD), no oscilloscope required

Built for one question

Can a low-cost rig tell Trojan activity from normal operation using power consumption alone, without a trusted reference chip or labelled Trojan data? Every part of RAQIB exists to answer that.

Firmware-emulated Trojan

The ESP32-S3 runs a Trojan with a hidden trigger (a button press) and a payload that heats the chip with extra square-root computation: 30,000 operations per cycle in the Dormant state (33–37 °C) and 50,000 in the Active state (38–45 °C). A cooling routine drops the clock to 160 MHz until the chip is back at 29 °C.

Unsupervised clustering

The detector never sees a label. It compares k-means, a Gaussian mixture model and Ward clustering for k = 2–4 and keeps the model with the highest silhouette score. The recorded states are used only afterwards, to score how well the clusters match.

Physically meaningful features

Six power-level features (mean, RMS, energy, 10th percentile, median, 90th percentile) separated Normal from Trojan perfectly, while the full 19-feature set reached an ARI of only 0.17. Fewer features with a clear physical meaning beat a larger generic set.

Low-cost measurement chain

A single 1 Ω high-side shunt (1 mV per mA), an ADS1256 at 30,000 samples per second with a gain of 64, and a Raspberry Pi 4 reading it over SPI — in place of a benchtop oscilloscope and laboratory supply.

Local and reproducible

Everything runs on the Raspberry Pi or a laptop with no cloud service. A fixed random seed means the same recording always gives the same result.

Live device monitor

No device connected

Connect the Raspberry Pi to stream the supply current measured through the shunt, or plug the ESP32-S3 in over USB to follow its state and temperature.

Current—
250-sample mean—
Samples received—
Device state—
Chip temperature—
Live indicator—
Connection log
Waiting for a device…

Raspberry Pi: run python3 live_server.py next to the acquisition program, then open the site from the Pi at http://raspberrypi.local:8000 (or open it as a local file) and press Connect Raspberry Pi. ESP32-S3: needs Chrome or Edge on a computer; the board's serial output (115200 baud) is read directly. The live indicator is a simple threshold against a Normal baseline you set; the verdicts reported in the Results come from the offline clustering pipeline.

From a button press to a verdict

01

Trigger

A push button on the ESP32-S3 switches between Normal, Dormant and Active. A status LED shows the state, and FreeRTOS tasks share the internal temperature sensor through a semaphore.

02

Payload

Once triggered, the payload runs extra square-root computation until the chip reaches its target temperature, drawing measurably more current than normal operation.

03

Measure

The supply current crosses a 1 Ω high-side shunt. The ADS1256 reads AIN0−AIN1 differentially at gain 64, and the Pi 4 logs every sample to CSV over SPI.

04

Detect

The trace is cut into 250-sample windows (step 50). Features are standardised, reduced with PCA (95% variance) and clustered; the silhouette score chooses the model and number of clusters.

What the recording showed

One continuous recording of 105,654 samples: Normal (9,806), Trojan (92,886) and Cooling (2,962). The Trojan nearly doubled the supply current and added frequent short spikes.

Mean supply current by state
Detection scores (k-means, chosen by silhouette)
TaskFeaturesSilhouetteBalanced acc.ARI
Normal vs TrojanPower-level (6)0.90100%1.00
Normal vs TrojanFull set (19)0.4885.3%0.17
Three statesPower-level (6)0.9066.7%0.85
Three statesFull set (19)0.5265.9%0.30

All 192 Normal windows and all 1,907 Trojan-affected windows were assigned correctly. The 55 Cooling windows join the Trojan cluster, so the after-effect is still flagged as abnormal.

Shunt voltage and ESP32-S3 power across the whole recording, with Normal, Trojan and Cooling shaded
Shunt voltage (top) and ESP32-S3 power (bottom) across the recording.
Cluster assigned to each window along the recording; it switches exactly where the device moves from Normal to Trojan
The cluster switches at the exact window where the device moves from Normal to Trojan.

Limitations: one recording in a fixed order, one strong payload, and relative rather than absolute current values. Repeated randomised recordings and weaker payloads are the next step.

The assembled prototype: Raspberry Pi 4, ADS1256 module, and the ESP32-S3 breadboard with the shunt resistor, power module and three push buttons

The prototype

Everything sits on one breadboard and was built in four tested stages: ADC to Pi, the shunt, the ESP32-S3 with its buttons and LEDs, and a common ground.

  • Raspberry Pi 4 (4 GB)SPI0, CE0, 3.84 MHz, DRDY on GPIO25
  • ADS1256 ADCAIN0−AIN1, PGA 64, 30,000 SPS
  • ESP32-S3 N16R8Device under test, 3.3 V through the shunt
  • 1 Ω shunt resistorHigh-side, 1 mV per mA
  • Breadboard power module3.3 V supply for the ESP32-S3
  • 3 push buttons + LEDsGPIO1 / GPIO2 / GPIO38, LEDs on GPIO48 / 47 / 21

Built by

B

Batool Sayed Jaffar

Computer Engineering

E

Eman Rabeea Abdulla

Computer Engineering

W

Walaa Abdulla Alsabbagh

Computer Engineering

Academic supervision

RAQIB was developed as an ITCE 499 senior project in the Department of Computer Engineering, College of Information Technology, University of Bahrain (Academic Year 2026–2027, Semester 1).

Ebrahim Abdulrahman Janahi Project Supervisor · University of Bahrain

Get in touch

Questions about the measurement rig, the firmware Trojan or the clustering pipeline — reach out to the team.