Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/vibe-native-pre-admission.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Vibe native pre-admission (no execution authority)
on:
pull_request:
paths:
- 'phios/vibe_native_admission.py'
- 'tests/test_vibe_native_admission.py'
- '.github/workflows/vibe-native-pre-admission.yml'
- 'docs/PHIOS_VIBE_NATIVE_PRE_ADMISSION.md'
push:
branches: [main]
paths:
- 'phios/vibe_native_admission.py'
- 'tests/test_vibe_native_admission.py'
- '.github/workflows/vibe-native-pre-admission.yml'
- 'docs/PHIOS_VIBE_NATIVE_PRE_ADMISSION.md'
permissions:
contents: read
jobs:
pinned-native-witness:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/checkout@v4
with:
repository: MichaelWave369/Vibe
ref: b5a0829b5eb13f342be4c8bfeb4d72213831c237
path: .interop/vibe
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install consumer and pinned producer
run: python -m pip install -e . -e .interop/vibe pytest
- name: Produce actual Vibe contract and independent verifier
run: |
test "$(git -C .interop/vibe rev-parse HEAD)" = "b5a0829b5eb13f342be4c8bfeb4d72213831c237"
witness="$RUNNER_TEMP/vibe-witness"
mkdir "$witness"
vibec native-contract .interop/vibe/vibe/examples/native_borrow_rust.vibe --out "$witness/contract.txt"
vibec cargo-export .interop/vibe/vibe/examples/native_borrow_rust.vibe --out "$witness/project"
cargo build --offline --locked --manifest-path .interop/vibe/native/verifier/Cargo.toml --target-dir "$witness/target"
cp "$witness/project/src/lib.rs" "$witness/artifact.rs"
cp "$witness/target/debug/vibe-native-verifier" "$witness/verifier"
"$witness/verifier" "$witness/contract.txt" "$witness/artifact.rs"
echo "PHIOS_VIBE_WITNESS_DIR=$witness" >> "$GITHUB_ENV"
- name: Require actual cross-repo permission witness and denial cases
run: |
test -n "$PHIOS_VIBE_WITNESS_DIR"
python -m pytest tests/test_vibe_native_admission.py -q
30 changes: 30 additions & 0 deletions docs/PHIOS_VIBE_NATIVE_PRE_ADMISSION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Operation Vibe Native R0.5a: PhiOS pre-admission

