Skip to main content

A transpilation plugin for Qiskit with a modified layout stage that encodes (classical) information using the virtual-to-physical qubit mapping

Project description

qiskit-layout-attack

Build & Test Python Wheel Package PyPI - Version PyPI - Wheel arXiv

[!NOTE] This plugin was developed to demonstrate the importance of reproducible builds in the Qiskit quantum computing workflow. It shows that non-reproducibility in the transpilation process (specifically during the layout stage) can be exploited to encode classical information into the transpiled quantum circuit. If an attacker subsequently gains access to the job description, this can lead to the leakage of confidential data.

A transpilation layout plugin for Qiskit that demonstrates how a modified transpilation stage can be used to hide classical information in the final transpiled quantum circuit.

The current implementation, by default, tries to encode the UTF-8 encoded string My secret data encoded in the transpiled circuit layout. into the transpiled circuit. Custom data will be used if available in builtins.data (see the example below). If data is too large to be encoded into the given circuit, the layout plugin fallbacks to the TrivialLayout, which maps virtual qubits to physical qubits in the trivial way (i.e., $0\rightarrow0$, $1\rightarrow1$, etc.).

The plugin is implemented as a subclass of PassManagerStagePlugin, which uses a custom pass called LeakyLayout. This pass is implemented as a subclass of AnalysisPass, since no changes to the quantum circuit are done.

Encoded data can be recovered with the recover_data() function implemented in the decoder module. See the example below.

Installation

git clone https://github.com/iyanmv/qiskit-leaky-layout.git
cd qiskit-leaky-layout
pip install .

Example

import builtins
from qiskit.circuit import QuantumCircuit
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit.transpiler.preset_passmanagers.plugin import list_stage_plugins
from qiskit_ibm_runtime.fake_provider import FakeBrisbane
from qiskit_leaky_layout.decoder import recover_data

# Check that layout plugin was installed successfully
assert "leaky_layout" in list_stage_plugins("layout")

# Fake 127-qubit backend used as target for the transpilation
backend = FakeBrisbane()

# Pass manager for the transpilation with our custom layout plugin
pm = generate_preset_pass_manager(
    optimization_level=3, backend=backend, layout_method="leaky_layout"
)

# 3-qubit GHZ circuit
qc = QuantumCircuit(backend.num_qubits)
qc.h(0)
qc.cx(0, range(1, 3))

# Uncomment to encode these bytes instead of the default message
# builtins.data = b"\x12Y\xfd$^%g\xcbf\x1b"

# Transpiled circuit
isa_qc = pm.run(qc)

# Recover data as raw bytes
recovered_default_message = recover_data(isa_qc, size_alphabet=127)[-56:]
assert (recovered_default_message == b"My secret data encoded in the transpiled circuit layout.")

# recovered_custom_message = recover_data(isa_qc, size_alphabet=127)[-10:]
# assert recovered_custom_message == b"\x12Y\xfd$^%g\xcbf\x1b"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qiskit_leaky_layout-0.2.4.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qiskit_leaky_layout-0.2.4-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file qiskit_leaky_layout-0.2.4.tar.gz.

File metadata

  • Download URL: qiskit_leaky_layout-0.2.4.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for qiskit_leaky_layout-0.2.4.tar.gz
Algorithm Hash digest
SHA256 af2f136b2b7d778d8a72b7fa9e56474ab787118f92d75c2d932e970987109ed6
MD5 db2969ce7c3965435c7f1e21fc19d2be
BLAKE2b-256 40b1a5c2be3a8fa3e56ac37823202c83c8c9d0669f5ffb31fa146f92dda80437

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit_leaky_layout-0.2.4.tar.gz:

Publisher: publish-to-pypi.yml on iyanmv/qiskit-leaky-layout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qiskit_leaky_layout-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for qiskit_leaky_layout-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8702c58b765572718b4a21695e152190b2fabe7a7419f6bb2c2553768b9621a0
MD5 5fa7eb2cc67397fb59a5ef18bdb6cbaa
BLAKE2b-256 230c1f5f09e943ef4d5452391820f1c327d6f81de686f5cae2c6a9a326cb5116

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit_leaky_layout-0.2.4-py3-none-any.whl:

Publisher: publish-to-pypi.yml on iyanmv/qiskit-leaky-layout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page