CodeSampleX

サンプル

github.com/klauspost/compress v1.19.1: Estimate

検証済みサンプル — golang github.com/klauspost/compress v1.19.1: Estimate. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました.

sha256:b15d52df8bd4f2364e523380d90c0e80bbe83f130a9f694f2ad355e323874c1c

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

実行証拠

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

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

検証実行環境

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

ケース

HOW
ゴール
verify github.com/klauspost/compress.Estimate in pkg:golang/github.com/klauspost/compress@v1.19.1
パッケージ
シンボル
  • github.com/klauspost/compress.Estimate
作成日
2026-10-11T11:22:49Z

コントラクト

  1. compress.Estimate returns 0 for inputs shorter than 16 bytes
  2. compress.Estimate returns score above 0.1 for repetitive text patterns
  3. compress.Estimate returns score above 0.5 for highly compressible data like zeroes or repeated bytes
  4. compress.Estimate returns score below 0.1 for high-entropy pseudo-random bytes
  5. compress.Estimate ranks compressible data higher than high-entropy data

ファイル

  • PROMPT.md
  • csx.json
  • estimate.go
  • go.mod
  • go.sum
  • 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 github.com/klauspost/compress.Estimate in pkg:golang/github.com/klauspost/compress@v1.19.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/klauspost/compress@v1.19.1
Demonstrate these symbols/APIs:
  - github.com/klauspost/compress.Estimate

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:30df9107f7a9e8d75dbadf62128ef6650f28ad9646191614d00ba1526d6e38e8","contract":["compress.Estimate returns 0 for inputs shorter than 16 bytes","compress.Estimate returns score above 0.1 for repetitive text patterns","compress.Estimate returns score above 0.5 for highly compressible data like zeroes or repeated bytes","compress.Estimate returns score below 0.1 for high-entropy pseudo-random bytes","compress.Estimate ranks compressible data higher than high-entropy data"],"goal":"verify github.com/klauspost/compress.Estimate in pkg:golang/github.com/klauspost/compress@v1.19.1","kind":"HOW","packages":["pkg:golang/github.com/klauspost/compress@v1.19.1"],"schemaVersion":1,"symbols":["github.com/klauspost/compress.Estimate"]},"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/klauspost/compress@v1.19.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/klauspost/compress@v1.19.1","symbols":["github.com/klauspost/compress.Estimate"],"verifierAdapter":"golang@1"}
estimate.go
package sample

import (
	"github.com/klauspost/compress"
)

// Estimate returns a normalized compressibility estimate of block b using compress.Estimate.
// Values close to zero are likely uncompressible.
// Values above 0.1 are likely to be compressible.
// Values above 0.5 are very compressible.
// Very small lengths (< 16) return 0.
func Estimate(b []byte) float64 {
	return compress.Estimate(b)
}

// IsCompressible reports whether the given data is estimated to be compressible (score >= 0.1).
func IsCompressible(b []byte) bool {
	return compress.Estimate(b) >= 0.1
}

// IsHighlyCompressible reports whether the given data is estimated to be highly compressible (score >= 0.5).
func IsHighlyCompressible(b []byte) bool {
	return compress.Estimate(b) >= 0.5
}
go.mod
module sample

go 1.26.6

require github.com/klauspost/compress v1.19.1
go.sum
github.com/klauspost/compress v1.19.1 h1:VsB4HPswih7mmZ8WleSFQ75c/Ui1M4trX5oAsJnhSlk=
github.com/klauspost/compress v1.19.1/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/klauspost/compress.Estimate in pkg:golang/github.com/klauspost/compress@v1.19.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/klauspost/compress@v1.19.1"
  ],
  "symbols": [
    "github.com/klauspost/compress.Estimate"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/klauspost/compress"
	"sample"
)

func main() {
	// Assertion 1: compress.Estimate returns 0 for inputs shorter than 16 bytes
	shortInputs := [][]byte{
		nil,
		{},
		[]byte("short"),
		[]byte("123456789012345"), // 15 bytes
	}
	for _, input := range shortInputs {
		score := compress.Estimate(input)
		if score != 0 {
			fmt.Fprintf(os.Stderr, "FAIL: expected 0 for input length %d, got %f\n", len(input), score)
			os.Exit(1)
		}
	}

	// Assertion 2: compress.Estimate returns score above 0.1 for repetitive text patterns
	repetitiveText := bytes.Repeat([]byte("repeating-pattern-"), 50)
	scoreRepetitive := sample.Estimate(repetitiveText)
	if scoreRepetitive <= 0.1 {
		fmt.Fprintf(os.Stderr, "FAIL: expected repetitive score > 0.1, got %f\n", scoreRepetitive)
		os.Exit(1)
	}
	if !sample.IsCompressible(repetitiveText) {
		fmt.Fprintf(os.Stderr, "FAIL: expected IsCompressible true for repetitive text\n")
		os.Exit(1)
	}

	// Assertion 3: compress.Estimate returns score above 0.5 for highly compressible data like zeroes or repeated bytes
	zeroes := make([]byte, 500)
	scoreZeroes := sample.Estimate(zeroes)
	if scoreZeroes <= 0.5 {
		fmt.Fprintf(os.Stderr, "FAIL: expected zeroes score > 0.5, got %f\n", scoreZeroes)
		os.Exit(1)
	}
	if !sample.IsHighlyCompressible(zeroes) {
		fmt.Fprintf(os.Stderr, "FAIL: expected IsHighlyCompressible true for zeroes\n")
		os.Exit(1)
	}

	homogeneous := bytes.Repeat([]byte{'X'}, 256)
	scoreHomogeneous := sample.Estimate(homogeneous)
	if scoreHomogeneous <= 0.8 {
		fmt.Fprintf(os.Stderr, "FAIL: expected homogeneous score > 0.8, got %f\n", scoreHomogeneous)
		os.Exit(1)
	}

	// Assertion 4: compress.Estimate returns score below 0.1 for high-entropy pseudo-random bytes
	randomData := make([]byte, 512)
	var state uint32 = 123456789
	for i := range randomData {
		state = state*1664525 + 1013904223
		randomData[i] = byte(state >> 24)
	}
	scoreRandom := sample.Estimate(randomData)
	if scoreRandom >= 0.1 {
		fmt.Fprintf(os.Stderr, "FAIL: expected high-entropy score < 0.1, got %f\n", scoreRandom)
		os.Exit(1)
	}
	if sample.IsCompressible(randomData) {
		fmt.Fprintf(os.Stderr, "FAIL: expected IsCompressible false for high-entropy data, got score %f\n", scoreRandom)
		os.Exit(1)
	}

	// Assertion 5: compress.Estimate ranks compressible data higher than high-entropy data
	if scoreRepetitive <= scoreRandom {
		fmt.Fprintf(os.Stderr, "FAIL: expected repetitive score (%f) > random score (%f)\n", scoreRepetitive, scoreRandom)
		os.Exit(1)
	}
	if scoreZeroes <= scoreRandom {
		fmt.Fprintf(os.Stderr, "FAIL: expected zeroes score (%f) > random score (%f)\n", scoreZeroes, scoreRandom)
		os.Exit(1)
	}

	fmt.Println("PASS: verify github.com/klauspost/compress.Estimate contract passed")
}

オリジンシーダー

匿名