[Hackathon] brettleehari: fair-ordering a red-team of the coordination layer + the primitive that closes it#69
Open
brettleehari wants to merge 1 commit into
Conversation
…r-keyed integrity validators
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.
[Hackathon] brettleehari: fair-ordering — a red-team of the coordination layer + the primitive that closes it
Thesis
In an agent marketplace the sequencer sets the execution order of a batch — and whoever authors that order can extract value from it (front-running / MEV). Every coordination plugin in the tree assumes an honest sequencer:
contract_netandhotstuff(merged), plus the open consensus/auction PRs (sealed-bid #5, PBFT #45, NandaQuorum #44, ResonanceBFT #58). None addresses ordering fairness — they answer who agrees and who wins, never what if the orderer is the adversary?This PR doesn't add another "fair sequencer" (any single design breaks — I broke five). It ships a systematic red-team of the ordering design space and the one primitive that survives it, with an integrity oracle keyed on the engine's forge-proof
corr— never on anything the sequencer wrote.The red-team result (six witnesses, one theorem)
corrid)Theorem (empirically witnessed): whoever authors the order exploits it. Every sequencer-authored scheme leaks. The escape is the last row — author the order with something the sequencer cannot see or forge.
The survivor: engine-authored FIFO
Tier-1 stamps every broadcast with a monotonic, engine-assigned
corrid the sequencer cannot forge (the trace has noseqfield and alltsare0.0, socorris the only neutral order signal). Traders self-broadcast inon_start, so arrival order is authored bycorr, not the sequencer — confirmed on the real engine: a predatory sequencer emitting in reverse can reorder under polling but cannot under self-broadcast, which is why the scenario uses it. The integrity validator reconstructs arrival order from the submitcorrs and asserts the executed order matches.What's in the PR
coordination/fifo_fair.py—FifoFairCoordination(survivor: executes in arrival order) +PredatoryCoordination(matched attacker: reorders by descending price).scenarios_builtin/fair_ordering.py+scenarios/fair_ordering.yaml— 1 sequencer + 8 traders; traders self-broadcast, sequencer finalizes.corr-keyed validators —fair_ordering_integrity(executed order == engine arrival order) andfair_ordering_no_injection(every submit executed exactly once; no censorship, no phantoms).The discrimination (the teeth)
Same scenario, swap one line — this ranks three plausible sequencers, not just the absent default:
coordination:fair_ordering_integrityfair_ordering_no_injectionfifo_fairpredatorycontract_netorder:*)Robustness (I red-teamed my own validator)
The verdict rests on two keys, so both are validated as forge-resistant, not trusted:
corr(neutral order): missing / malformed / duplicatecorron a submit FAILS loudly — never silently bucketed — so a mangledcorrcan't collapse the order and slip a reorder past.pos(execution order): must be numeric, unique, and a clean0..n-1bijection; gaps / out-of-range / duplicates FAIL.posis the sequencer's claim, only ever checked against thecorr-derived truth.Guard tests:
test_integrity_fails_on_malformed_corr,test_integrity_fails_on_duplicate_pos,test_integrity_fails_on_non_bijection_pos.Scope, stated honestly
In zero-latency Tier-1, arrival order collapses to a fixed registration order, so this delivers unmanipulability (anti-MEV) — no party can alter the order — not egalitarian fairness. Real-latency first-come-first-served is the deployment reading; the fixed order is the Tier-1 model of it. Timestamp trust is engine-provided here; a real network needs trusted receipt timestamps — named, not assumed. The complete answer against a self-interested sequencer is an encrypted order flow (Shutter / Aequitas) — a privacy × coordination cross-layer step this PR points at but does not claim.
How to verify
Determinism: same seed → byte-identical trace (
test_determinism_byte_identical).make ci-localgreen: ruff check, ruff format --check, pyright (0 errors, strict), pytest (all pass).Persona:
market-microstructure / adversary engineer— leads with the threat model, ships the attacker beside the defender, and the validator's whole posture is "trust the engine's record, never the sequencer's narration."Appendix: reproduce the red-team (rows 1–4, offline)
Pure-Python, stdlib-only, deterministic (fixed seeds). Not committed per charter (no offline deps in the diff); available on request. Each reproduces one witness:
sha256calls, 100% of runs; with competing grinders the biggest CPU budget wins (a priority-gas-auction).beacon = sha256(sorted(all commit hashes)),position = sha256(H_i‖beacon). A public-commit last-mover, and a private-commit omniscient sequencer, each randomize their slot per attempt → ~N tries to land position 0.test_neutral_order_is_engine_authored_not_sequencerproves a predatory sequencer reorders arrival under polling but cannot under self-broadcast — the survivor, on the real engine.