Ejemplo
zerovec 0.11.6: zerovec::ule::OptionULE
Muestra verificada para cargo zerovec 0.11.6: zerovec::ule::OptionULE. El contrato se ejecutó en rust 1 · linux alpine/x64 · docker y pasó.
sha256:4c0ee350ab49abf65e41983ca43c2d5edd16624f12f9691002939d4652c6a6be
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
rust linux x64 rust rust 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::OptionULE in pkg:cargo/zerovec@0.11.6
- Paquetes
- Símbolos
-
- zerovec::ule::OptionULE
- Entorno
- rust
- Creado
- 2026-09-21T13:22:53Z
Contrato
- assert OptionULE::new and OptionULE::get correctly wrap and unwrap unaligned ULE elements
- assert Option<T> converts to and from OptionULE<T::ULE> via AsULE trait
- assert ZeroVec<Option<T>> borrows slices of OptionULE and indexes items accurately
- assert OptionULE::validate_bytes validates boolean flags and rejects invalid bit patterns or non-zeroed None bytes
- assert ZeroVec::<Option<T>>::parse_bytes reconstructs optional zero-copy vectors from raw byte buffers
Archivos
- .gitignore
- Cargo.lock
- Cargo.toml
- NOTES.md
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- tests/contract.rs
Código fuente
/target
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "verify-zerovec-option-ule"
version = "0.1.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",
]
[package]
name = "verify-zerovec-option-ule"
version = "0.1.0"
edition = "2021"
[dependencies]
zerovec = "=0.11.6"
# CodeSampleX Notes: zerovec OptionULE zero-copy optional representation
## Search Result
`search_known_solution` returned **MISS** (`NO_SAFE_MATCH`) for `zerovec::ule::OptionULE` in `pkg:cargo/zerovec@0.11.6`.
## What a Model Would Have Written Instead
A naive model might assume `Option<T>` can be stored in a `ZeroVec` using standard Rust layout or assume `OptionULE` behaves like `Option<T>` directly without understanding that `OptionULE` is an unaligned byte-level representation requiring unaligned little-endian (ULE) inner types and explicit discriminant validation. Furthermore, a model might try to use missing methods like `ZeroVec::alloc_from_slice` instead of `ZeroVec::new_borrowed` or `ZeroVec::parse_bytes`.
## How the Contract Verifies the Goal
- Validates direct construction and retrieval via `OptionULE::new` and `OptionULE::get`.
- Validates the `AsULE` trait conversion between native `Option<T>` and `OptionULE<T::ULE>`.
- Validates zero-copy borrowing in `ZeroVec<Option<T>>` via `ZeroVec::new_borrowed`.
- Validates raw byte serialization and deserialization via `ULE::validate_bytes` and `ZeroVec::parse_bytes`, ensuring corrupt discriminants (non 0/1) or invalid payload bytes are safely rejected.
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::OptionULE 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::OptionULE
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.
{"case":{"caseId":"case:sha256:9a413d82a39ead7c39d4ca539cd27e75e9bd70d4103721f23f4a8a01aed8aedf","contract":["assert OptionULE::new and OptionULE::get correctly wrap and unwrap unaligned ULE elements","assert Option\u003cT\u003e converts to and from OptionULE\u003cT::ULE\u003e via AsULE trait","assert ZeroVec\u003cOption\u003cT\u003e\u003e borrows slices of OptionULE and indexes items accurately","assert OptionULE::validate_bytes validates boolean flags and rejects invalid bit patterns or non-zeroed None bytes","assert ZeroVec::\u003cOption\u003cT\u003e\u003e::parse_bytes reconstructs optional zero-copy vectors from raw byte buffers"],"goal":"verify zerovec::ule::OptionULE in pkg:cargo/zerovec@0.11.6","kind":"HOW","packages":["pkg:cargo/zerovec@0.11.6"],"schemaVersion":1,"symbols":["zerovec::ule::OptionULE"]},"contractCommand":["cargo","test","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","executionContext":"rust","language":"rust","os":"linux","packageManager":"cargo","runtime":"rust","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/zerovec@0.11.6"],"schemaVersion":1,"subject":"pkg:cargo/zerovec@0.11.6","symbols":["zerovec::ule::OptionULE"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify zerovec::ule::OptionULE in pkg:cargo/zerovec@0.11.6",
"kind": "HOW",
"packages": [
"pkg:cargo/zerovec@0.11.6"
],
"symbols": [
"zerovec::ule::OptionULE"
]
}
//! Verification sample for `zerovec::ule::OptionULE` in `zerovec@0.11.6`.
use zerovec::ule::{AsULE, OptionULE, ULE, UleError};
use zerovec::ZeroVec;
/// Wraps an optional value into an `OptionULE` representation.
pub fn wrap_option_ule<T: AsULE>(val: Option<T>) -> OptionULE<T::ULE> {
val.to_unaligned()
}
/// Unwraps an `OptionULE` back into native `Option<T>`.
pub fn unwrap_option_ule<T: AsULE>(ule: OptionULE<T::ULE>) -> Option<T> {
<Option<T> as AsULE>::from_unaligned(ule)
}
/// Validates raw byte slice as a sequence of `OptionULE<U>`.
pub fn validate_option_ule_bytes<U: ULE>(bytes: &[u8]) -> Result<(), UleError> {
<OptionULE<U> as ULE>::validate_bytes(bytes)
}
/// Borrows a slice of `OptionULE<T::ULE>` as a `ZeroVec<Option<T>>`.
pub fn create_zerovec_options<'a, T: AsULE>(
slice: &'a [OptionULE<T::ULE>],
) -> ZeroVec<'a, Option<T>> {
ZeroVec::new_borrowed(slice)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_wrap_unwrap() {
let opt = Some(42u32);
let ule = wrap_option_ule(opt);
assert_eq!(unwrap_option_ule(ule), opt);
let none_opt: Option<u32> = None;
let none_ule = wrap_option_ule(none_opt);
assert_eq!(unwrap_option_ule(none_ule), none_opt);
}
}
use zerovec::ule::{AsULE, CharULE, OptionULE, ULE};
use zerovec::ZeroVec;
#[test]
fn test_option_ule_direct_construction() {
let some_val = 42u32.to_unaligned();
let opt_some = OptionULE::new(Some(some_val));
assert_eq!(opt_some.get(), Some(some_val));
assert_eq!(u32::from_unaligned(opt_some.get().unwrap()), 42);
let opt_none = OptionULE::<<u32 as AsULE>::ULE>::new(None);
assert_eq!(opt_none.get(), None);
}
#[test]
fn test_option_ule_as_ule_roundtrip() {
let orig_some: Option<u32> = Some(9999);
let orig_none: Option<u32> = None;
let ule_some: OptionULE<<u32 as AsULE>::ULE> = orig_some.to_unaligned();
let ule_none: OptionULE<<u32 as AsULE>::ULE> = orig_none.to_unaligned();
assert_eq!(<Option<u32> as AsULE>::from_unaligned(ule_some), orig_some);
assert_eq!(<Option<u32> as AsULE>::from_unaligned(ule_none), orig_none);
}
#[test]
fn test_zerovec_option_ule_storage() {
let orig_some: Option<u32> = Some(9999);
let orig_none: Option<u32> = None;
let ule_slice = [
orig_some.to_unaligned(),
orig_none.to_unaligned(),
OptionULE::new(Some(123u32.to_unaligned())),
];
let zv: ZeroVec<Option<u32>> = ZeroVec::new_borrowed(&ule_slice);
assert_eq!(zv.len(), 3);
assert_eq!(zv.get(0), Some(Some(9999)));
assert_eq!(zv.get(1), Some(None));
assert_eq!(zv.get(2), Some(Some(123)));
assert_eq!(zv.get(3), None);
}
#[test]
fn test_option_ule_byte_validation() {
let valid_some_bytes = [1u8, 1, 0, 0, 0];
assert!(<OptionULE<<u32 as AsULE>::ULE> as ULE>::validate_bytes(&valid_some_bytes).is_ok());
let valid_none_bytes = [0u8, 0, 0, 0, 0];
assert!(<OptionULE<<u32 as AsULE>::ULE> as ULE>::validate_bytes(&valid_none_bytes).is_ok());
let invalid_bool_bytes = [2u8, 0, 0, 0, 0];
assert!(<OptionULE<<u32 as AsULE>::ULE> as ULE>::validate_bytes(&invalid_bool_bytes).is_err());
let invalid_none_bytes = [0u8, 1, 0, 0, 0];
assert!(<OptionULE<<u32 as AsULE>::ULE> as ULE>::validate_bytes(&invalid_none_bytes).is_err());
let invalid_char_bytes = [1u8, 0x00, 0xD8, 0x00];
assert!(<OptionULE<CharULE> as ULE>::validate_bytes(&invalid_char_bytes).is_err());
}
#[test]
fn test_zerovec_option_parse_bytes() {
let raw_bytes: Vec<u8> = [
1u8, 10, 0, 0, 0,
0u8, 0, 0, 0, 0,
1u8, 20, 0, 0, 0,
].to_vec();
let parsed_zv = ZeroVec::<Option<u32>>::parse_bytes(&raw_bytes).expect("parse_bytes should succeed");
assert_eq!(parsed_zv.get(0), Some(Some(10)));
assert_eq!(parsed_zv.get(1), Some(None));
assert_eq!(parsed_zv.get(2), Some(Some(20)));
}
Seeder de origen
anónimo