-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Consolidated SDK with Rust-compatible builder API and FFI bindings #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mikerah
wants to merge
6
commits into
main
Choose a base branch
from
feature/mpcaas-ffi-bindings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
This commit adds the foundation for MPCaaS (MPC as a Service) support in the Python SDK, matching the Rust SDK's client-server architecture. New modules: - stoffel/native/: Core FFI infrastructure - _lib_loader.py: Centralized platform-specific library loading - types.py: ctypes structures (U256, ByteSlice, shares, etc.) - errors.py: Error code mappings and exception classes - quic_ffi.py: Raw ctypes bindings for QUIC networking - network.py: Async QUICNetwork wrapper with ThreadPoolExecutor - hb_client_ffi.py: HoneyBadger MPC client FFI bindings - stoffel/mpcaas/: MPCaaS protocol layer - protocol.py: Wire-compatible message serialization (bincode-style) - client.py: StoffelClient with builder pattern - server.py: StoffelServer with builder pattern - examples/honeybadger_mpc_demo.py: E2E demo matching Rust SDK The implementation uses ctypes FFI bindings to native Rust libraries for a minimal dependency footprint (security-first approach). Note: This is initial scaffolding. Full FFI integration requires native libraries to be built and some FFI exports may need additions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implements Phase 1 of parallel development plan (non-STO-356 blocked work):
Core Builder API:
- Add Stoffel entry point with compile(), compile_file(), load() methods
- Add StoffelBuilder with fluent API for MPC configuration
- Add StoffelRuntime thin wrapper holding program + MPCConfig
- Add ProtocolType, ShareType, OptimizationLevel enums
- Add unified error hierarchy matching Rust SDK
FFI Wrappers:
- Add vm_ffi.py for StoffelVM native bindings
- Add compiler_ffi.py for StoffelLang compiler bindings
- Add share_ffi.py for secret sharing FFI
Enhanced Program Class:
- Add bytecode() method to get raw bytes
- Add save() method to write bytecode to file
- Add list_functions() and execute_function() methods
MPC Configuration:
- Validate HoneyBadger constraint: n >= 3t + 1
- Validate ROBUST shares required for HoneyBadger
Tests:
- Add 39 unit tests for builder pattern and config validation
Usage:
from stoffel import Stoffel, ProtocolType
runtime = Stoffel.compile(source) \
.parties(5) \
.threshold(1) \
.build()
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Consolidates FFI implementations from closed PRs: - PR #3: VM bytecode loading (stoffel_load_bytecode, NativeVM.load()) - PR #4: MPC secret sharing (U256, FieldKind, NativeShareManager) Files added: - stoffel/_core.py: Working execute_local() implementation - stoffel/native/vm.py: NativeVM with load() method - stoffel/native/compiler.py: stoffel_compile_to_binary() FFI - stoffel/native/mpc.py: Complete MPC FFI with U256/FieldKind Closes: PR #3 (feature/vm-bytecode-execution) Closes: PR #4 (feature/mpc-protocols-ffi) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add VMWithMPC wrapper for executing bytecode with real MPC operations - Add HoneyBadger engine FFI bindings (hb_engine_ffi.py) - Add network FFI bindings (network_ffi.py) - Update server to use VMWithMPC for MPC computation - Add TLS initialization guard to prevent rustls panic on multiple calls - Export new MPC-VM integration classes from mpcaas module Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add FFI bindings for mpc-protocols' extract_quic_network() function which converts NetworkOpaque to a raw Arc<QuicNetworkManager> pointer that StoffelVM's hb_engine_new() expects. Changes: - quic_ffi.py: Add extract_quic_network() and free_raw_quic_network() bindings - network.py: Update get_hb_network() to return StoffelVM-compatible pointer - server.py: Re-enable HoneyBadger engine creation (was disabled for debugging) - hb_engine_ffi.py: Improve pointer handling for network argument This fixes the segfault caused by FFI type mismatch between mpc-protocols (NetworkOpaque wrapping GenericNetwork) and StoffelVM (expecting raw Arc). Requires: mpc-protocols PR #65 (feat/extract-quic-network-ffi branch) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add party_id parameter to QUICNetwork for proper MPC connection mapping. This fixes the "PREPROCESSING_FAILED" error in HoneyBadger preprocessing. Root cause: - new_quic_network() created random UUID-based node_ids - HoneyBadger expected sequential party IDs (0, 1, 2, etc.) - Network::send(recipient) couldn't find connections by party ID Changes: - quic_ffi.py: Add binding for new_quic_network_with_party_id FFI - network.py: Add party_id parameter to QUICNetwork - server.py: Pass party_id when creating network Test results: - Before: Immediate "PREPROCESSING_FAILED" error - After: Preprocessing runs (no immediate failure) 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
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
Consolidated Python SDK implementation with:
Stoffel.compile().parties(5).threshold(1).build())Changes
New High-Level API
Stoffelentry point withcompile(),compile_file(),load()methodsStoffelBuilderfluent builder for MPC configurationStoffelRuntimethin wrapper holding program + configMPCConfigdataclass matching Rust SDKProtocolType,ShareType,OptimizationLevelenumsStoffelError,CompilationError,ConfigurationError, etc.)FFI Bindings (ported from PRs #3 and #4)
stoffel/native/vm.py:NativeVMwithload()methodstoffel/native/compiler.py:stoffel_compile_to_binary()FFIstoffel/native/mpc.py: Complete MPC FFI withU256,FieldKind,NativeShareManagerstoffel/_core.py: Workingexecute_local()implementationMPCaaS Server (new)
stoffel/mpcaas/server.py: HoneyBadger MPC server with QUIC networkingstoffel/native/network.py: QUIC network FFI bindings with party ID supportstoffel/native/quic_ffi.py: Low-level QUIC FFI includingnew_quic_network_with_party_id()MPC Configuration Validation
n >= 3t + 1Supersedes
Dependencies
new_quic_network_with_party_id()FFI functionTest plan
Usage
🤖 Generated with Claude Code