Skip to content

research(railgun): add Shell cryptography and hardware benchmarks - #235

Draft
0xterricola wants to merge 16 commits into
keycard-tech:masterfrom
0xterricola:research/railgun-upstream-v1
Draft

0xterricola wants to merge 16 commits into
keycard-tech:masterfrom
0xterricola:research/railgun-upstream-v1

Conversation

@0xterricola

@0xterricola 0xterricola commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Experimental RAILGUN cryptographic research for Keycard Shell, exploring the feasibility of executing RAILGUN-compatible arithmetic on the STM32H573 Cortex-M33 MCU using its hardware Public Key Accelerator (PKA).

Current status: Physical hardware validation completed — 10/10 runs passed, 50/50 diagnostic checks successful.

This is a research integration, not a production RAILGUN wallet implementation.

Implementation

Introduces the following experimental components:

  • BN254 / BabyJubjub: Field arithmetic, point validation, point addition, and public-scalar multiplication.
  • Poseidon t6: RAILGUN-compatible hashing using HAL-backed modular arithmetic.
  • BLAKE-512: Compatibility implementation and native reference-vector tests.
  • Native tests: Reference vectors, synthetic EdDSA-Poseidon signing compatibility, full-width public-scalar operations, and edge-case coverage.
  • Hardware diagnostics: Public-vector benchmarks on the Shell's STM32 PKA.
  • QR export: Structured JSON containing diagnostic statuses, execution times, and firmware revision.

On-device navigation

Extras → Kohaku Research → RAILGUN Diagnostics

The diagnostics execute entirely on the Shell MCU, without accessing private keys or communicating with the Keycard secure element.

Maintainer Feedback and Firmware Updates

Following hardware feedback from @mikkoph:

  • Rebased the research branch onto upstream v1.5.3.
  • Restored app/FreeRTOSConfig.h to the upstream configuration.
  • Removed the experimental stack-overflow hook and stack high-water instrumentation.
  • Removed the associated stack_free field from QR exports.
  • Rebuilt the native tests and Cortex-M33 firmware.

An earlier experimental firmware build failed to boot on the maintainer's development device.

After these changes, the updated developer-signed firmware booted successfully on my physical Shell and completed all hardware diagnostics.

The exact cause of the original boot failure has not been independently isolated.

Validated revision: 0506470

Physical Hardware Validation

Hardware: Keycard Shell (STM32H573)
Firmware base: v1.5.3
Revision: 0506470
Test runs: 10 consecutive complete runs
Diagnostic checks: 50
Failures: 0

Benchmark Results

Diagnostic Passed Average Range
BN254 PKA ×64 10/10 3.5 ms 3–4 ms
BN254 boundary vectors 10/10 0.2 ms 0–1 ms
Poseidon t6 10/10 157.7 ms 157–158 ms
BabyJubjub small 10/10 1.8 ms 1–2 ms
BabyJubjub full-width 10/10 281.2 ms 281–282 ms

Observations

  • 10/10 complete hardware runs passed.
  • 50/50 individual diagnostics passed.
  • No observed freezes, unexpected resets, or timeouts.
  • QR benchmark exports successfully decoded.
  • Execution timings remained consistent across all runs.
  • The earlier boot failure did not recur with the updated firmware.

The 0 ms boundary measurements reflect millisecond timer resolution, not zero computation time.

Representative Hardware Output

{
  "v": 1,
  "rev": "0506470",
  "bn64": {"s": "pass", "ms": 4},
  "bnedge": {"s": "pass", "ms": 0},
  "p6": {"s": "pass", "ms": 158},
  "bj2": {"s": "pass", "ms": 2},
  "bj256": {"s": "pass", "ms": 281}
}

Build and Test Validation

All four targeted native regression suites pass:

  • bignum
  • railgun_babyjubjub
  • railgun_poseidon
  • railgun_blake512

The unsigned STM32H573 Cortex-M33 ELF also builds and links successfully.

Firmware Memory

Resource Measurement
Flash (text + data) 298,886 bytes
Static RAM (data + BSS) 642,576 bytes
Remaining RAM within 640 KiB 12,784 bytes
Core task stack allocation 8,192 bytes

These measurements include existing firmware infrastructure, including the camera framebuffer and memory pool.

The remaining RAM margin warrants consideration before expanding the implementation.

Custom FreeRTOS stack instrumentation has been removed to preserve upstream configuration compatibility.

Security Review and Limitations

