> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stoffelmpc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How Backend Selection Works

> How Stoffel carries MPC backend selection through config, bytecode, the VM, local runs, and SDK network/client configuration.

Use this page after choosing a backend to see how that choice flows through `Stoffel.toml`, CLI flags, Rust SDK builders, bytecode metadata, local execution, and network/client configuration. If you need the app-level input, execution, and output flow, use [MPC Integration](../architecture/mpc). For backend selection guidance, start with [MPC Backends](./overview).

Stoffel records the selected MPC backend in the compiled program and carries it through the CLI, Rust SDK, VM, and network/client layers.

## End-to-end path

<img src="https://mintcdn.com/stoffellabs/WsJVEVCX73RSUEma/images/diagrams/honeybadger-network.svg?fit=max&auto=format&n=WsJVEVCX73RSUEma&q=85&s=d4a185c53589422d5e091b18a5da7967" alt="HoneyBadger MPC runtime diagram showing client input/output paths, coordinator-managed sessions, preprocessing material, and peer protocol rounds between VM parties." width="1200" height="675" data-path="images/diagrams/honeybadger-network.svg" />

<img src="https://mintcdn.com/stoffellabs/WsJVEVCX73RSUEma/images/campaign/stoffel-networked-privacy-backend.png?fit=max&auto=format&n=WsJVEVCX73RSUEma&q=85&s=ce93340ce44de6b4039ac1c8a2a8bac4" alt="Campaign-style networked privacy backend diagram showing client input and output paths, coordinator routing, preprocessing, and peer protocol messages." width="1800" height="1125" data-path="images/campaign/stoffel-networked-privacy-backend.png" />

At runtime, clients submit protected inputs, the coordinator manages session lifecycle and IO routing, and the parties execute the VM while exchanging HoneyBadger protocol messages.

The important invariant is that the compiled bytecode and the runtime agree on:

* backend: HoneyBadgerMPC or AVSS;
* curve/field where applicable;
* parties and threshold;
* client input/output schemas;
* preprocessing demand for operations such as multiplication and randomness.

## Backend selectors

At the SDK level, backend selection is represented as:

```rust theme={null}
MpcBackend::HoneyBadger
MpcBackend::Avss { curve: Curve::Bls12_381 /* or another Curve */ }
```

At the CLI/config level, the accepted string selectors are:

```text theme={null}
honeybadger
avss
avss:bls12_381
avss:bn254
avss:curve25519
avss:ed25519
avss:secp256k1
avss:p-256
```

`--field` / `curve = "..."` sets the AVSS curve. HoneyBadgerMPC does not take a curve selector in the SDK config; it uses the field configuration expected by the HoneyBadger path.

## Current config validation

Stoffel validates local and network MPC topology with:

```text theme={null}
parties >= 4 * threshold + 1
parties >= 5
threshold > 0
```

This is the rule developers should use for project config, local runs, and network config. It is stricter than the baseline `3t + 1` threshold often used to introduce asynchronous Byzantine protocols because Stoffel's current end-to-end path includes preprocessing and robust execution requirements.

SDK summaries also expose the minimum reconstruction shares:

| Backend        | Reported reconstruction threshold |
| -------------- | --------------------------------- |
| HoneyBadgerMPC | `2 * threshold + 1`               |
| AVSS           | `threshold + 1`                   |

## Bytecode manifest

The `.stflb` manifest stores backend metadata so a runtime can reject mismatched execution settings early.

```text theme={null}
CompiledBinary
└── ClientIoManifest
    ├── mpc_backend: HoneyBadger | Avss
    ├── mpc_curve: Bls12_381 | Bn254 | Curve25519 | Ed25519 | Secp256k1 | Secp256r1
    ├── clients: input/output share schemas
    └── preprocessing_demand
```

StoffelLang compilation writes this metadata from compiler options. The CLI and SDK set those options from project config or builder overrides.

## Local MPC execution

`stoffel run`, `stoffel dev`, and SDK `.execute_local().await?` run the compiled program against a local MPC test network on the developer machine.

The local runner receives:

