CodeSampleX

サンプル

golang.org/x/sys v0.18.0

検証済みサンプル — golang golang.org/x/sys v0.18.0. go 1.26 · linux alpine/x64 · docker で contract を実行し、成功しました: unix.Getpagesize returns a positive system memory…

sha256:f1a2f783da16120ec642c2140cd47bf0e4a7e66910dd62f9231a556a96047d99

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

コントラクト

  1. unix.Getpagesize returns a positive system memory page size in bytes
  2. unix.Pipe creates a unidirectional pipe returning valid non-negative file descriptors for read and write
  3. unix.Write writes bytes to a pipe descriptor and unix.Read reads the matching bytes back
  4. unix.Getpid returns the caller process ID matching os.Getpid
  5. unix.NsecToTimeval converts nanoseconds to Timeval and unix.TimevalToNsec accurately converts back

ファイル

  • 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.18.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/sys@v0.18.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:f6275f362c3de54fcd98626ca29d43f26f6881ad8dd700b373e1dd9b2477e902","contract":["unix.Getpagesize returns a positive system memory page size in bytes","unix.Pipe creates a unidirectional pipe returning valid non-negative file descriptors for read and write","unix.Write writes bytes to a pipe descriptor and unix.Read reads the matching bytes back","unix.Getpid returns the caller process ID matching os.Getpid","unix.NsecToTimeval converts nanoseconds to Timeval and unix.TimevalToNsec accurately converts back"],"goal":"verify pkg:golang/golang.org/x/sys@v0.18.0","kind":"HOW","packages":["pkg:golang/golang.org/x/sys@v0.18.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.18.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/sys@v0.18.0","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22.0

require golang.org/x/sys v0.18.0
go.sum
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
main.go
package main

import (
	"fmt"
	"os"

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

// GetPageSize returns the memory page size in bytes.
func GetPageSize() int {
	return unix.Getpagesize()
}

// CreatePipe creates a pipe and returns the read and write file descriptors.
func CreatePipe() ([2]int, error) {
	var fds [2]int
	if err := unix.Pipe(fds[:]); err != nil {
		return fds, fmt.Errorf("pipe failed: %w", err)
	}
	return fds, nil
}

// PipeEcho writes a message to the pipe and reads it back.
func PipeEcho(msg []byte) ([]byte, error) {
	fds, err := CreatePipe()
	if err != nil {
		return nil, err
	}
	defer unix.Close(fds[0])
	defer unix.Close(fds[1])

	if _, err := unix.Write(fds[1], msg); err != nil {
		return nil, fmt.Errorf("write failed: %w", err)
	}

	buf := make([]byte, len(msg))
	n, err := unix.Read(fds[0], buf)
	if err != nil {
		return nil, fmt.Errorf("read failed: %w", err)
	}
	return buf[:n], nil
}

// ConvertTimevalRoundTrip converts nanoseconds to Timeval and back.
func ConvertTimevalRoundTrip(nsec int64) (unix.Timeval, int64) {
	tv := unix.NsecToTimeval(nsec)
	recovered := unix.TimevalToNsec(tv)
	return tv, recovered
}

func main() {
	pageSize := GetPageSize()
	fmt.Printf("Memory page size: %d bytes\n", pageSize)

	pid := unix.Getpid()
	fmt.Printf("Current PID: %d\n", pid)

	data := []byte("hello from unix pipe")
	echoed, err := PipeEcho(data)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error in PipeEcho: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Echoed data: %s\n", string(echoed))

	tv, rec := ConvertTimevalRoundTrip(1_234_567_000)
	fmt.Printf("Timeval: %d sec, %d usec -> Recovered: %d nsec\n", tv.Sec, tv.Usec, rec)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/sys@v0.18.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/sys@v0.18.0"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

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

func main() {
	// Assertion 1: unix.Getpagesize returns a positive system memory page size in bytes
	pageSize := unix.Getpagesize()
	if pageSize <= 0 {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Getpagesize returned non-positive size: %d\n", pageSize)
		os.Exit(1)
	}
	if pageSize%512 != 0 {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Getpagesize unexpected non-multiple of 512: %d\n", pageSize)
		os.Exit(1)
	}

	// Assertion 2: unix.Pipe creates a unidirectional pipe returning valid non-negative file descriptors for read and write
	var fds [2]int
	if err := unix.Pipe(fds[:]); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Pipe failed: %v\n", err)
		os.Exit(1)
	}
	defer unix.Close(fds[0])
	defer unix.Close(fds[1])

	if fds[0] < 0 || fds[1] < 0 {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Pipe returned negative file descriptors: [%d, %d]\n", fds[0], fds[1])
		os.Exit(1)
	}

	// Assertion 3: unix.Write writes bytes to a pipe descriptor and unix.Read reads the matching bytes back
	payload := []byte("csx-sys-contract-verification-payload")
	nWritten, err := unix.Write(fds[1], payload)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Write failed: %v\n", err)
		os.Exit(1)
	}
	if nWritten != len(payload) {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Write short write: wrote %d, want %d\n", nWritten, len(payload))
		os.Exit(1)
	}

	readBuf := make([]byte, len(payload))
	nRead, err := unix.Read(fds[0], readBuf)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Read failed: %v\n", err)
		os.Exit(1)
	}
	if nRead != len(payload) {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Read short read: read %d, want %d\n", nRead, len(payload))
		os.Exit(1)
	}
	if !bytes.Equal(readBuf, payload) {
		fmt.Fprintf(os.Stderr, "FAIL: read data does not match payload: got %q, want %q\n", readBuf, payload)
		os.Exit(1)
	}

	// Assertion 4: unix.Getpid returns the caller process ID matching os.Getpid
	pid := unix.Getpid()
	if pid <= 0 {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Getpid returned non-positive PID: %d\n", pid)
		os.Exit(1)
	}
	if pid != os.Getpid() {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Getpid mismatch: got %d, want %d\n", pid, os.Getpid())
		os.Exit(1)
	}

	// Assertion 5: unix.NsecToTimeval converts nanoseconds to Timeval and unix.TimevalToNsec accurately converts back
	const testNsec = int64(3_500_000_000)
	tv := unix.NsecToTimeval(testNsec)
	if tv.Sec != 3 || tv.Usec != 500_000 {
		fmt.Fprintf(os.Stderr, "FAIL: unix.NsecToTimeval mismatch: sec=%d, usec=%d (expected sec=3, usec=500000)\n", tv.Sec, tv.Usec)
		os.Exit(1)
	}
	recoveredNsec := unix.TimevalToNsec(tv)
	if recoveredNsec != testNsec {
		fmt.Fprintf(os.Stderr, "FAIL: unix.TimevalToNsec mismatch: got %d, want %d\n", recoveredNsec, testNsec)
		os.Exit(1)
	}

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

オリジンシーダー

匿名