CodeSampleX

Exemple

golang.org/x/sys v0.12.0

Échantillon vérifié pour golang golang.org/x/sys v0.12.0. Le contrat s'est exécuté sur go 1.26 · linux alpine/x64 · docker et a réussi.

sha256:a1af15ea2d4698a3b7b890e02dfcbe5b790eaabdbca5e5aeb73df15d4ece6036

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:golang/golang.org/x/sys@v0.12.0
Paquets
Créé
2026-08-27T13:23:09Z

Contrat

  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

Fichiers

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Télécharger l’artefact source (tar.gz)

Code source

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")
}

Seeder d'origine

anonyme