CodeSampleX

Exemple

rand_chacha 0.9.0: rand_chacha::ChaCha20Rng, rand_chacha::ChaCha12Rng, rand_chacha::ChaCha8Rng

Échantillon vérifié pour cargo rand_chacha 0.9.0: rand_chacha::ChaCha20Rng, rand_chacha::ChaCha12Rng, rand_chacha::ChaCha8Rng. Le contrat s'est exécuté sur…

sha256:2e36dc83459bfec693baadca3e50c302d74f107e6ab0b251a31aa6cbb9e5ed08

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux · musl x64 cargo

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-19

Cas

HOW
Objectif
verify pkg:cargo/rand_chacha@0.9.0
Paquets
Symboles
  • rand_chacha::ChaCha20Rng
  • rand_chacha::ChaCha12Rng
  • rand_chacha::ChaCha8Rng
  • rand_chacha::ChaChaRng
Créé
2026-09-19T02:57:54Z

Contrat

  1. assert ChaCha20Rng::from_seed produces deterministic output matching ChaCha20 reference vector
  2. assert ChaCha20Rng::set_stream and set_word_pos control stream and offset positions
  3. assert ChaCha20Rng::fill_bytes populates destination slice via RngCore
  4. assert ChaCha12Rng and ChaCha8Rng construct from u64 seed and generate random u64 values
  5. assert ChaChaRng is an alias of ChaCha20Rng with identical behavior

Fichiers

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/main.rs

Télécharger l’artefact source (tar.gz)

Code source

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

[[package]]
name = "cfg-if"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"

[[package]]
name = "getrandom"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
dependencies = [
 "cfg-if",
 "libc",
 "r-efi",
 "wasip2",
]

[[package]]
name = "libc"
version = "0.2.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"

[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
 "zerocopy",
]

[[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 = "r-efi"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"

[[package]]
name = "rand_chacha"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
 "ppv-lite86",
 "rand_core",
]

[[package]]
name = "rand_core"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"
dependencies = [
 "getrandom",
]

[[package]]
name = "sample"
version = "0.1.0"
dependencies = [
 "rand_chacha",
]

[[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.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"

[[package]]
name = "wasip2"
version = "1.0.4+wasi-0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487"
dependencies = [
 "wit-bindgen",
]

[[package]]
name = "wit-bindgen"
version = "0.57.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"

[[package]]
name = "zerocopy"
version = "0.8.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d35102a9f36d089ccae9e4c6802bc118be4487b80aaffc0ab4e0cf5ce92d2873"
dependencies = [
 "zerocopy-derive",
]

[[package]]
name = "zerocopy-derive"
version = "0.8.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "146c01f5ab44258da43cf276c74a2763db2ff3969c9c652c3f2de07041d0b2bc"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
]
Cargo.toml
[package]
name = "sample"
version = "0.1.0"
edition = "2021"

[dependencies]
rand_chacha = "=0.9.0"
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 pkg:cargo/rand_chacha@0.9.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/rand_chacha@0.9.0

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:536b4af1d64ff8696095c91b93d779599fb1fe75f0ba66a9c5ecd59aa5ee7c12","contract":["assert ChaCha20Rng::from_seed produces deterministic output matching ChaCha20 reference vector","assert ChaCha20Rng::set_stream and set_word_pos control stream and offset positions","assert ChaCha20Rng::fill_bytes populates destination slice via RngCore","assert ChaCha12Rng and ChaCha8Rng construct from u64 seed and generate random u64 values","assert ChaChaRng is an alias of ChaCha20Rng with identical behavior"],"goal":"verify pkg:cargo/rand_chacha@0.9.0","kind":"HOW","packages":["pkg:cargo/rand_chacha@0.9.0"],"schemaVersion":1,"symbols":["rand_chacha::ChaCha20Rng","rand_chacha::ChaCha12Rng","rand_chacha::ChaCha8Rng","rand_chacha::ChaChaRng"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/rand_chacha@0.9.0"],"schemaVersion":1,"subject":"pkg:cargo/rand_chacha@0.9.0","symbols":["rand_chacha::ChaCha20Rng","rand_chacha::ChaCha12Rng","rand_chacha::ChaCha8Rng","rand_chacha::ChaChaRng"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/rand_chacha@0.9.0",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/rand_chacha@0.9.0"
  ],
  "symbols": [
    "rand_chacha::ChaCha20Rng",
    "rand_chacha::ChaCha12Rng",
    "rand_chacha::ChaCha8Rng",
    "rand_chacha::ChaChaRng"
  ]
}
src/main.rs
use rand_chacha::rand_core::{RngCore, SeedableRng};
use rand_chacha::{ChaCha12Rng, ChaCha20Rng, ChaCha8Rng, ChaChaRng};

fn main() {
    // 1. Deterministic generation with ChaCha20Rng from a 32-byte seed
    let seed = [0u8; 32];
    let mut rng20 = ChaCha20Rng::from_seed(seed);
    assert_eq!(rng20.get_seed(), seed);
    let val1 = rng20.next_u32();
    assert_eq!(val1, 0xade0b876, "ChaCha20 first word must match reference vector");

    // 2. Stream and word position control
    rng20.set_stream(100);
    assert_eq!(rng20.get_stream(), 100);
    rng20.set_word_pos(32);
    assert_eq!(rng20.get_word_pos(), 32);

    // 3. Buffer filling via RngCore::fill_bytes
    let mut buf = [0u8; 16];
    rng20.fill_bytes(&mut buf);
    assert_ne!(buf, [0u8; 16], "fill_bytes should populate non-zero random bytes");

    // 4. ChaCha12Rng and ChaCha8Rng seeding and u64 generation
    let mut rng12 = ChaCha12Rng::seed_from_u64(999);
    let val12 = rng12.next_u64();
    assert_ne!(val12, 0);

    let mut rng8 = ChaCha8Rng::seed_from_u64(999);
    let val8 = rng8.next_u64();
    assert_ne!(val8, 0);

    // 5. Verify ChaChaRng type alias equivalence to ChaCha20Rng
    let mut alias_rng: ChaChaRng = ChaChaRng::from_seed(seed);
    assert_eq!(alias_rng.next_u32(), 0xade0b876);

    println!("All contract assertions passed successfully.");
}

Seeder d'origine

anonyme