From 583d09a410bae5bfa0194f3fa387b2fb0a16639c Mon Sep 17 00:00:00 2001 From: saymrwulf Date: Mon, 6 Jul 2026 19:07:59 +0200 Subject: [PATCH] =?UTF-8?q?swe.html:=20add=20Part=20VI=C2=BD=20on=20the=20?= =?UTF-8?q?multi-party=20re-architecture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New section covers splitting the parties, the Rust transport-security layer (Ed25519/X25519 over cgo, no RSA), the validated wire boundary, and cast-as- intended return codes. Also corrects the error-handling slide (the netdemo mode does cross a real trust boundary) and notes the Rust dependency on the deps slide. Verified: deck serves 200 and the script balances. Co-Authored-By: Claude Fable 5 --- cmd/evote/web/swe.html | 80 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/cmd/evote/web/swe.html b/cmd/evote/web/swe.html index b65f5cd..a6a4a7c 100644 --- a/cmd/evote/web/swe.html +++ b/cmd/evote/web/swe.html @@ -357,8 +357,8 @@ const S = [ github.com/spf13/cobra v1.10.2 // CLI framework golang.org/x/crypto v0.47.0 // SHA3, Argon2id ) -

That's the entire dependency list. Everything else -- ElGamal encryption, zero-knowledge proofs, the Bayer-Groth shuffle argument, Pedersen commitments -- is implemented from scratch.

-
Minimize your dependencies. Every dependency is a liability: it can break, go unmaintained, introduce vulnerabilities, or change its API. For a cryptographic system, building from primitives also means you understand every line. You're not trusting a black box.

This doesn't mean "never use libraries." It means: use libraries for things that aren't your core domain (CLI parsing, hash algorithms), and own the code for things that are your core domain (the election protocol).
+

That's the entire Go dependency list. The protocol crypto -- ElGamal, zero-knowledge proofs, the Bayer-Groth shuffle, Pedersen commitments -- is implemented from scratch. The one deliberate exception is transport security: the multi-party mode links a small Rust crate (ed25519-dalek, x25519-dalek) for signatures and key exchange.

+
Own your core domain; borrow the rest. The election protocol is the core domain, so it's built from primitives -- you understand every line. But hand-rolling Ed25519 or X25519 would be reckless: constant-time, audited implementations are exactly what you should depend on. Knowing which is which is the skill.
` }, @@ -750,10 +750,10 @@ combined := CombinePublicKeys(pk0, pk1, pk2, pk3, pk4)Should this PoC have better error handling?

- No. And here's why.

- This code runs a single-threaded, in-memory election ceremony. There's no network, no disk I/O, no user input after the flags are parsed. If something goes wrong, it's because the math is wrong -- and the correct response is to crash with a stack trace, not to gracefully return an error that nobody knows how to handle.

- In production? Absolutely add proper error handling. There are network calls, database transactions, concurrent operations, and partial failures. But for a PoC, clarity wins over defensive programming. -
Match your error strategy to your context. A PoC, a library, a web server, and an embedded system all need different error handling approaches. Don't cargo-cult if err != nil { return err } on every line if you're writing throwaway code. And don't panic in a library that other people import. Context matters.
+ It depends which mode you're in.

+ The single-process demo runs an in-memory ceremony with no untrusted input after the flags are parsed. If something goes wrong there, it's because the math is wrong -- crashing with a stack trace is the right response.

+ But the multi-party netdemo (Part VI½) crosses a real trust boundary: parties exchange signed messages, and a malformed message from a peer must produce a clean rejection, not a panic. So the transport-facing code returns errors and validates every decoded value -- the same code, held to a stricter standard because its inputs are no longer trusted. +
Match your error strategy to your context. Panic on impossible internal states in throwaway code; return errors at trust boundaries where inputs are attacker-controlled. The same project can need both -- what changes is whether the input is trusted.
` }, @@ -850,6 +850,74 @@ combined := CombinePublicKeys(pk0, pk1, pk2, pk3, pk4) +
Part VI½
+

