CodeSampleX

Ejemplo

zerovec 0.11.6: zerovec::ule::ULE

Muestra verificada para cargo zerovec 0.11.6: zerovec::ule::ULE. El contrato se ejecutó en rust 1 · linux alpine/x64 · docker y pasó.

sha256:32e36cd5bef16ab378d2657eb938bcd913437c9dd530c0160d3b086bf3c35e67

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux · alpine · musl x64 cargo

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-09-21

Caso

HOW
Objetivo
verify zerovec::ule::ULE in pkg:cargo/zerovec@0.11.6
Paquetes
Símbolos
  • zerovec::ule::ULE
Creado
2026-09-21T08:51:27Z

Contrato

  1. ULE::validate_bytes validates aligned byte lengths and bit validity for unaligned little-endian types
  2. ULE::parse_bytes_to_slice parses valid byte buffers into typed ULE slices and rejects ill-formed inputs
  3. ULE::slice_as_bytes converts typed ULE slices back into raw byte slices matching original data
  4. ULE::slice_from_bytes_unchecked allows unsafe zero-copy casting from validated byte buffers
  5. Custom types implement ULE to enforce byte alignment and domain validation invariants

Archivos

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.rs

Descargar el artefacto de código fuente (tar.gz)

Código fuente

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "sample-zerovec"
version = "1.0.0"
dependencies = [
 "zerovec",
]

[[package]]
name = "zerofrom"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272"

[[package]]
name = "zerovec"
version = "0.11.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239"
dependencies = [
 "zerofrom",
]
Cargo.toml
[package]
name = "sample-zerovec"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
zerovec = "=0.11.6"

[[bin]]
name = "contract"
path = "test/contract.rs"
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify zerovec::ule::ULE in pkg:cargo/zerovec@0.11.6
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/zerovec@0.11.6
Demonstrate these symbols/APIs:
  - zerovec::ule::ULE

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:d2be67e7796003454ff9efb7dbcf7558f1c448b5a37fc487924a821cb31395df","contract":["ULE::validate_bytes validates aligned byte lengths and bit validity for unaligned little-endian types","ULE::parse_bytes_to_slice parses valid byte buffers into typed ULE slices and rejects ill-formed inputs","ULE::slice_as_bytes converts typed ULE slices back into raw byte slices matching original data","ULE::slice_from_bytes_unchecked allows unsafe zero-copy casting from validated byte buffers","Custom types implement ULE to enforce byte alignment and domain validation invariants"],"goal":"verify zerovec::ule::ULE in pkg:cargo/zerovec@0.11.6","kind":"HOW","packages":["pkg:cargo/zerovec@0.11.6"],"schemaVersion":1,"symbols":["zerovec::ule::ULE"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/zerovec@0.11.6"],"schemaVersion":1,"subject":"pkg:cargo/zerovec@0.11.6","symbols":["zerovec::ule::ULE"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify zerovec::ule::ULE in pkg:cargo/zerovec@0.11.6",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/zerovec@0.11.6"
  ],
  "symbols": [
    "zerovec::ule::ULE"
  ]
}
src/lib.rs
//! Clean-room verification sample for zerovec::ule::ULE.

pub use zerovec::ule::ULE;
test/contract.rs
use core::mem::size_of;
use zerovec::ule::{CharULE, RawBytesULE, UleError, ULE};

#[repr(C, packed)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
struct AsciiPairULE {
    first: u8,
    second: u8,
}

unsafe impl ULE for AsciiPairULE {
    fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> {
        if bytes.len() % size_of::<Self>() != 0 {
            return Err(UleError::length::<Self>(bytes.len()));
        }
        for byte in bytes {
            if !byte.is_ascii() {
                return Err(UleError::parse::<Self>());
            }
        }
        Ok(())
    }
}

fn main() {
    // 1. ULE::validate_bytes validates aligned byte lengths and bit validity for unaligned little-endian types
    assert_eq!(size_of::<RawBytesULE<4>>(), 4);
    assert!(RawBytesULE::<4>::validate_bytes(&[1, 2, 3, 4]).is_ok());
    assert!(matches!(
        RawBytesULE::<4>::validate_bytes(&[1, 2, 3]),
        Err(UleError::InvalidLength { len: 3, .. })
    ));
    assert!(CharULE::validate_bytes(&[0x61, 0x00, 0x00]).is_ok());
    assert!(CharULE::validate_bytes(&[0xFF, 0xFF, 0xFF]).is_err());
    assert!(CharULE::validate_bytes(&[0x61, 0x00]).is_err());

    // 2. ULE::parse_bytes_to_slice parses valid byte buffers into typed ULE slices and rejects ill-formed inputs
    let raw_buf = [1u8, 2, 3, 4, 5, 6, 7, 8];
    let raw_slice = RawBytesULE::<4>::parse_bytes_to_slice(&raw_buf).expect("parse RawBytesULE");
    assert_eq!(raw_slice.len(), 2);
    assert_eq!(raw_slice[0], RawBytesULE([1, 2, 3, 4]));
    assert_eq!(raw_slice[1], RawBytesULE([5, 6, 7, 8]));

    let char_buf = [0x61, 0x00, 0x00, 0x62, 0x00, 0x00];
    let char_slice = CharULE::parse_bytes_to_slice(&char_buf).expect("parse CharULE");
    assert_eq!(char_slice.len(), 2);
    assert_eq!(char_slice[0].to_char(), 'a');
    assert_eq!(char_slice[1].to_char(), 'b');

    // 3. ULE::slice_as_bytes converts typed ULE slices back into raw byte slices matching original data
    assert_eq!(RawBytesULE::<4>::slice_as_bytes(raw_slice), &raw_buf);
    assert_eq!(CharULE::slice_as_bytes(char_slice), &char_buf);

    // 4. ULE::slice_from_bytes_unchecked allows unsafe zero-copy casting from validated byte buffers
    let valid_bytes = [0x41u8, 0x00, 0x00];
    assert!(CharULE::validate_bytes(&valid_bytes).is_ok());
    let unchecked_slice = unsafe { CharULE::slice_from_bytes_unchecked(&valid_bytes) };
    assert_eq!(unchecked_slice.len(), 1);
    assert_eq!(unchecked_slice[0].to_char(), 'A');

    // 5. Custom types implement ULE to enforce byte alignment and domain validation invariants
    let valid_ascii = [b'A', b'B', b'C', b'D'];
    assert!(AsciiPairULE::validate_bytes(&valid_ascii).is_ok());
    let pairs = AsciiPairULE::parse_bytes_to_slice(&valid_ascii).expect("valid ascii pairs");
    assert_eq!(pairs.len(), 2);
    assert_eq!(pairs[0], AsciiPairULE { first: b'A', second: b'B' });
    assert_eq!(pairs[1], AsciiPairULE { first: b'C', second: b'D' });
    assert_eq!(AsciiPairULE::slice_as_bytes(pairs), &valid_ascii);

    let invalid_len = [b'A', b'B', b'C'];
    assert!(AsciiPairULE::validate_bytes(&invalid_len).is_err());

    let invalid_ascii = [b'A', 0xFF];
    assert!(AsciiPairULE::validate_bytes(&invalid_ascii).is_err());

    println!("All zerovec::ule::ULE contract assertions passed successfully.");
}

Seeder de origen

anónimo