Initial independent research review identified additional coverage requirements, including:

  • BabyJubjub low-order-point behavior and subgroup-validation considerations.
  • Full-width BN254 field boundary vectors.
  • Cooperative execution timeouts and diagnostic limits.
  • Separation of public arithmetic from secret-dependent operations.

Regression coverage was added for the relevant arithmetic cases.

This work does not provide:

  • Keycard private-key extraction or handling.
  • Secure-element signing through the RAILGUN integration.
  • Groth16 proof generation.
  • RAILGUN transaction construction or broadcasting.
  • A complete RAILGUN wallet.
  • Production-grade side-channel protection.

The public-scalar arithmetic implementation is variable-time and must not be reused for secret scalars without further security engineering.

Hardware validation confirms the tested public-vector arithmetic operations only. It does not establish production readiness or long-term hardware reliability.

Current Status

  • BN254 / BabyJubjub arithmetic implementation
  • Poseidon t6 compatibility
  • BLAKE-512 compatibility
  • Native cryptographic reference-vector tests
  • Initial security review and follow-up regression coverage
  • STM32 hardware PKA integration
  • Experimental Shell diagnostics menu
  • JSON QR benchmark export
  • Rebase onto upstream v1.5.3
  • Restore upstream FreeRTOS configuration
  • Cortex-M33 firmware build validation
  • Physical firmware boot validation
  • 10/10 consecutive physical hardware runs passed
  • 50/50 diagnostic checks passed
  • Maintainer review and architectural feedback
  • Additional security review if the scope expands

Open Questions / Next Steps

I'd appreciate maintainer feedback on whether these diagnostics are useful to retain upstream as experimental research.

Areas where guidance would be especially valuable:

  • Whether this functionality belongs in the Shell firmware or should remain a separate research branch.
  • Whether the implementation should be simplified or reorganized.
  • Additional hardware testing or memory constraints to address.
  • Appropriate separation of cryptographic responsibilities between the Shell MCU and Keycard secure element.
  • Which follow-up experiments, if any, would be most useful.

I'd prefer to align on the architecture and scope before expanding the implementation further.


Status: Draft — experimental cryptographic research, not production wallet functionality.

@0xterricola

Copy link
Copy Markdown
Contributor Author

Daybreak Blue — Independent Security Review Follow-up

Completed an independent, read-only review of the RAILGUN research implementation at 5272fb7, followed by two isolated test commits.

Findings and follow-ups

  • BN254 hardware coverage: The original 64-operation benchmark exercised only 7 × 11. Added full-width modular arithmetic boundary vectors in ab36627, preserving the original benchmark separately.
  • BabyJubjub subgroup validation: Confirmed that the public-scalar API accepts the order-two point (0, Fr−1). Added a native regression test in e9cccc7. The API remains documented as variable-time and does not enforce subgroup membership.
  • Execution budgets: Diagnostic timeouts remain cooperative soft deadlines. Actual device latency and stack headroom require hardware measurement.
  • Security boundary: No path was identified in the current diagnostics that passes Keycard secret material into the variable-time arithmetic.

Validation

All four targeted native test suites pass. The unsigned Cortex-M33 firmware links successfully. The expanded QR report fits the 320-byte buffer in representative worst-case size testing.

(cherry picked from commit 70e45fbb41cc5a5515b63a5dd0c364c8e20782f7)
(cherry picked from commit f6bcc9d31fa45187b0d207c52d9275af0cea25fb)
(cherry picked from commit e43cc52a754de15c2cc104a5f700b919333f43f5)
(cherry picked from commit 36ff99c00eed25ec92a8074278ae31c1824ffa2e)
(cherry picked from commit deca99e6c656db1a05226749931e40212733284f)
(cherry picked from commit f5ed427d9af991732e3ee998d21529382ce724c2)
(cherry picked from commit 5542d884ab1672ecd001d3ed18c2b354477d3171)
@0xterricola
0xterricola force-pushed the research/railgun-upstream-v1 branch from e9cccc7 to 0506470 Compare November 13, 2026 07:53
@0xterricola

Copy link
Copy Markdown
Contributor Author

Quick update following the initial hardware feedback:

I've rebased PR #235 onto upstream v1.5.3 and restored FreeRTOSConfig.h to its original configuration, removing the custom stack-overflow hook and monitoring code.

The updated developer-signed firmware now boots successfully on my physical Shell.

I also completed 10 consecutive hardware diagnostic runs using revision 0506470:

  • 10/10 complete runs passed
  • 50/50 individual diagnostic checks passed
  • QR exports worked consistently
  • No observed freezes, resets, or timeouts

I've updated the PR description with the full benchmark results, implementation details, and current limitations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant