CodeSampleX

サンプル

rand_core 0.9.5

検証済みサンプル — cargo rand_core 0.9.5. rust 1 · linux alpine/x64 · docker で contract を実行し、成功しました: RngCore next_u32 and next_u64 produce expected sequential values

sha256:ab17eb7f08d5f435996186ca0224cb02dfefdc63b9e4973c8fa63a29663f3f4c

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux · alpine · musl x64 cargo

検証実行環境

環境 コントラクト ステージ 実行日
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

ケース

HOW
ゴール
verify pkg:cargo/rand_core@0.9.5
パッケージ
作成日
2026-09-19T02:51:54Z

コントラクト

  1. RngCore next_u32 and next_u64 produce expected sequential values
  2. RngCore fill_bytes populates buffer using helper
  3. SeedableRng seed_from_u64 initializes deterministic generator
  4. TryRngCore blanket implementation for RngCore provides infallible try_fill_bytes
  5. UnwrapMut wraps TryRngCore and reborrows correctly

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

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

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

[[package]]
name = "sample-rand-core"
version = "1.0.0"
dependencies = [
 "rand_core",
]
Cargo.toml
[package]
name = "sample-rand-core"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
rand_core = "=0.9.5"

[[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 pkg:cargo/rand_core@0.9.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/rand_core@0.9.5

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:f6e294e43dc44e91501dbaa5f58f38a4c7f622c963b8924cf20166bdb1175ed9","contract":["RngCore next_u32 and next_u64 produce expected sequential values","RngCore fill_bytes populates buffer using helper","SeedableRng seed_from_u64 initializes deterministic generator","TryRngCore blanket implementation for RngCore provides infallible try_fill_bytes","UnwrapMut wraps TryRngCore and reborrows correctly"],"goal":"verify pkg:cargo/rand_core@0.9.5","kind":"HOW","packages":["pkg:cargo/rand_core@0.9.5"],"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/rand_core@0.9.5"],"schemaVersion":1,"subject":"pkg:cargo/rand_core@0.9.5","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/rand_core@0.9.5",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/rand_core@0.9.5"
  ]
}
src/lib.rs
//! Clean-room verification sample for rand_core.

pub use rand_core::*;
test/contract.rs
use rand_core::{RngCore, SeedableRng, TryRngCore, impls, le};

struct StepRng(u64);

impl RngCore for StepRng {
    fn next_u32(&mut self) -> u32 {
        self.next_u64() as u32
    }

    fn next_u64(&mut self) -> u64 {
        let val = self.0;
        self.0 = self.0.wrapping_add(1);
        val
    }

    fn fill_bytes(&mut self, dst: &mut [u8]) {
        impls::fill_bytes_via_next(self, dst);
    }
}

struct SeedableNum(u64);

impl RngCore for SeedableNum {
    fn next_u32(&mut self) -> u32 {
        self.next_u64() as u32
    }
    fn next_u64(&mut self) -> u64 {
        let val = self.0;
        self.0 = self.0.wrapping_add(1);
        val
    }
    fn fill_bytes(&mut self, dst: &mut [u8]) {
        impls::fill_bytes_via_next(self, dst);
    }
}

impl SeedableRng for SeedableNum {
    type Seed = [u8; 8];

    fn from_seed(seed: Self::Seed) -> Self {
        let mut x = [0u64; 1];
        le::read_u64_into(&seed, &mut x);
        SeedableNum(x[0])
    }
}

fn main() {
    // 1. RngCore next_u32 and next_u64 produce expected sequential values
    let mut rng = StepRng(100);
    assert_eq!(rng.next_u64(), 100);
    assert_eq!(rng.next_u64(), 101);
    assert_eq!(rng.next_u32(), 102);

    // 2. RngCore fill_bytes populates buffer using helper
    let mut buf = [0u8; 8];
    let mut rng2 = StepRng(1);
    rng2.fill_bytes(&mut buf);
    assert_eq!(buf, [1, 0, 0, 0, 0, 0, 0, 0]);

    // 3. SeedableRng seed_from_u64 initializes deterministic generator
    let mut seeded = SeedableNum::seed_from_u64(42);
    let val1 = seeded.next_u64();
    let mut seeded2 = SeedableNum::seed_from_u64(42);
    let val2 = seeded2.next_u64();
    assert_eq!(val1, val2);

    // 4. TryRngCore blanket implementation for RngCore provides infallible try_fill_bytes
    let mut try_buf = [0u8; 4];
    let mut rng3 = StepRng(5);
    assert!(rng3.try_fill_bytes(&mut try_buf).is_ok());

    // 5. UnwrapMut wraps TryRngCore and reborrows correctly
    let mut rng4 = StepRng(10);
    let mut unwrapped = rng4.unwrap_mut();
    assert_eq!(unwrapped.next_u64(), 10);
    let mut reborrowed = unwrapped.re();
    assert_eq!(reborrowed.next_u64(), 11);

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

オリジンシーダー

匿名