An experimental C# binding to BitVM2, enabling trust-minimized Bitcoin bridges from .NET.
PonziTech.BitVM provides a comprehensive .NET wrapper around BitVM, the trust-minimized Bitcoin bridge that implements Groth16 SNARK verification on Bitcoin without soft forks. This package enables CLR applications to:
- Execute Bitcoin scripts with full BitVM primitives
- Create and manage peg-in/peg-out bridge operations
- Work with Winternitz signatures and other BitVM cryptographic primitives
- Verify SNARK proofs using Groth16
# Install the core package
dotnet add package PonziTech.BitVM.Core
# Install the bridge package for peg-in/peg-out operations
dotnet add package PonziTech.BitVM.Bridgeusing PonziTech.BitVM.Core;
using PonziTech.BitVM.Bridge;
// Execute Bitcoin scripts
using var executor = new ScriptExecutor();
var result = await executor.ExecuteAsync(scriptBytes);
// Create bridge operations
var config = new BridgeConfiguration {
Network = BitcoinNetwork.Testnet,
EsploraUrl = "https://mempool.space/testnet/api",
VerifierPublicKeys = new[] { verifierPubkey }
};
using var bridge = new BridgeClient(config);
using var depositor = DepositorContext.Create(config, depositorWif);
var pegIn = await bridge.CreatePegInAsync(depositor, depositOutpoint, depositAmount, "0x1234...");PonziTech.BitVM.Native - Auto-generated P/Invoke bindings (FFI)
PonziTech.BitVM.Core - Core operations (script execution, crypto)
PonziTech.BitVM.Bridge - Bridge operations (peg-in/peg-out graphs)
┌─────────────────────────────────────────────────────────┐
│ C# Application (NBitcoin integration) │
├─────────────────────────────────────────────────────────┤
│ PonziTech.BitVM.Core │ PonziTech.BitVM.Bridge │
│ (Managed API) │ (Domain Operations) │
├─────────────────────────────────────────────────────────┤
│ PonziTech.BitVM.Native (Auto-generated FFI) │
├─────────────────────────────────────────────────────────┤
│ libbitvm_ffi.{dll/so/dylib} (Rust) │
├─────────────────────────────────────────────────────────┤
│ BitVM Core Library (Rust) │
│ - Script execution │
│ - Hash functions (SHA256, BLAKE3) │
│ - U32 operations │
│ - BN254 elliptic curves │
│ - Winternitz signatures │
│ - Groth16 verification │
├─────────────────────────────────────────────────────────┤
│ BitVM Bridge Library (Rust) │
│ - Peg-in/peg-out graphs │
│ - Transaction management │
│ - Multi-sig coordination │
└─────────────────────────────────────────────────────────┘
Core (script execution + crypto):
| Platform | Architecture | Status |
|---|---|---|
| Windows | x64 | ✅ Supported |
| Linux | x64 | ✅ Supported |
| macOS | x64 | ✅ Supported |
| macOS | ARM64 | ✅ Supported |
Bridge (peg-in/peg-out operations):
| Platform | Architecture | Status |
|---|---|---|
| Windows | x64 | ❌ Not supported (see note below) |
| Linux | x64 | ✅ Supported |
| macOS | x64 | ✅ Supported |
| macOS | ARM64 | ✅ Supported |
Note: The bridge Rust crate depends on unix-only SSH/SFTP components upstream. On Windows, the bridge FFI exports are present but return an error stating that bridge support is unavailable. Use WSL/Linux for bridge workflows.
- .NET 10.0 SDK
- Rust toolchain
- Git with submodules support
Option 1: Visual Studio 2022 (Recommended)
- Visual Studio 2022 with "Desktop development with C++" workload
- Or Build Tools for Visual Studio 2022 with C++ tools
Option 2: winget (Quick Install)
# Install all dependencies automatically
winget install Microsoft.DotNet.SDK.10
winget install Rustlang.Rustup
winget install Microsoft.VisualStudio.2022.BuildTools- Xcode Command Line Tools:
xcode-select --install
- GCC:
sudo apt install build-essential(Ubuntu/Debian) or equivalent - OpenSSL development libraries:
sudo apt install libssl-dev
# Check .NET
dotnet --version # Should be 10.0.x
# Check Rust
cargo --version # Should be 1.8x.x
# Check C++ compiler (Windows)
cl.exe # Should show Microsoft C/C++ Compiler
# Check C++ compiler (Unix)
gcc --version # Should show GCC version# Clone with submodules
git clone --recursive https://github.com/PonziTech/BitVM.git
cd BitVM
# Build everything (PowerShell)
./build/build.ps1 -Configuration Release
# Or manually:
cd ffi
cargo build --release
cd ..
dotnet build PonziTech.BitVM.sln -c Release# Build native libraries for all platforms
./build/build.ps1 -Configuration Release
# Pack NuGet packages
./build/build.ps1 -Configuration Release -Packusing var executor = new ScriptExecutor();
// Execute a simple script
var script = new byte[] { 0x51, 0x69 }; // OP_TRUE OP_VERIFY
var result = await executor.ExecuteAsync(script);
Console.WriteLine($"Success: {result.Success}");
Console.WriteLine($"Stack: {result.FinalStack}");using var executor = new ScriptExecutor();
// Generate SHA256 script
var sha256Script = executor.GenerateSha256Script(32);
// Generate BLAKE3 script
var blake3Script = executor.GenerateBlake3Script(128);
// Generate u32 operations
var pushScript = executor.GenerateU32PushScript(42);
var verifyScript = executor.GenerateU32EqualVerifyScript();// Generate keypair (20-byte secret)
var secret = WinternitzSignatures.GenerateSecret();
var pubkey = WinternitzSignatures.GetPublicKey(secret, WinternitzSignatures.MessageSize.Size16);
// Sign message
var message = new byte[16]; // 16 bytes for Size16
var signature = WinternitzSignatures.Sign(secret, message, WinternitzSignatures.MessageSize.Size16);
// Get verification script
var verifyScript = WinternitzSignatures.GetChecksigScript(pubkey, WinternitzSignatures.MessageSize.Size16);// Configure bridge
var config = new BridgeConfiguration {
Network = BitcoinNetwork.Testnet,
EsploraUrl = "https://mempool.space/testnet/api",
VerifierPublicKeys = new[] { verifierPubkey1, verifierPubkey2 }
};
// Create client
using var bridge = new BridgeClient(config);
// Create depositor context
using var depositor = DepositorContext.Create(config, depositorWif);
// Get deposit address
var depositAddress = depositor.GetAddress();
Console.WriteLine($"Deposit to: {depositAddress}");
// After funding, create peg-in graph
var depositTx = await GetDepositTransactionAsync(); // Your implementation
var pegIn = await bridge.CreatePegInAsync(depositor, depositTx.Outpoint, depositTx.Amount, "0xYourEvmAddress");
// Check status
var status = await bridge.GetPegInStatusAsync(pegIn);
Console.WriteLine($"Status: {status}");
// Serialize for sharing
var json = bridge.SerializePegInGraph(pegIn);# Run all tests
dotnet test PonziTech.BitVM.sln
# Run with coverage
dotnet test PonziTech.BitVM.sln --collect:"XPlat Code Coverage"Problem: Rust requires the Visual C++ linker which comes with Visual Studio Build Tools.
Solution:
# Install via winget
winget install Microsoft.VisualStudio.2022.BuildTools
# Or download from:
# https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022
# IMPORTANT: Select "Desktop development with C++" workload during installProblem: Rust is not in your PATH.
Solution:
# Restart your terminal after installing Rust
# Or manually add to PATH:
$env:PATH += ";$env:USERPROFILE\.cargo\bin"Problem: The BitVM submodule may not be initialized.
Solution:
# Initialize submodules
git submodule update --init --recursive
# Verify BitVM is present
ls external/BitVMProblem: The native DLL was not copied to the runtimes directory.
Solution:
# Build the FFI layer first
cd ffi
cargo build --release
cd ..
# Copy manually if needed
Copy-Item ffi\target\release\bitvm_ffi.dll runtimes\win-x64\native\Problem: The csbindgen-generated bindings haven't been created.
Solution:
# Build the FFI layer - this runs the build.rs script which generates bindings
cd ffi && cargo build
# Or use the build script
./build/build.ps1BitVM is experimental technology. This package is in early development. The API is subject to change and the underlying BitVM implementation is not yet production-ready.
- BitVM Whitepaper
- BitVM Repository
- API Reference (coming soon)
- Examples (coming soon)
Contributions are welcome! Please read our Contributing Guide for details.
MIT License - see LICENSE file for details.
- BitVM - The original BitVM implementation
- NBitcoin - Bitcoin library for .NET
- Arkworks - zkSNARK ecosystem
For questions and support:
- GitHub Issues: github.com/PonziTech/BitVM/issues
There is no meme, we love you. ❤️