feat(ffi): add extract_quic_network FFI for StoffelVM compatibility#65
Open
feat(ffi): add extract_quic_network FFI for StoffelVM compatibility#65
Conversation
…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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extract_quic_network()FFI function that extractsArc<QuicNetworkManager>fromNetworkOpaqueand returns it as a boxed Arc pointerfree_raw_quic_network()to free the extracted pointernew_quic_network_with_party_id()FFI function for MPC party ID mappingProblem
mpc-protocols'
NetworkOpaquewrapsGenericNetwork(an enum containingArc<QuicNetworkManager>), while StoffelVM'shb_engine_new()expects a rawBox<Arc<QuicNetworkManager>>. PassingNetworkOpaque*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:
extract_quic_network()- ExtractsArc<QuicNetworkManager>fromNetworkOpaquein the format StoffelVM expectsfree_raw_quic_network()- Frees the extracted pointernew_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 IDThis 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
cargo build --releasehoneybadger_mpc_demo.py🤖 Generated with Claude Code