CodeSampleX

サンプル

golang.org/x/sys v0.20.0

検証済みサンプル — golang golang.org/x/sys v0.20.0. go 1.26 · linux alpine/x64 · docker で contract を実行し、成功しました: unix.Eventfd creates a non-blocking event file…

sha256:41842de6b3e7ddf901da810c0c149dfa939fab614ea5830717b9a5f10bb5e51e

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

実行証拠

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

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
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-27

ケース

HOW
ゴール
verify pkg:golang/golang.org/x/sys@v0.20.0
パッケージ
作成日
2026-08-27T23:04:05Z

コントラクト

  1. unix.Eventfd creates a non-blocking event file descriptor that writes and reads 8-byte event counters
  2. unix.Sysinfo retrieves system uptime and total RAM statistics
  3. unix.Getrlimit queries the current and maximum open file descriptor resource limits
  4. unix.Getpagesize returns the system memory page size in bytes

ファイル

  • 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 pkg:golang/golang.org/x/sys@v0.20.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/sys@v0.20.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:7f35af7a33bef11bd14be1741ccf6428f4fe6b106e1f072f013dd7b45489a538","contract":["unix.Eventfd creates a non-blocking event file descriptor that writes and reads 8-byte event counters","unix.Sysinfo retrieves system uptime and total RAM statistics","unix.Getrlimit queries the current and maximum open file descriptor resource limits","unix.Getpagesize returns the system memory page size in bytes"],"goal":"verify pkg:golang/golang.org/x/sys@v0.20.0","kind":"HOW","packages":["pkg:golang/golang.org/x/sys@v0.20.0"],"schemaVersion":1},"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/golang.org/x/sys@v0.20.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/sys@v0.20.0","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require golang.org/x/sys v0.20.0
go.sum
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
main.go
package main

import (
	"encoding/binary"
	"fmt"
	"os"

	"golang.org/x/sys/unix"
)

// CreateAndUseEventfd demonstrates creating an eventfd descriptor and passing counter values.
func CreateAndUseEventfd() (uint64, error) {
	efd, err := unix.Eventfd(0, unix.EFD_CLOEXEC|unix.EFD_NONBLOCK)
	if err != nil {
		return 0, fmt.Errorf("eventfd failed: %w", err)
	}
	defer unix.Close(efd)

	var writeBuf [8]byte
	binary.LittleEndian.PutUint64(writeBuf[:], 42)
	n, err := unix.Write(efd, writeBuf[:])
	if err != nil || n != 8 {
		return 0, fmt.Errorf("write to eventfd failed: %w", err)
	}

	var readBuf [8]byte
	n, err = unix.Read(efd, readBuf[:])
	if err != nil || n != 8 {
		return 0, fmt.Errorf("read from eventfd failed: %w", err)
	}

	val := binary.LittleEndian.Uint64(readBuf[:])
	return val, nil
}

// GetSystemInfo retrieves uptime and RAM metrics using unix.Sysinfo.
func GetSystemInfo() (unix.Sysinfo_t, error) {
	var info unix.Sysinfo_t
	if err := unix.Sysinfo(&info); err != nil {
		return info, fmt.Errorf("sysinfo failed: %w", err)
	}
	return info, nil
}

// GetDescriptorLimits retrieves open file resource limits via unix.Getrlimit.
func GetDescriptorLimits() (unix.Rlimit, error) {
	var rlim unix.Rlimit
	if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlim); err != nil {
		return rlim, fmt.Errorf("getrlimit failed: %w", err)
	}
	return rlim, nil
}

// GetMemoryPageSize returns the system memory page size.
func GetMemoryPageSize() int {
	return unix.Getpagesize()
}

func main() {
	counter, err := CreateAndUseEventfd()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error with eventfd: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Eventfd counter: %d\n", counter)

	info, err := GetSystemInfo()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error with sysinfo: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("System uptime: %d seconds, Total RAM: %d bytes\n", info.Uptime, info.Totalram)

	rlim, err := GetDescriptorLimits()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error with getrlimit: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("File descriptor limits: cur=%d, max=%d\n", rlim.Cur, rlim.Max)

	pageSize := GetMemoryPageSize()
	fmt.Printf("Memory page size: %d bytes\n", pageSize)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/sys@v0.20.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/sys@v0.20.0"
  ]
}
test/contract.go
package main

import (
	"encoding/binary"
	"fmt"
	"os"

	"golang.org/x/sys/unix"
)

func main() {
	// Assertion 1: unix.Eventfd creates a non-blocking event file descriptor that writes and reads 8-byte event counters
	efd, err := unix.Eventfd(0, unix.EFD_CLOEXEC|unix.EFD_NONBLOCK)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Eventfd failed: %v\n", err)
		os.Exit(1)
	}
	defer unix.Close(efd)

	const expectedVal = uint64(100)
	var writeBuf [8]byte
	binary.LittleEndian.PutUint64(writeBuf[:], expectedVal)

	nw, err := unix.Write(efd, writeBuf[:])
	if err != nil || nw != 8 {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Write on eventfd failed: nw=%d, err=%v\n", nw, err)
		os.Exit(1)
	}

	var readBuf [8]byte
	nr, err := unix.Read(efd, readBuf[:])
	if err != nil || nr != 8 {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Read on eventfd failed: nr=%d, err=%v\n", nr, err)
		os.Exit(1)
	}

	val := binary.LittleEndian.Uint64(readBuf[:])
	if val != expectedVal {
		fmt.Fprintf(os.Stderr, "FAIL: eventfd value mismatch: got %d, expected %d\n", val, expectedVal)
		os.Exit(1)
	}

	// Assertion 2: unix.Sysinfo retrieves system uptime and total RAM statistics
	var info unix.Sysinfo_t
	if err := unix.Sysinfo(&info); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Sysinfo failed: %v\n", err)
		os.Exit(1)
	}
	if info.Uptime <= 0 {
		fmt.Fprintf(os.Stderr, "FAIL: invalid sysinfo uptime: %d\n", info.Uptime)
		os.Exit(1)
	}
	if info.Totalram <= 0 {
		fmt.Fprintf(os.Stderr, "FAIL: invalid sysinfo totalram: %d\n", info.Totalram)
		os.Exit(1)
	}

	// Assertion 3: unix.Getrlimit queries the current and maximum open file descriptor resource limits
	var rlim unix.Rlimit
	if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlim); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Getrlimit failed: %v\n", err)
		os.Exit(1)
	}
	if rlim.Cur == 0 || rlim.Max < rlim.Cur {
		fmt.Fprintf(os.Stderr, "FAIL: invalid rlimit values: cur=%d, max=%d\n", rlim.Cur, rlim.Max)
		os.Exit(1)
	}

	// Assertion 4: unix.Getpagesize returns the system memory page size in bytes
	pageSize := unix.Getpagesize()
	if pageSize <= 0 {
		fmt.Fprintf(os.Stderr, "FAIL: invalid page size: %d\n", pageSize)
		os.Exit(1)
	}

	fmt.Println("PASS: golang.org/x/sys contract passed")
}

オリジンシーダー

匿名