Producer baseline: MichaelWave369/Vibe at merged commit `b5a0829b5eb13f342be4c8bfeb4d72213831c237` (PR #93, R0.4).

PhiOS evaluates bounded identity artifact evidence using its existing Mandala
AuthorityContext. The trusted host must supply the policy, verifier location
and current authority context. The permission `evidence.vibe.native.review`
must be present in both the ceiling and explicit grants. Default is HOLD.
Policy must explicitly allow the exact contract SHA-256 and artifact SHA-256
pair, and pin the locally reviewed verifier executable bytes. Candidate input
cannot provide or expand host policy. The gate runs only those pinned verifier
bytes in a temporary directory with a timeout. It never runs the candidate.

The native checker validates artifact correspondence to a projection. Neither
hashes nor this receipt prove publisher identity or full Vibe semantics.
The producer commit identifies the reviewed contract baseline, not a runtime
attestation of the binary build. The host is responsible for independently
reviewing the binary and pair before configuring policy. No network-facing
authority broker, signatures, ledger append, persistent registry, executable
loading, kernel admission, or kernel permission grant are introduced.

CI checks out the exact merged Vibe producer, exports its real shared-borrow
contract and Cargo artifact, builds its actual native verifier offline, and
requires positive eligibility plus permission-denial and native-rejection
witnesses. Unit tests cover missing grants, missing ceiling, altered bytes,
unapproved pair, timeout, and non-authority receipts.

Next gate: bind reviewed evidence to authenticated provenance and current
authority epoch before any future execution request. PhiKernel remains
unchanged; no QEMU or native execution witness is claimed here.
151 changes: 151 additions & 0 deletions phios/vibe_native_admission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
"""Permission-bound Vibe native evidence pre-admission, never execution.

Policy, authority context and verifier location are supplied by the trusted
PhiOS host, not by the candidate. A successful decision is eligibility only.
"""
from __future__ import annotations

import hashlib
import os
import re
import subprocess
from dataclasses import dataclass
from pathlib import Path
from tempfile import TemporaryDirectory

from phios.covenant.models import canonical_sha256
from phios.mandala import AuthorityContext

VIBE_NATIVE_REVIEW_PERMISSION = "evidence.vibe.native.review"
VIBE_PRODUCER_COMMIT = "b5a0829b5eb13f342be4c8bfeb4d72213831c237"
MAX_ARTIFACT_BYTES = 64 * 1024
MAX_VERIFIER_BYTES = 32 * 1024 * 1024
_SHA256 = re.compile(r"[0-9a-f]{64}")
_PASS = b"PASS: canonical bounded identity artifact (projection only; no execution attestation)"


def _digest(data: bytes) -> str:
return hashlib.sha256(data).hexdigest()


def _valid_digest(value: str) -> bool:
return isinstance(value, str) and _SHA256.fullmatch(value) is not None


@dataclass(frozen=True, slots=True)
class VibeNativeReviewPolicy:
"""Host-reviewed verifier binary and exact contract/artifact pairs."""

verifier_sha256: str
approved_pairs: tuple[tuple[str, str], ...] = ()

def __post_init__(self) -> None:
if not _valid_digest(self.verifier_sha256):
raise ValueError("invalid verifier digest")
if len(self.approved_pairs) > 64:
raise ValueError("too many approved pairs")
if any(
len(pair) != 2 or not all(_valid_digest(value) for value in pair)
for pair in self.approved_pairs
):
raise ValueError("invalid approved pair")
if tuple(sorted(set(self.approved_pairs))) != self.approved_pairs:
raise ValueError("approved pairs must be sorted and unique")

@property
def sha256(self) -> str:
return canonical_sha256({
"schema": "phios.vibe_native_review_policy.v0.1",
"producer_contract_baseline": VIBE_PRODUCER_COMMIT,
"verifier_sha256": self.verifier_sha256,
"approved_pairs": [list(pair) for pair in self.approved_pairs],
})


def _read_verifier(path: Path) -> bytes:
if not path.is_file():
raise ValueError("verifier must be a regular file")
with path.open("rb") as stream:
data = stream.read(MAX_VERIFIER_BYTES + 1)
if not data or len(data) > MAX_VERIFIER_BYTES:
raise ValueError("invalid verifier size")
return data


def _check_native(verifier: bytes, contract: bytes, artifact: bytes) -> bool:
"""Run only host-pinned verifier bytes; candidate Rust is data, never executed."""
with TemporaryDirectory(prefix="phios-vibe-review-") as temp:
root = Path(temp)
binary = root / ("verifier.exe" if os.name == "nt" else "verifier")
binary.write_bytes(verifier)
binary.chmod(0o700)
wire = root / "contract.txt"
source = root / "artifact.rs"
wire.write_bytes(contract)
source.write_bytes(artifact)
result = subprocess.run(
[str(binary), str(wire), str(source)],
cwd=root,
stdin=subprocess.DEVNULL,
capture_output=True,
timeout=10,
check=False,
)
return result.returncode == 0 and result.stdout.strip() == _PASS


def evaluate_vibe_native(
contract: bytes,
artifact: bytes,
*,
policy: VibeNativeReviewPolicy,
authority: AuthorityContext,
verifier_path: Path,
) -> dict[str, object]:
"""Evaluate eligibility with current explicit permission and exact reviewed bytes.

No ledger append, loader, compilation, candidate execution or authority grant.
The receipt is deterministic evidence, not a signed token or reusable lease.
"""
if not isinstance(contract, bytes) or not isinstance(artifact, bytes):
raise TypeError("candidate inputs must be immutable bytes")
if not 0 < len(contract) <= MAX_ARTIFACT_BYTES or not 0 < len(artifact) <= MAX_ARTIFACT_BYTES:
raise ValueError("candidate outside bounded size")
pair = (_digest(contract), _digest(artifact))
reason = "PERMISSION_DENIED"
checked = False
if authority.allows(VIBE_NATIVE_REVIEW_PERMISSION):
reason = "PAIR_NOT_APPROVED"
if pair in policy.approved_pairs:
try:
verifier = _read_verifier(verifier_path)
reason = "VERIFIER_DIGEST_MISMATCH"
if _digest(verifier) == policy.verifier_sha256:
checked = True
reason = "NATIVE_REJECTED"
if _check_native(verifier, contract, artifact):
reason = "REVIEW_ELIGIBLE"
except (OSError, ValueError, subprocess.SubprocessError):
reason = "VERIFIER_UNAVAILABLE"
eligible = reason == "REVIEW_ELIGIBLE"
receipt: dict[str, object] = {
"schema": "phios.vibe_native_review_receipt.v0.1",
"producer_contract_baseline": VIBE_PRODUCER_COMMIT,
"contract_sha256": pair[0],
"artifact_sha256": pair[1],
"policy_sha256": policy.sha256,
"authority_context_sha256": canonical_sha256(authority.to_dict()),
"permission": VIBE_NATIVE_REVIEW_PERMISSION,
"decision": "ELIGIBLE" if eligible else "HOLD",
"reason": reason,
"native_check_attempted": checked,
"eligible_for_later_review": eligible,
"ledger_write_performed": False,
"candidate_executed": False,
"operational_authority": False,
"action_authority": False,
"execution_authority": False,
"kernel_admitted": False,
}
receipt["receipt_sha256"] = canonical_sha256(receipt)
return receipt
148 changes: 148 additions & 0 deletions tests/test_vibe_native_admission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
from __future__ import annotations

import hashlib
import os
import subprocess
from pathlib import Path

import pytest

from phios import vibe_native_admission as admission
from phios.covenant.models import canonical_sha256
from phios.mandala import AuthorityContext

PERMISSION = admission.VIBE_NATIVE_REVIEW_PERMISSION
CONTRACT = b"vibe-native-contract-v1\nfunction\tid\ngoal\tidentity\ninput\tx\tnumber\noutput\tx\tnumber\n"
ARTIFACT = (
b"// Generated by Vibe Native R0.1 (identity contract only).\n"
b"// Return inputs unchanged.\n#![forbid(unsafe_code)]\n"
b"pub fn id(x: f64) -> f64 {\n x\n}\n"
)


def _sha(value: bytes) -> str:
return hashlib.sha256(value).hexdigest()


def _policy(binary: bytes, contract: bytes = CONTRACT, artifact: bytes = ARTIFACT):
return admission.VibeNativeReviewPolicy(_sha(binary), ((_sha(contract), _sha(artifact)),))


def _authority():
return AuthorityContext(ceiling=(PERMISSION,), grants=(PERMISSION,))


@pytest.mark.parametrize("authority", [
AuthorityContext(),
AuthorityContext(ceiling=(PERMISSION,)),
AuthorityContext(grants=(PERMISSION,)),
AuthorityContext(ceiling=("other",), grants=("other",)),
])
def test_denied_permissions_never_read_or_run_verifier(monkeypatch, authority, tmp_path):
def forbidden(*args):
pytest.fail("permission denial must precede any verifier access")

monkeypatch.setattr(admission, "_read_verifier", forbidden)
monkeypatch.setattr(admission, "_check_native", forbidden)
result = admission.evaluate_vibe_native(
CONTRACT, ARTIFACT, policy=_policy(b"binary"),
authority=authority, verifier_path=tmp_path / "missing",
)
assert result["reason"] == "PERMISSION_DENIED"
assert result["decision"] == "HOLD"
assert result["native_check_attempted"] is False


def test_exact_pair_and_binary_digest_required(monkeypatch, tmp_path):
binary = tmp_path / "verifier"
binary.write_bytes(b"changed")

def forbidden(*args):
pytest.fail("unapproved pair or binary cannot be checked")

monkeypatch.setattr(admission, "_check_native", forbidden)
policy = _policy(b"reviewed")
for artifact, reason in [
(ARTIFACT + b"// change\n", "PAIR_NOT_APPROVED"),
(ARTIFACT, "VERIFIER_DIGEST_MISMATCH"),
]:
result = admission.evaluate_vibe_native(
CONTRACT, artifact, policy=policy, authority=_authority(), verifier_path=binary,
)
assert result["reason"] == reason
assert result["decision"] == "HOLD"


@pytest.mark.parametrize("outcome, reason", [
(True, "REVIEW_ELIGIBLE"),
(False, "NATIVE_REJECTED"),
(None, "VERIFIER_UNAVAILABLE"),
])
def test_decision_receipt_never_grants_authority(monkeypatch, tmp_path, outcome, reason):
binary = tmp_path / "verifier"
binary.write_bytes(b"reviewed")

def check(verifier, contract, artifact):
assert (verifier, contract, artifact) == (b"reviewed", CONTRACT, ARTIFACT)
if outcome is None:
raise subprocess.TimeoutExpired("verifier", 10)
return outcome

monkeypatch.setattr(admission, "_check_native", check)
result = admission.evaluate_vibe_native(
CONTRACT, ARTIFACT, policy=_policy(b"reviewed"),
authority=_authority(), verifier_path=binary,
)
assert result["reason"] == reason
assert result["eligible_for_later_review"] is (outcome is True)
assert result["native_check_attempted"] is True
for key in ("execution_authority", "operational_authority", "action_authority",
"candidate_executed", "kernel_admitted", "ledger_write_performed"):
assert result[key] is False
claimed = result.pop("receipt_sha256")
assert claimed == canonical_sha256(result)


def test_oversized_and_default_hold(tmp_path):
policy = admission.VibeNativeReviewPolicy(_sha(b"reviewed"))
with pytest.raises(ValueError, match="bounded size"):
admission.evaluate_vibe_native(
b"x" * 65537, ARTIFACT, policy=policy,
authority=_authority(), verifier_path=tmp_path / "missing",
)
result = admission.evaluate_vibe_native(
CONTRACT, ARTIFACT, policy=policy,
authority=_authority(), verifier_path=tmp_path / "missing",
)
assert result["reason"] == "PAIR_NOT_APPROVED"


def test_pinned_real_vibe_producer_and_verifier():
root = os.environ.get("PHIOS_VIBE_WITNESS_DIR")
if not root:
pytest.skip("real producer witness is required in the pinned interop workflow")
directory = Path(root)
binary = directory / "verifier"
data = binary.read_bytes()
contract = (directory / "contract.txt").read_bytes()
artifact = (directory / "artifact.rs").read_bytes()
policy = _policy(data, contract, artifact)
result = admission.evaluate_vibe_native(
contract, artifact, policy=policy, authority=_authority(), verifier_path=binary,
)
assert result["decision"] == "ELIGIBLE"
assert result["native_check_attempted"] is True
assert result["execution_authority"] is False
changed = artifact + b"// mutation\n"
# Even a locally approved but noncanonical artifact must fail native verification.
rejected = admission.evaluate_vibe_native(
contract, changed, policy=_policy(data, contract, changed),
authority=_authority(), verifier_path=binary,
)
assert rejected["reason"] == "NATIVE_REJECTED"
denied = admission.evaluate_vibe_native(
contract, artifact, policy=policy, authority=AuthorityContext(),
verifier_path=binary,
)
assert denied["reason"] == "PERMISSION_DENIED"
assert denied["native_check_attempted"] is False
Loading