Implementation:0sec labs 0 Patch Verify
| Knowledge Sources | |
|---|---|
| Domains | Binary_Analysis, Patching, Verification |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete tool for proposing and verifying binary patches that close confirmed PoVs without regressions, provided by the 0verse patch module.
Description
The run_patch_stage function iterates ONLY over findings with pov.reproduced == True and proposes fixes in three layers: B0 (deterministic located fix recommendation, zero-dependency), Mode A (LLM-generated source diff, rebuild, verify), and B1 (binary micro-patch for x86-64 ELF). A patch is verified ONLY when the confirmed PoV no longer reproduces against the patched artifact AND no regression is observed (oracle.verify_patch, the deterministic LLM-free adjudicator). Gated on ZEROVERSE_PATCH=1.
patch_enabled checks whether the patch stage is enabled via the environment variable.
Usage
Import these functions when you need to propose and verify patches for confirmed vulnerabilities. This is Stage 7 (optional) of the 0verse pipeline.
Code Reference
Source Location
- Repository: 0security
- File: 0verse/src/zeroverse/patch.py:L1-100+, 0verse/src/zeroverse/pipeline.py:L2050-2138
Signature
def run_patch_stage(
result, # RunResult with confirmed PoVs
path, # binary path
decompiled, # decompiled C dict
*,
llm: LLM, # provider-neutral LLM protocol
output_dir,
budget: BudgetTracker | None = None,
executor: Executor | None = None,
...
) -> int:
"""Iterate over confirmed PoVs; propose+verify patches; return attached count."""
def patch_enabled() -> bool:
"""Return True if ZEROVERSE_PATCH=1 is set in the environment."""
@dataclass
class Patch:
mode: str # "B0" | "A" | "B1"
verified: bool # True only when PoV no longer reproduces AND no regression
diff: str = "" # unified diff (Mode A) or recommendation (B0)
patched_artifact: str = ""
recommendation: str = ""
regression: bool = False
Import
from zeroverse.patch import run_patch_stage, patch_enabled
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| result | RunResult | Yes | Pipeline result with confirmed PoVs |
| path | str | Yes | Binary path |
| decompiled | dict[str,str] | Yes | Decompiled C code per function |
| llm | LLM | Yes | LLM for Mode A source diff generation |
| budget | BudgetTracker | No | Attempt budget |
Outputs
| Name | Type | Description |
|---|---|---|
| return | int | Number of patches attached to confirmed PoVs |
| PoV.patch | Patch | Patch dataclass attached to each confirmed PoV |
Usage Examples
Enabling the patch stage
import os
os.environ["ZEROVERSE_PATCH"] = "1"
from zeroverse.api import scan, ScanOptions
from zeroverse.patch import patch_enabled
assert patch_enabled(), "Patch stage requires ZEROVERSE_PATCH=1"
result = scan("./target", opts=ScanOptions(backend="ghidra"))
for f in result.findings:
if f.confirmed and f.patch_verified:
print(f"Verified patch: {f.patch_mode}")
print(f"Diff:\n{f.patch_diff}")