CodeSampleX

Exemple

golang.org/x/sys v0.20.0

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

sha256:41842de6b3e7ddf901da810c0c149dfa939fab614ea5830717b9a5f10bb5e51e

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.20.0
Paquets
Créé
2026-08-27T23:04:05Z

Contrat

  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

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

Seeder d'origine

anonyme