From One Process to Many Parties

+
The real system isn't one program.
It's ten mutually distrusting parties on separate machines.
+ + ` +}, + +{ + part: 'Part VI½: Going Multi-Party', + title: 'The Trust Structure Was Missing', + html: ` +

The single-process demo is faithful to the protocol but not to the trust model. Every party -- the setup component, four control components, the electoral board, the voting server, the voters, the verifier -- lived as fields on one shared struct. Anyone could read anyone's secret key.

+

The netdemo mode splits them into separate endpoints (pkg/party). Each holds only its own private state; everything that crosses between parties travels as an authenticated message over a bus (pkg/transport).

+
A protocol demo can collapse all parties into one process. A trust demo can't -- the whole point is that no single party sees the whole picture. Splitting them turns "trust us" into "verify every message."
+ ` +}, + +{ + part: 'Part VI½: Going Multi-Party', + title: 'Transport Security -- in Rust', + html: ` +

Every inter-party message is Ed25519-signed; confidential deliveries (voting cards) use X25519 ECDH + AES-GCM. Crucially, that cryptography is implemented in Rust, not Go, and called over a C ABI via cgo:

+
// rust/transportsec (ed25519-dalek, x25519-dalek) -> C ABI -> Go +// pkg/transportsec/transportsec.go +func Ed25519Sign(seed, msg []byte) ([]byte, error) // calls Rust +func X25519SharedSecret(priv, peerPub []byte) ([]byte, error)
+

No RSA anywhere -- including the X.509 certificate authority, whose Ed25519 signatures are produced through a Go crypto.Signer shim that forwards to Rust. A cross-language test proves the Rust signatures are standard RFC 8032 (Go's stdlib verifies them and vice-versa).

+
Language boundaries are an architecture tool. Isolating all the signature/key-exchange code in one small Rust crate with a five-function C ABI means the security-critical primitives live in one memory-safe, audited place -- and the Go side literally cannot re-implement or bypass them.
+ ` +}, + +{ + part: 'Part VI½: Going Multi-Party', + title: 'The Validation Boundary', + html: ` +

Once messages arrive from other parties, they're untrusted. The single serialization layer (pkg/party/wire.go) is the choke point: crypto objects travel as decimal strings and every decode routes through the checked constructors.

+
func strToGq(s string, group *emath.GqGroup) (emath.GqElement, error) { + v, ok := new(big.Int).SetString(s, 10) + if !ok { return ..., err } + return emath.NewGqElement(v, group) // validates membership in G_q +}
+

A peer cannot inject a value outside the group -- the small-subgroup and non-residue attacks are closed at the exact point where a proof or ciphertext crosses the boundary.

+
In a monolith, "is this a valid group element?" is an invariant you establish once. Across a trust boundary, it's a question you must re-ask on every single decode. The architecture makes that unavoidable by funneling all decoding through one validated layer.
+ ` +}, + +{ + part: 'Part VI½: Going Multi-Party', + title: 'Cast-as-Intended, For Real', + html: ` +

The return codes a voter checks against their card are now computed by the control components from the submitted ciphertext -- not looked up. The voter sends a second ciphertext E2 and a plaintext-equality proof that E2 and the ballot encrypt the same vote.

+
voter --> ballot E1 + E2 + equality proof --> server +server --> verify proof on every CC, then: + exponentiate E2 by each CC's return-code key, + joint-decrypt --> vote^Σk --> look up short code +voter <-- return code -- check against card
+

If malware encrypts option A for the tally but option B in the return-code channel, the equality proof fails and the ballot is rejected. A unit test drives exactly that attack and confirms it's caught.

+
Soundness is a property of the whole pipeline, not one function. The proof, the CC computation, the mapping lookup, and the voter's check only add up to "cast-as-intended" when every link holds -- which is why it needs a test that attacks the seam between them.
+ ` +}, + // ============================================================ // PART VII: THE CLI AS A PRODUCT // ============================================================