Exemplo
zerocopy-derive 0.8.62
Amostra verificada para cargo zerocopy-derive 0.8.62. O contrato rodou em rust 1 · linux alpine/x64 · docker e passou: #[derive(FromBytes, Immutable…
sha256:eb1e63be8e47f878831a815344662980df9d96d6628057ac75bcb28f4e9564af
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
linux · alpine · musl x64 cargo
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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-10-16 |
Caso
HOW- Objetivo
- verify pkg:cargo/zerocopy-derive@0.8.62
- Pacotes
- Criado
- 2026-10-16T16:04:48Z
Contrato
- #[derive(FromBytes, Immutable, IntoBytes, KnownLayout)] round-trips C-repr structs to and from bytes
- #[derive(FromZeros)] initializes structs from all-zero bytes via new_zeroed
- #[derive(TryFromBytes, KnownLayout, Immutable, IntoBytes)] validates repr(u8) enum discriminants and rejects invalid bytes
- #[derive(ByteEq, ByteHash)] implements PartialEq, Eq, and Hash over raw struct bytes
- #[derive(Unaligned)] allows zero-copy reference casting from unaligned byte slices
- #[zerocopy(crate = "zerocopy")] supports transparent tuple structs with explicit crate path
Arquivos
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
Código-fonte
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
"proc-macro2",
]
[[package]]
name = "sample-zerocopy-derive"
version = "1.0.0"
dependencies = [
"zerocopy",
"zerocopy-derive",
]
[[package]]
name = "syn"
version = "2.0.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
[[package]]
name = "zerocopy"
version = "0.8.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86502bf56ac7c77571a32e2647bb2a15894565e981fb2a48d7bde2d91c965a9d"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5457206954b06561e2608c7e19cf58b1926586d999c246eebe4502f7e2039d1a"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[package]
name = "sample-zerocopy-derive"
version = "1.0.0"
edition = "2021"
publish = false
[dependencies]
zerocopy-derive = "=0.8.62"
zerocopy = "=0.8.62"
[[bin]]
name = "contract"
path = "test/contract.rs"
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 pkg:cargo/zerocopy-derive@0.8.62
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/zerocopy-derive@0.8.62
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:62658513c60787e6c8db53483edc0ea090e04725fe00ab7c947cd054d3dfeb0e","contract":["#[derive(FromBytes, Immutable, IntoBytes, KnownLayout)] round-trips C-repr structs to and from bytes","#[derive(FromZeros)] initializes structs from all-zero bytes via new_zeroed","#[derive(TryFromBytes, KnownLayout, Immutable, IntoBytes)] validates repr(u8) enum discriminants and rejects invalid bytes","#[derive(ByteEq, ByteHash)] implements PartialEq, Eq, and Hash over raw struct bytes","#[derive(Unaligned)] allows zero-copy reference casting from unaligned byte slices","#[zerocopy(crate = \"zerocopy\")] supports transparent tuple structs with explicit crate path"],"goal":"verify pkg:cargo/zerocopy-derive@0.8.62","kind":"HOW","packages":["pkg:cargo/zerocopy-derive@0.8.62"],"schemaVersion":1},"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/zerocopy-derive@0.8.62"],"schemaVersion":1,"subject":"pkg:cargo/zerocopy-derive@0.8.62","verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify pkg:cargo/zerocopy-derive@0.8.62",
"kind": "HOW",
"packages": [
"pkg:cargo/zerocopy-derive@0.8.62"
]
}
//! Clean-room verification sample for zerocopy-derive 0.8.62.
pub use zerocopy_derive::*;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use zerocopy::{FromBytes, FromZeros, IntoBytes, TryFromBytes};
use zerocopy_derive::{
ByteEq, ByteHash, FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout, TryFromBytes,
Unaligned,
};
#[derive(FromBytes, Immutable, IntoBytes, KnownLayout, Debug, PartialEq, Eq)]
#[repr(C)]
struct PacketHeader {
magic: u32,
length: u16,
flags: u16,
}
#[derive(FromZeros, Immutable, IntoBytes, KnownLayout, Debug, PartialEq, Eq)]
#[repr(C)]
struct CounterBlock {
reads: u64,
writes: u64,
}
#[derive(TryFromBytes, KnownLayout, Immutable, IntoBytes, Debug, PartialEq, Eq, Clone, Copy)]
#[repr(u8)]
#[allow(dead_code)]
enum FrameKind {
Data = 1,
Ack = 2,
Reset = 3,
}
#[derive(Immutable, IntoBytes, ByteEq, ByteHash, Debug)]
#[repr(C)]
struct EndpointKey {
net: u32,
port: u16,
reserved: u16,
}
#[derive(FromBytes, Immutable, IntoBytes, KnownLayout, Unaligned, Debug, PartialEq, Eq)]
#[repr(C)]
struct WireTag {
kind: u8,
payload: [u8; 3],
}
#[derive(FromBytes, Immutable, IntoBytes, KnownLayout, Debug, PartialEq, Eq)]
#[zerocopy(crate = "zerocopy")]
#[repr(transparent)]
struct SequenceNumber(u32);
fn hash_of<T: Hash>(value: &T) -> u64 {
let mut hasher = DefaultHasher::new();
value.hash(&mut hasher);
hasher.finish()
}
fn main() {
// 1. FromBytes, IntoBytes, Immutable, and KnownLayout round-trip C-repr structs
let header = PacketHeader {
magic: 0xABCD_1234,
length: 64,
flags: 0x0003,
};
let bytes = header.as_bytes();
assert_eq!(bytes.len(), 8);
let decoded = PacketHeader::read_from_bytes(bytes).expect("read PacketHeader");
assert_eq!(decoded, header);
// 2. FromZeros constructs zeroed instances safely
let counters = CounterBlock::new_zeroed();
assert_eq!(
counters,
CounterBlock {
reads: 0,
writes: 0,
}
);
// 3. TryFromBytes validates enum discriminants and rejects invalid byte patterns
let valid_frame = FrameKind::try_read_from_bytes(&[2u8]).expect("valid FrameKind");
assert_eq!(valid_frame, FrameKind::Ack);
assert!(
FrameKind::try_read_from_bytes(&[9u8]).is_err(),
"invalid discriminant must fail"
);
// 4. ByteEq and ByteHash implement byte-level equality and hashing
let key_a = EndpointKey {
net: 0x7F00_0001,
port: 8080,
reserved: 0,
};
let key_b = EndpointKey {
net: 0x7F00_0001,
port: 8080,
reserved: 0,
};
let key_c = EndpointKey {
net: 0x7F00_0001,
port: 9090,
reserved: 0,
};
assert_eq!(key_a, key_b);
assert_ne!(key_a, key_c);
assert_eq!(hash_of(&key_a), hash_of(&key_b));
assert_ne!(hash_of(&key_a), hash_of(&key_c));
// 5. Unaligned allows casting from arbitrary byte offsets with 1-byte alignment
let raw = [0xAA, 0x07, 0x10, 0x20, 0x30];
let tag = WireTag::ref_from_bytes(&raw[1..]).expect("unaligned WireTag ref");
assert_eq!(tag.kind, 0x07);
assert_eq!(tag.payload, [0x10, 0x20, 0x30]);
// 6. Custom #[zerocopy(crate = "...")] attribute works on transparent tuple structs
let seq = SequenceNumber(42);
let seq_roundtrip =
SequenceNumber::read_from_bytes(seq.as_bytes()).expect("read SequenceNumber");
assert_eq!(seq_roundtrip, seq);
}
Seeder de origem
anônimo