CodeSampleX

Exemple

golang.org/x/sys v0.40.0

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

sha256:fb9c411a2be5fa9a672e8254bcf4271fc4c852014d2dcb89948cca41542c351b

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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-10-11

Cas

HOW
Objectif
verify pkg:golang/golang.org/x/sys@v0.40.0
Paquets
Créé
2026-10-11T09:29:13Z

Contrat

  1. unix.Getpid returns a positive process ID
  2. unix.Getppid returns a non-negative parent process ID
  3. unix.Getpagesize returns a positive power-of-two page size
  4. unix.ByteSliceToString parses null-terminated C strings
  5. unix.TimevalToNsec converts a unix.Timeval struct into nanoseconds
  6. unix.NsecToTimeval converts nanoseconds into a unix.Timeval struct
  7. unix.TimespecToNsec converts a unix.Timespec struct into nanoseconds
  8. unix.NsecToTimespec converts nanoseconds into a unix.Timespec struct

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

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/sys@v0.40.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:24d16ca51c98782568afe068fa18a64db55c68aa77b466475ba5aaaf2bec498f","contract":["unix.Getpid returns a positive process ID","unix.Getppid returns a non-negative parent process ID","unix.Getpagesize returns a positive power-of-two page size","unix.ByteSliceToString parses null-terminated C strings","unix.TimevalToNsec converts a unix.Timeval struct into nanoseconds","unix.NsecToTimeval converts nanoseconds into a unix.Timeval struct","unix.TimespecToNsec converts a unix.Timespec struct into nanoseconds","unix.NsecToTimespec converts nanoseconds into a unix.Timespec struct"],"goal":"verify pkg:golang/golang.org/x/sys@v0.40.0","kind":"HOW","packages":["pkg:golang/golang.org/x/sys@v0.40.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.40.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/sys@v0.40.0","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require golang.org/x/sys v0.40.0
go.sum
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
main.go
package main

import (
	"fmt"

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

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

	fmt.Printf("Process PID: %d, Parent PID: %d, Page size: %d\n", pid, ppid, pageSize)

	tv := unix.Timeval{Sec: 1, Usec: 500000}
	nsec := unix.TimevalToNsec(tv)
	fmt.Printf("Timeval (%d sec, %d usec) -> %d ns\n", tv.Sec, tv.Usec, nsec)

	str := unix.ByteSliceToString([]byte{'c', 's', 'x', 0, 't', 'e', 's', 't'})
	fmt.Printf("ByteSliceToString -> %q\n", str)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/sys@v0.40.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/sys@v0.40.0"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

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

func main() {
	// Assertion 1: unix.Getpid returns a positive process ID
	pid := unix.Getpid()
	if pid <= 0 {
		fmt.Fprintf(os.Stderr, "FAIL: expected positive PID, got %d\n", pid)
		os.Exit(1)
	}

	// Assertion 2: unix.Getppid returns a non-negative parent process ID
	ppid := unix.Getppid()
	if ppid < 0 {
		fmt.Fprintf(os.Stderr, "FAIL: expected non-negative PPID, got %d\n", ppid)
		os.Exit(1)
	}

	// Assertion 3: unix.Getpagesize returns a positive power-of-two page size
	pageSize := unix.Getpagesize()
	if pageSize <= 0 || (pageSize&(pageSize-1)) != 0 {
		fmt.Fprintf(os.Stderr, "FAIL: expected positive power-of-two page size, got %d\n", pageSize)
		os.Exit(1)
	}

	// Assertion 4: unix.ByteSliceToString parses null-terminated C strings
	raw := []byte{'h', 'e', 'l', 'l', 'o', 0, 'w', 'o', 'r', 'l', 'd'}
	parsed := unix.ByteSliceToString(raw)
	if parsed != "hello" {
		fmt.Fprintf(os.Stderr, "FAIL: expected 'hello', got %q\n", parsed)
		os.Exit(1)
	}

	// Assertion 5: unix.TimevalToNsec converts a unix.Timeval struct into nanoseconds
	tv := unix.Timeval{Sec: 2, Usec: 500000}
	expectedNsec := int64(2500000000)
	actualNsec := unix.TimevalToNsec(tv)
	if actualNsec != expectedNsec {
		fmt.Fprintf(os.Stderr, "FAIL: expected %d ns, got %d ns\n", expectedNsec, actualNsec)
		os.Exit(1)
	}

	// Assertion 6: unix.NsecToTimeval converts nanoseconds into a unix.Timeval struct
	convertedTv := unix.NsecToTimeval(expectedNsec)
	if convertedTv.Sec != tv.Sec || convertedTv.Usec != tv.Usec {
		fmt.Fprintf(os.Stderr, "FAIL: expected Timeval{Sec: %d, Usec: %d}, got %+v\n", tv.Sec, tv.Usec, convertedTv)
		os.Exit(1)
	}

	// Assertion 7: unix.TimespecToNsec converts a unix.Timespec struct into nanoseconds
	ts := unix.Timespec{Sec: 3, Nsec: 123456789}
	expectedTsNsec := int64(3123456789)
	actualTsNsec := unix.TimespecToNsec(ts)
	if actualTsNsec != expectedTsNsec {
		fmt.Fprintf(os.Stderr, "FAIL: expected %d ns, got %d ns\n", expectedTsNsec, actualTsNsec)
		os.Exit(1)
	}

	// Assertion 8: unix.NsecToTimespec converts nanoseconds into a unix.Timespec struct
	convertedTs := unix.NsecToTimespec(expectedTsNsec)
	if convertedTs.Sec != ts.Sec || convertedTs.Nsec != ts.Nsec {
		fmt.Fprintf(os.Stderr, "FAIL: expected Timespec{Sec: %d, Nsec: %d}, got %+v\n", ts.Sec, ts.Nsec, convertedTs)
		os.Exit(1)
	}

	fmt.Println("PASS: all contract assertions passed successfully")
}

Seeder d'origine

anonyme