CodeSampleX

示例

golang.org/x/sys v0.12.0

已验证示例 — golang golang.org/x/sys v0.12.0. contract 在 go 1.26 · linux alpine/x64 · docker 上运行并通过: unix.Getpid and unix.Getppid return positive process…

sha256:a1af15ea2d4698a3b7b890e02dfcbe5b790eaabdbca5e5aeb73df15d4ece6036

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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.12.0
包
创建时间
2026-08-27T13:23:09Z

契约

  1. unix.Getpid and unix.Getppid return positive process identifiers
  2. unix.ClockGettime retrieves monotonic clock time with valid nanoseconds
  3. unix.Statfs queries filesystem statistics returning positive block size and total blocks
  4. unix.Eventfd creates non-blocking event file descriptor transferring integer counter value

文件

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

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/sys@v0.12.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:0841ee1fc4b9c6f445189d5fa011008b877329f13112dc922c82141822b7d774","contract":["unix.Getpid and unix.Getppid return positive process identifiers","unix.ClockGettime retrieves monotonic clock time with valid nanoseconds","unix.Statfs queries filesystem statistics returning positive block size and total blocks","unix.Eventfd creates non-blocking event file descriptor transferring integer counter value"],"goal":"verify pkg:golang/golang.org/x/sys@v0.12.0","kind":"HOW","packages":["pkg:golang/golang.org/x/sys@v0.12.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.12.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/sys@v0.12.0","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require golang.org/x/sys v0.12.0
go.sum
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
main.go
package main

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

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

// GetProcessIDs returns the current process ID and parent process ID.
func GetProcessIDs() (int, int) {
	pid := unix.Getpid()
	ppid := unix.Getppid()
	return pid, ppid
}

// GetMonotonicTime returns current monotonic clock reading as unix.Timespec.
func GetMonotonicTime() (unix.Timespec, error) {
	var ts unix.Timespec
	if err := unix.ClockGettime(unix.CLOCK_MONOTONIC, &ts); err != nil {
		return ts, fmt.Errorf("clock_gettime failed: %w", err)
	}
	return ts, nil
}

// GetFilesystemStats returns filesystem statistics for the specified path.
func GetFilesystemStats(path string) (unix.Statfs_t, error) {
	var stat unix.Statfs_t
	if err := unix.Statfs(path, &stat); err != nil {
		return stat, fmt.Errorf("statfs failed: %w", err)
	}
	return stat, nil
}

// TransferEventCounter creates an eventfd, writes a counter value, and reads it back.
func TransferEventCounter(val uint64) (uint64, error) {
	fd, err := unix.Eventfd(0, unix.EFD_CLOEXEC|unix.EFD_NONBLOCK)
	if err != nil {
		return 0, fmt.Errorf("eventfd failed: %w", err)
	}
	defer unix.Close(fd)

	var buf [8]byte
	binary.NativeEndian.PutUint64(buf[:], val)
	n, err := unix.Write(fd, buf[:])
	if err != nil {
		return 0, fmt.Errorf("write to eventfd failed: %w", err)
	}
	if n != 8 {
		return 0, fmt.Errorf("short write to eventfd: %d bytes", n)
	}

	var readBuf [8]byte
	rn, err := unix.Read(fd, readBuf[:])
	if err != nil {
		return 0, fmt.Errorf("read from eventfd failed: %w", err)
	}
	if rn != 8 {
		return 0, fmt.Errorf("short read from eventfd: %d bytes", rn)
	}

	result := binary.NativeEndian.Uint64(readBuf[:])
	return result, nil
}

func main() {
	pid, ppid := GetProcessIDs()
	fmt.Printf("Process IDs: PID=%d, PPID=%d\n", pid, ppid)

	ts, err := GetMonotonicTime()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error getting monotonic time: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Monotonic time: %d.%09d s\n", ts.Sec, ts.Nsec)

	stat, err := GetFilesystemStats(".")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error getting filesystem stats: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Filesystem stats: Bsize=%d, Blocks=%d\n", stat.Bsize, stat.Blocks)

	counter, err := TransferEventCounter(42)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error with eventfd counter: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Eventfd transferred value: %d\n", counter)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/sys@v0.12.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/sys@v0.12.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.go
package main

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

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

func main() {
	// Assertion 1: unix.Getpid and unix.Getppid return positive process identifiers
	pid := unix.Getpid()
	ppid := unix.Getppid()
	if pid <= 0 || ppid < 0 {
		fmt.Fprintf(os.Stderr, "FAIL: invalid PID=%d or PPID=%d\n", pid, ppid)
		os.Exit(1)
	}

	// Assertion 2: unix.ClockGettime retrieves monotonic clock time with valid nanoseconds
	var ts unix.Timespec
	if err := unix.ClockGettime(unix.CLOCK_MONOTONIC, &ts); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: unix.ClockGettime CLOCK_MONOTONIC failed: %v\n", err)
		os.Exit(1)
	}
	if ts.Sec < 0 || ts.Nsec < 0 || ts.Nsec >= 1000000000 {
		fmt.Fprintf(os.Stderr, "FAIL: invalid timespec values: sec=%d, nsec=%d\n", ts.Sec, ts.Nsec)
		os.Exit(1)
	}

	// Assertion 3: unix.Statfs queries filesystem statistics returning positive block size and total blocks
	var stat unix.Statfs_t
	if err := unix.Statfs(".", &stat); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Statfs failed: %v\n", err)
		os.Exit(1)
	}
	if stat.Bsize <= 0 || stat.Blocks == 0 {
		fmt.Fprintf(os.Stderr, "FAIL: invalid statfs values: bsize=%d, blocks=%d\n", stat.Bsize, stat.Blocks)
		os.Exit(1)
	}

	// Assertion 4: unix.Eventfd creates non-blocking event file descriptor transferring integer counter value
	fd, 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(fd)

	var writeBuf [8]byte
	binary.NativeEndian.PutUint64(writeBuf[:], 12345)
	n, err := unix.Write(fd, writeBuf[:])
	if err != nil || n != 8 {
		fmt.Fprintf(os.Stderr, "FAIL: unix.Write on eventfd failed: n=%d, err=%v\n", n, err)
		os.Exit(1)
	}

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

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

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

原始种子者

匿名