CodeSampleX

Exemple

rand_chacha 0.9.0: rand_chacha::rand_core::RngCore

Échantillon vérifié pour cargo rand_chacha 0.9.0: rand_chacha::rand_core::RngCore. Le contrat s'est exécuté sur rust 1 · linux alpine/x64 · docker et a…

sha256:9f5dcb3cc2b65639944f9f894f46081b4be74344199bd95b61de909465aeb18c

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 · alpine · 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-10-10

Cas

HOW
Objectif
verify rand_chacha::rand_core::RngCore in pkg:cargo/rand_chacha@0.9.0
Paquets
Symboles
  • rand_chacha::rand_core::RngCore
Créé
2026-10-10T14:45:42Z

Contrat

  1. ChaCha20Rng, ChaCha12Rng, and ChaCha8Rng implement rand_chacha::rand_core::RngCore
  2. RngCore::next_u32 returns pseudo-random u32 values deterministically for a fixed seed
  3. RngCore::next_u64 returns pseudo-random u64 values deterministically for a fixed seed
  4. RngCore::fill_bytes fills byte slices of varying lengths including empty, partial-block, and multi-block sizes
  5. RngCore is implemented for &mut R allowing mutable references to act as RNG sources
  6. ChaCha20Rng automatically implements rand_chacha::rand_core::TryRngCore with Infallible error type

Fichiers

  • Cargo.lock
  • Cargo.toml
  • NOTES.md
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.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.190"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce5d3ddc6d3fa000eb1536d85e147bfe31aacaba692ed6a876f95cb7c855be78"

[[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-rand-chacha"
version = "1.0.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.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",
]
Cargo.toml
[package]
name = "sample-rand-chacha"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
rand_chacha = "=0.9.0"

[[bin]]
name = "contract"
path = "test/contract.rs"
NOTES.md
# rand_chacha 0.9.0 RngCore Contract Notes

## What `search_known_solution` answered
`search_known_solution` returned `NO_SAFE_MATCH` for verifying `rand_chacha::rand_core::RngCore` in `rand_chacha@0.9.0`.

## What a model would have written instead
A model might assume that `RngCore` still includes `try_fill_bytes` returning `Result<(), Error>` as in older `rand_core` versions (0.6.x used by `rand_chacha` 0.3.x). In `rand_core` 0.9.x re-exported by `rand_chacha` 0.9.0, `RngCore` only specifies `next_u32`, `next_u64`, and `fill_bytes`. Fallible operations are separated into the `TryRngCore` trait, which `RngCore` implementors automatically satisfy with `Infallible` error type.

## How the wrong version fails
Calling `try_fill_bytes` directly via `RngCore` fails compilation unless `TryRngCore` is brought into scope, and expecting a fallible error type causes a type mismatch against `core::convert::Infallible`.
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 rand_chacha::rand_core::RngCore in pkg:cargo/rand_chacha@0.9.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/rand_chacha@0.9.0
Demonstrate these symbols/APIs:
  - rand_chacha::rand_core::RngCore

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:11392f1369a42bd6f1e6ae02ba74491ead27fb2513e88058702f0fb0bd0db480","contract":["ChaCha20Rng, ChaCha12Rng, and ChaCha8Rng implement rand_chacha::rand_core::RngCore","RngCore::next_u32 returns pseudo-random u32 values deterministically for a fixed seed","RngCore::next_u64 returns pseudo-random u64 values deterministically for a fixed seed","RngCore::fill_bytes fills byte slices of varying lengths including empty, partial-block, and multi-block sizes","RngCore is implemented for \u0026mut R allowing mutable references to act as RNG sources","ChaCha20Rng automatically implements rand_chacha::rand_core::TryRngCore with Infallible error type"],"goal":"verify rand_chacha::rand_core::RngCore in pkg:cargo/rand_chacha@0.9.0","kind":"HOW","packages":["pkg:cargo/rand_chacha@0.9.0"],"schemaVersion":1,"symbols":["rand_chacha::rand_core::RngCore"]},"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/rand_chacha@0.9.0"],"schemaVersion":1,"subject":"pkg:cargo/rand_chacha@0.9.0","symbols":["rand_chacha::rand_core::RngCore"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify rand_chacha::rand_core::RngCore in pkg:cargo/rand_chacha@0.9.0",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/rand_chacha@0.9.0"
  ],
  "symbols": [
    "rand_chacha::rand_core::RngCore"
  ]
}
src/lib.rs
//! Clean-room verification sample for rand_chacha.

