Skip to content

feat(ffi): add extract_quic_network FFI for StoffelVM compatibility#65

Open
Mikerah wants to merge 2 commits intomainfrom
feat/extract-quic-network-ffi
Open

feat(ffi): add extract_quic_network FFI for StoffelVM compatibility#65
Mikerah wants to merge 2 commits intomainfrom
feat/extract-quic-network-ffi

Conversation

@Mikerah
Copy link
Contributor

@Mikerah Mikerah commented Jan 8, 2026

Summary

  • Add extract_quic_network() FFI function that extracts Arc<QuicNetworkManager> from NetworkOpaque and returns it as a boxed Arc pointer
  • Add free_raw_quic_network() to free the extracted pointer
  • NEW: Add new_quic_network_with_party_id() FFI function for MPC party ID mapping

Problem

mpc-protocols' NetworkOpaque wraps GenericNetwork (an enum containing Arc<QuicNetworkManager>), while StoffelVM's hb_engine_new() expects a raw Box<Arc<QuicNetworkManager>>. Passing NetworkOpaque* directly to StoffelVM causes a segfault due to memory layout mismatch.

Additionally, MPC preprocessing requires correct party ID mapping - the network layer's socket index must match the MPC protocol's party ID to ensure share distribution is consistent.

Solution

Add extraction and party ID functions:

  1. extract_quic_network() - Extracts Arc<QuicNetworkManager> from NetworkOpaque in the format StoffelVM expects
  2. free_raw_quic_network() - Frees the extracted pointer
  3. new_quic_network_with_party_id() - Creates a QUIC network with explicit party ID mapping, ensuring the local party index matches the MPC protocol's expected party ID

This enables the Python SDK to create networks via mpc-protocols FFI and pass them to StoffelVM's HoneyBadger engine with correct party ID alignment.

Test plan

  • Build passes with cargo build --release
  • Integration test with Python SDK's honeybadger_mpc_demo.py

🤖 Generated with Claude Code

…ibility

Add two new FFI functions to enable interoperability between mpc-protocols
network types and external libraries like StoffelVM:

- extract_quic_network(): Extracts Arc<QuicNetworkManager> from NetworkOpaque
  and returns it as a boxed Arc pointer compatible with StoffelVM's
  hb_engine_new() function
- free_raw_quic_network(): Frees the extracted pointer

This solves the FFI type mismatch where mpc-protocols uses NetworkOpaque
(wrapping GenericNetwork) while StoffelVM expects a raw Arc<QuicNetworkManager>.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Mikerah Mikerah requested review from GarryFCR and cadaniluk January 8, 2026 14:33
Add FFI function to create QUIC networks with specific party IDs.
This is essential for MPC operations where parties need consistent IDs
for handshakes and connection lookups.

The existing new_quic_network() generates random UUID-based node_ids,
which causes preprocessing failures when HoneyBadger tries to send to
sequential party IDs (0, 1, 2, etc.).

Changes:
- Add new_quic_network_with_party_id(party_id, returned_connections)
- Uses QuicNetworkManager::with_node_id(party_id)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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