Rederive: The Package Manager That Ships Behavioral Contracts Instead of Binaries
Hook
What if your package manager deleted the original source code during installation and rebuilt it from scratch using AI, then verified the rebuilt version passes tests the original never saw?
Context
The npm colors.js sabotage in January 2022 exposed a fundamental flaw in how we consume open-source packages: we trust maintainers not to ship malicious code. Faker.js and colors.js—used by millions of projects—suddenly started printing gibberish and infinite loops to protest corporations using unpaid labor. The incident raised an uncomfortable question: what's stopping a compromised maintainer account from doing something worse?
Current solutions don't solve the trust problem, they just move it around. Package signing (Sigstore, npm provenance) proves who shipped the bytes, but not whether those bytes are benign. Reproducible builds (Nix, Guix) verify bit-for-bit determinism, but still trust the source code itself. Dependency vendoring gives you a static snapshot, but you're still running whatever the maintainer wrote. Rederive takes a radically different approach: ship the behavioral contract (specification + verification tests), not the implementation. The package manager either verifies the shipped code passes held-out oracles it never trained on, or rebuilds the entire package from scratch using LLM synthesis and proves the regenerated code matches the contract.
Technical Insight
Rederive's core innovation is the held-out oracle—test vectors that act as cryptographic commitments to behavior. When you package code with Rederive, it generates test cases the original implementation never executes during development. These oracle vectors become execution-stamped expectations: if new code (whether shipped or LLM-generated) passes them, it's behavioral evidence of equivalence, not just hash matching.
The SIR (Structured Intermediate Representation) format is where this gets concrete. Instead of shipping JavaScript or Python, you ship kind-tagged function specifications with type signatures and oracle pointers. Here's what a SIR contract looks like for a simple color formatting utility:
{
"kind": "function",
"name": "red",
"signature": "(text: string) => string",
"spec": "Wraps input text with ANSI red color escape codes",
"oracles": [
{"input": ["hello"], "output": "\u001b[31mhello\u001b[39m"},
{"input": [""], "output": "\u001b[31m\u001b[39m"},
{"input": ["multi\nline"], "output": "\u001b[31mmulti\nline\u001b[39m"}
],
"content_hash": "sha256:a3f2b..."
}
The verification flow operates in two modes. The check operation is deterministic and free: it runs the held-out oracle test vectors against shipped source code and validates content hashes. This catches both semantic tampering (oracle misses) and any modification whatsoever (hash mismatch). It's explicitly designed to prevent the colors.js sabotage case—if a maintainer ships malicious code, the oracles fail because the new behavior diverges from the contract.
The resynth operation is where things get expensive and philosophically weird. Rederive deletes the original source code, sends the SIR spec to Claude Code subagents via Anthropic's Messages API, runs multiple workers in quorum, and rebuilds the implementation from scratch. The regenerated code must pass the same held-out oracles to be accepted. This means you're trusting behavioral equivalence verified by tests the LLM never saw, not trusting the publisher's binary blob.
The normalize mode (not yet shipped as a CLI command) addresses a harder problem: verifying refactored code reproduces original behavior on unseen inputs, including concurrent interleavings. It generates test scenarios using partial-order reduction to explore concurrent execution spaces, then verifies the refactored implementation passes them. Here's the conceptual flow:
# Original stateful code (serves as oracle)
def original_counter():
count = 0
def increment():
nonlocal count
temp = count
count = temp + 1
return increment
# Rederive generates concurrent scenarios with controlled scheduling
scenarios = generate_interleavings(
original_counter,
operations=["increment", "increment"],
threads=2
)
# Verifies refactored code matches across interleaving space
for schedule in scenarios:
original_result = replay(original_counter, schedule)
refactored_result = replay(refactored_counter, schedule)
assert original_result == refactored_result
The clever bit is virtual time injection for deterministic replay of timer-dependent code. Instead of hoping concurrent tests pass under random scheduling, Rederive controls the execution order and verifies behavior across the partial-order reduction space. This would be genuinely useful for refactoring stateful systems like database drivers or event loops—if it actually shipped.
The trust boundary here is explicitly the independent oracle, not the publisher's binary. Oracle tampering would require breaking execution-stamped behavioral expectations, which means shipping an oracle that passes a malicious implementation. But who generates the oracles? How do you prove they're comprehensive? The repository doesn't answer this, and it's the Achilles heel of the whole model. A malicious maintainer could ship garbage oracles that trivially pass garbage implementations, defeating the entire verification scheme.
Gotcha
The 'trust-nothing' framing collapses under scrutiny. Resynth fundamentally requires external LLM API access to Anthropic's Claude via the Messages API. You're not escaping trust—you're just shifting it from the package maintainer to Anthropic's infrastructure, your network connection, and your token budget. The determinism claim only holds for the check operation; actually rebuilding packages means trusting an opaque neural network and paying per-token for every transitive dependency.
This is a 2-star repository with a single example package (colors 1.4.0, a zero-dependency utility). There's no evidence it handles real dependency graphs, multi-language ecosystems, or native extensions. The normalize mode—the most interesting piece for concurrent verification—is explicitly marked as not shipping. Performance and token costs are unspecified, but basic math makes this infeasible: rebuilding a typical Node.js project's 500+ transitive dependencies via LLM synthesis would cost hundreds of dollars and take hours. The oracle generation problem is unsolved, making this vulnerable to malicious publishers who ship weak tests. For anything beyond toy examples, this is a research prototype, not a production package manager.
Verdict
Use if: You maintain a handful of critical zero-dependency utilities (cryptographic libraries, parsing tools, core runtime helpers) and want behavioral locks against maintainer compromise. The check operation provides real value as a trust boundary if oracles are independently audited. Also useful if you're researching LLM-based program synthesis with formal verification guardrails, or exploring behavioral contracts as an alternative to binary trust. Skip if: You need actual supply chain defense tooling for production systems today—the LLM dependency, token costs, and unsolved oracle generation problem make this impractical for real dependency trees. Use Sigstore for provenance, Nix for reproducible builds, or vendor your dependencies and audit changes. The normalize mode's concurrency verification would be killer for refactoring stateful code, but it doesn't exist as a usable feature yet.