CodeSampleX

サンプル

github.com/cespare/xxhash/v2 v2.1.1: Sum64String

検証済みサンプル — golang github.com/cespare/xxhash/v2 v2.1.1: Sum64String. go 1.26 · linux alpine/x64 · docker で contract を実行し、成功しました.

sha256:c2fd8fc07474fb7456abf494eb824830fd8ec05d66bfade9c0fd230c9620acc7

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

実行証拠

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

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

検証実行環境

環境 コントラクト ステージ 実行日
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-26
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-07

ケース

HOW
ゴール
verify Sum64String in pkg:golang/github.com/cespare/xxhash/v2@v2.1.1
パッケージ
シンボル
  • Sum64String
作成日
2026-08-26T01:16:18Z

コントラクト

  1. xxhash.Sum64String computes the 64-bit xxHash checksum of a string matching xxhash.Sum64 of the equivalent byte slice
  2. xxhash.Sum64String produces deterministic non-zero checksum for non-empty string and distinct hashes for distinct string inputs
  3. xxhash.Sum64String correctly computes the hash of an empty string

ファイル

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

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

ソース

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 Sum64String in pkg:golang/github.com/cespare/xxhash/v2@v2.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/cespare/xxhash/v2@v2.1.1
Demonstrate these symbols/APIs:
  - Sum64String

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:0bd935df081559214d3814e4fa32c77a5f85b9cc33309f8862dcfbd6cb829cb0","contract":["xxhash.Sum64String computes the 64-bit xxHash checksum of a string matching xxhash.Sum64 of the equivalent byte slice","xxhash.Sum64String produces deterministic non-zero checksum for non-empty string and distinct hashes for distinct string inputs","xxhash.Sum64String correctly computes the hash of an empty string"],"goal":"verify Sum64String in pkg:golang/github.com/cespare/xxhash/v2@v2.1.1","kind":"HOW","packages":["pkg:golang/github.com/cespare/xxhash/v2@v2.1.1"],"schemaVersion":1,"symbols":["Sum64String"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/cespare/xxhash/v2@v2.1.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/cespare/xxhash/v2@v2.1.1","symbols":["Sum64String"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require github.com/cespare/xxhash/v2 v2.1.1
go.sum
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
main.go
package main

import (
	"fmt"

	"github.com/cespare/xxhash/v2"
)

func main() {
	input := "hello world"
	hashString := xxhash.Sum64String(input)
	hashBytes := xxhash.Sum64([]byte(input))

	fmt.Printf("xxhash.Sum64String(%q) = %016x\n", input, hashString)
	fmt.Printf("xxhash.Sum64([]byte(%q)) = %016x\n", input, hashBytes)
	fmt.Printf("Equal: %t\n", hashString == hashBytes)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify Sum64String in pkg:golang/github.com/cespare/xxhash/v2@v2.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/cespare/xxhash/v2@v2.1.1"
  ],
  "symbols": [
    "Sum64String"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"github.com/cespare/xxhash/v2"
)

func main() {
	// Assertion 1: xxhash.Sum64String computes the 64-bit xxHash checksum of a string matching xxhash.Sum64 of the equivalent byte slice
	testStrings := []string{
		"",
		"a",
		"hello world",
		"The quick brown fox jumps over the lazy dog",
		"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
	}

	for _, s := range testStrings {
		hStr := xxhash.Sum64String(s)
		hBytes := xxhash.Sum64([]byte(s))
		if hStr != hBytes {
			fmt.Fprintf(os.Stderr, "FAIL: Sum64String(%q) = %d != Sum64([]byte) = %d\n", s, hStr, hBytes)
			os.Exit(1)
		}
	}

	// Assertion 2: xxhash.Sum64String produces deterministic non-zero checksum for non-empty string and distinct hashes for distinct string inputs
	h1 := xxhash.Sum64String("test-input-1")
	h1Repeat := xxhash.Sum64String("test-input-1")
	h2 := xxhash.Sum64String("test-input-2")

	if h1 == 0 {
		fmt.Fprintf(os.Stderr, "FAIL: Sum64String produced unexpected zero hash for non-empty string\n")
		os.Exit(1)
	}
	if h1 != h1Repeat {
		fmt.Fprintf(os.Stderr, "FAIL: Sum64String is not deterministic: %d != %d\n", h1, h1Repeat)
		os.Exit(1)
	}
	if h1 == h2 {
		fmt.Fprintf(os.Stderr, "FAIL: Sum64String collision for distinct inputs %d == %d\n", h1, h2)
		os.Exit(1)
	}

	// Assertion 3: xxhash.Sum64String correctly computes the hash of an empty string
	hEmpty := xxhash.Sum64String("")
	hEmptyBytes := xxhash.Sum64([]byte{})
	if hEmpty != hEmptyBytes {
		fmt.Fprintf(os.Stderr, "FAIL: Sum64String(\"\") = %d != Sum64([]byte{}) = %d\n", hEmpty, hEmptyBytes)
		os.Exit(1)
	}
	if hEmpty != 17241709254077376921 {
		fmt.Fprintf(os.Stderr, "FAIL: Sum64String(\"\") expected 17241709254077376921, got %d\n", hEmpty)
		os.Exit(1)
	}
}

オリジンシーダー

匿名