CodeSampleX

サンプル

golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1

検証済みサンプル — golang golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました.

sha256:ecd8f4d70eff2115c6a432f76cec4a6cb084cd0a5e5fc25f5b7d6a2e03bd27dc

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。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-09-15

ケース

HOW
ゴール
verify pkg:golang/golang.org/x/sys@v0.0.0-20210615035016-665e8c7367d1
パッケージ
作成日
2026-09-15T16:24:19Z

コントラクト

  1. unix.Getpid returns a positive integer process ID matching os.Getpid
  2. unix.Getppid returns a positive integer parent process ID matching os.Getppid
  3. unix.Getpagesize returns a positive system page size that is a power of two matching os.Getpagesize
  4. unix.ByteSliceToString converts a null-terminated byte slice into a Go string
  5. unix.BytePtrToString converts a null-terminated byte pointer into a Go string
  6. unix.Uname populates a Utsname structure with non-empty sysname and nodename

ファイル

  • 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.0.0-20210615035016-665e8c7367d1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/sys@v0.0.0-20210615035016-665e8c7367d1

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:20cb7c5715095c4fc4b1fca360b6d6ed94be2f7f8165aef68f20fbd63da453e7","contract":["unix.Getpid returns a positive integer process ID matching os.Getpid","unix.Getppid returns a positive integer parent process ID matching os.Getppid","unix.Getpagesize returns a positive system page size that is a power of two matching os.Getpagesize","unix.ByteSliceToString converts a null-terminated byte slice into a Go string","unix.BytePtrToString converts a null-terminated byte pointer into a Go string","unix.Uname populates a Utsname structure with non-empty sysname and nodename"],"goal":"verify pkg:golang/golang.org/x/sys@v0.0.0-20210615035016-665e8c7367d1","kind":"HOW","packages":["pkg:golang/golang.org/x/sys@v0.0.0-20210615035016-665e8c7367d1"],"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.0.0-20210615035016-665e8c7367d1"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/sys@v0.0.0-20210615035016-665e8c7367d1","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1
go.sum
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
main.go
package main

import (
	"fmt"
	"os"

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

func main() {
	pid := unix.Getpid()
	ppid := unix.Getppid()
	pageSize := unix.Getpagesize()

	fmt.Printf("Process ID: %d (os: %d)\n", pid, os.Getpid())
	fmt.Printf("Parent Process ID: %d (os: %d)\n", ppid, os.Getppid())
	fmt.Printf("Page size: %d bytes\n", pageSize)

	b := []byte{'s', 'a', 'm', 'p', 'l', 'e', 0, 't', 'e', 'x', 't'}
	str := unix.ByteSliceToString(b)
	fmt.Printf("Converted string: %s\n", str)

	var uts unix.Utsname
	if err := unix.Uname(&uts); err == nil {
		fmt.Printf("OS sysname: %s\n", unix.ByteSliceToString(uts.Sysname[:]))
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/sys@v0.0.0-20210615035016-665e8c7367d1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/sys@v0.0.0-20210615035016-665e8c7367d1"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

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

func main() {
	if err := runTests(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("All contract assertions passed.")
}

func runTests() error {
	// 1. unix.Getpid returns a positive integer process ID matching os.Getpid
	pid := unix.Getpid()
	if pid <= 0 {
		return fmt.Errorf("expected unix.Getpid() > 0, got %d", pid)
	}
	if pid != os.Getpid() {
		return fmt.Errorf("expected unix.Getpid() (%d) to equal os.Getpid() (%d)", pid, os.Getpid())
	}

	// 2. unix.Getppid returns a positive integer parent process ID matching os.Getppid
	ppid := unix.Getppid()
	if ppid <= 0 {
		return fmt.Errorf("expected unix.Getppid() > 0, got %d", ppid)
	}
	if ppid != os.Getppid() {
		return fmt.Errorf("expected unix.Getppid() (%d) to equal os.Getppid() (%d)", ppid, os.Getppid())
	}

	// 3. unix.Getpagesize returns a positive system page size that is a power of two matching os.Getpagesize
	pageSize := unix.Getpagesize()
	if pageSize <= 0 || (pageSize&(pageSize-1)) != 0 {
		return fmt.Errorf("expected positive power of 2 page size, got %d", pageSize)
	}
	if pageSize != os.Getpagesize() {
		return fmt.Errorf("expected unix.Getpagesize() (%d) to equal os.Getpagesize() (%d)", pageSize, os.Getpagesize())
	}

	// 4. unix.ByteSliceToString converts a null-terminated byte slice into a Go string
	buf := []byte{'t', 'e', 's', 't', 0, 'e', 'x', 't', 'r', 'a'}
	str := unix.ByteSliceToString(buf)
	if str != "test" {
		return fmt.Errorf("expected 'test', got %q", str)
	}

	// 5. unix.BytePtrToString converts a null-terminated byte pointer into a Go string
	ptrStr := unix.BytePtrToString(&buf[0])
	if ptrStr != "test" {
		return fmt.Errorf("expected 'test', got %q", ptrStr)
	}

	// 6. unix.Uname populates a Utsname structure with non-empty sysname and nodename
	var uts unix.Utsname
	if err := unix.Uname(&uts); err != nil {
		return fmt.Errorf("unix.Uname failed: %w", err)
	}
	sysname := unix.ByteSliceToString(uts.Sysname[:])
	nodename := unix.ByteSliceToString(uts.Nodename[:])
	if sysname == "" {
		return fmt.Errorf("expected non-empty sysname from unix.Uname")
	}
	if nodename == "" {
		return fmt.Errorf("expected non-empty nodename from unix.Uname")
	}

	return nil
}

オリジンシーダー

匿名