* the compiled program;
* entrypoint name;
* backend kind;
* curve config;
* parties and threshold;
* ClientStore inputs and expected output-client metadata.

This lets the same source program be checked against HoneyBadgerMPC or AVSS by changing backend configuration instead of changing application code.

## Network and off-chain client execution

The Rust SDK can generate network deployment configs and build client/server handles. Backend selection is part of those configs:

```rust theme={null}
# use stoffel::prelude::*;
# fn example() -> stoffel::Result<()> {
let deployment = NetworkDeployment::builder([
    "127.0.0.1:19200",
    "127.0.0.1:19201",
    "127.0.0.1:19202",
    "127.0.0.1:19203",
    "127.0.0.1:19204",
])
.expected_clients(1)
.threshold(1)
.backend(MpcBackend::HoneyBadger)
.preprocessing(1000, 500)
.build()?;
# Ok(())
# }
```

AVSS can be selected in the same builder:

```rust theme={null}
# use stoffel::prelude::*;
# fn example() -> stoffel::Result<()> {
let deployment = NetworkDeployment::builder([
    "127.0.0.1:19200",
    "127.0.0.1:19201",
    "127.0.0.1:19202",
    "127.0.0.1:19203",
    "127.0.0.1:19204",
])
.expected_clients(1)
.threshold(1)
.backend(MpcBackend::Avss { curve: Curve::Bls12_381 })
.preprocessing(1000, 500)
.build()?;
# Ok(())
# }
```

The current SDK off-chain client I/O path supports HoneyBadgerMPC and AVSS over `bls12_381`. Other AVSS curves are still selectable for bytecode/runtime paths and curve-aware StoffelLang protocol examples; validate the specific client/network path you plan to use.

## VM boundary

The VM does not expose different application syntax for each backend. Secret-register operations and builtins yield backend-specific work through the MPC runtime:

| VM operation                        | Backend effect                                                       |
| ----------------------------------- | -------------------------------------------------------------------- |
| clear-to-secret input               | Creates backend share data.                                          |
| secret multiplication               | Uses backend multiplication/preprocessing path.                      |
| opening/reveal                      | Reconstructs according to backend share type.                        |
| `Share.random` / `Share.random_int` | Produces backend random share data.                                  |
| `Share.get_commitment`              | Returns commitment bytes when the backend share carries commitments. |
| `Avss.*` helpers                    | Inspect AVSS share metadata and commitments.                         |

This separation lets developers write StoffelLang around `secret T`, `Share`, `ClientStore`, `Mpc`, and `MpcOutput` while selecting the backend in config.

## Backend-specific notes

### HoneyBadgerMPC

HoneyBadgerMPC share data is field-oriented and supports the general arithmetic path. Its local/network execution path uses robust field-share reconstruction and preprocessing for multiplication-heavy workloads.

### AVSS

AVSS share data can carry Feldman commitment material. StoffelLang exposes `AvssShare` helpers and `Share.get_commitment(...)` when the output boundary needs public commitments, curve-encoded values, or scalar responses. Curve selection matters because scalar-field and group encodings must match the external verifier or protocol boundary.

## Troubleshooting

| Symptom                                  | Check                                                                                                                              |
| ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| Config says the threshold is invalid     | Confirm `parties >= 4 * threshold + 1` and `parties >= 5`.                                                                         |
| HoneyBadger rejects a curve selector     | Use `backend = "honeybadger"` without a curve, or switch to AVSS for curve workflows.                                              |
| AVSS client I/O fails on a non-BLS curve | The current SDK off-chain client I/O path supports AVSS over `bls12_381`; test other curves through supported local/runtime paths. |
| Runtime backend mismatch                 | Rebuild `.stflb` after changing `[mpc]` config or pass matching SDK/CLI backend overrides.                                         |
| Multiplication exhausts preprocessing    | Increase preprocessing in network config or reduce secret multiplications.                                                         |

## See also

* [MPC Protocols](./overview)
* [HoneyBadgerMPC](./honeybadger-mpc)
* [AVSS](./avss)
* [Stoffel VM builtins](../stoffel-vm/builtins)
* [Rust SDK API](../rust-sdk/api)