pub use rand_chacha::*;
test/contract.rs
use rand_chacha::rand_core::{RngCore, SeedableRng, TryRngCore};
use rand_chacha::{ChaCha8Rng, ChaCha12Rng, ChaCha20Rng};

fn main() {
    // 1. ChaCha20Rng, ChaCha12Rng, and ChaCha8Rng implement rand_chacha::rand_core::RngCore
    let seed = [0x42u8; 32];
    let mut rng20 = ChaCha20Rng::from_seed(seed);
    let mut rng12 = ChaCha12Rng::from_seed(seed);
    let mut rng8 = ChaCha8Rng::from_seed(seed);

    fn assert_rng_core<R: RngCore>(_rng: &mut R) {}
    assert_rng_core(&mut rng20);
    assert_rng_core(&mut rng12);
    assert_rng_core(&mut rng8);

    // 2. RngCore::next_u32 returns pseudo-random u32 values deterministically for a fixed seed
    let mut rng_a = ChaCha20Rng::from_seed(seed);
    let mut rng_b = ChaCha20Rng::from_seed(seed);
    let val_a1 = rng_a.next_u32();
    let val_a2 = rng_a.next_u32();
    let val_b1 = rng_b.next_u32();
    let val_b2 = rng_b.next_u32();
    assert_eq!(val_a1, val_b1);
    assert_eq!(val_a2, val_b2);
    assert_ne!(val_a1, val_a2);

    // 3. RngCore::next_u64 returns pseudo-random u64 values deterministically for a fixed seed
    let mut rng_u64_a = ChaCha20Rng::from_seed(seed);
    let mut rng_u64_b = ChaCha20Rng::from_seed(seed);
    let u64_a = rng_u64_a.next_u64();
    let u64_b = rng_u64_b.next_u64();
    assert_eq!(u64_a, u64_b);
    assert_ne!(u64_a, 0);

    // 4. RngCore::fill_bytes fills byte slices of varying lengths including empty, partial-block, and multi-block sizes
    let mut rng = ChaCha20Rng::from_seed(seed);
    let mut empty = [];
    rng.fill_bytes(&mut empty);

    let mut small_buf = [0u8; 16];
    rng.fill_bytes(&mut small_buf);
    assert!(small_buf.iter().any(|&b| b != 0));

    let mut large_buf = [0u8; 128]; // larger than 64-byte ChaCha block
    rng.fill_bytes(&mut large_buf);
    assert!(large_buf.iter().any(|&b| b != 0));

    // Deterministic stream match: same seed produces identical byte fills
    let mut rng_bytes_a = ChaCha20Rng::from_seed(seed);
    let mut rng_bytes_b = ChaCha20Rng::from_seed(seed);
    let mut buf_a = [0u8; 64];
    let mut buf_b = [0u8; 64];
    rng_bytes_a.fill_bytes(&mut buf_a);
    rng_bytes_b.fill_bytes(&mut buf_b);
    assert_eq!(buf_a, buf_b);

    // 5. RngCore is implemented for &mut R allowing mutable references to act as RNG sources
    let mut rng_ref = ChaCha20Rng::from_seed(seed);
    fn call_via_ref<R: RngCore>(rng: &mut R) {
        let _ = rng.next_u32();
        let _ = rng.next_u64();
    }
    call_via_ref(&mut &mut rng_ref);

    // 6. ChaCha20Rng automatically implements rand_chacha::rand_core::TryRngCore with Infallible error type
    let mut try_rng = ChaCha20Rng::from_seed(seed);
    let res_u32: Result<u32, core::convert::Infallible> = try_rng.try_next_u32();
    assert!(res_u32.is_ok());
    let res_u64: Result<u64, core::convert::Infallible> = try_rng.try_next_u64();
    assert!(res_u64.is_ok());
    let mut try_buf = [0u8; 32];
    let res_fill: Result<(), core::convert::Infallible> = try_rng.try_fill_bytes(&mut try_buf);
    assert!(res_fill.is_ok());

    println!("All rand_chacha::rand_core::RngCore contract assertions passed.");
}

Seeder d'origine

anonyme