CodeSampleX

Ejemplo

modernc.org/memory v1.11.0

Muestra verificada para golang modernc.org/memory v1.11.0. El contrato se ejecutó en go 1.26 · linux alpine/x64 · docker y pasó.

sha256:029cb77b24a6edea4c8091ed6cf7682f9872c0de61e6c883bd3b2471cb7550af

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado windows 11 x64 go

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-19

Caso

HOW
Objetivo
verify pkg:golang/modernc.org/memory@v1.11.0
Paquetes
Creado
2026-08-18T17:41:26Z

Contrato

  1. memory.Allocator zero value is ready to allocate and free memory
  2. alloc.Malloc allocates a byte slice of the requested size without errors
  3. alloc.Realloc resizes an allocated memory block preserving existing contents
  4. alloc.Calloc allocates a zero-initialized byte slice of the requested size
  5. alloc.Free deallocates memory blocks without errors
  6. alloc.Close closes the allocator and releases OS memory resources

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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/modernc.org/memory@v1.11.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/modernc.org/memory@v1.11.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:5347e44876c17ec489aa74b079a0435e08e9f88f084765f58023f45fdfe147f5","contract":["memory.Allocator zero value is ready to allocate and free memory","alloc.Malloc allocates a byte slice of the requested size without errors","alloc.Realloc resizes an allocated memory block preserving existing contents","alloc.Calloc allocates a zero-initialized byte slice of the requested size","alloc.Free deallocates memory blocks without errors","alloc.Close closes the allocator and releases OS memory resources"],"goal":"verify pkg:golang/modernc.org/memory@v1.11.0","kind":"HOW","packages":["pkg:golang/modernc.org/memory@v1.11.0"],"schemaVersion":1},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","ecosystem":"golang","os":"windows","osVersionBucket":"11","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/modernc.org/memory@v1.11.0"],"schemaVersion":1,"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.23.0

require modernc.org/memory v1.11.0

require golang.org/x/sys v0.31.0 // indirect
go.sum
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/modernc.org/memory@v1.11.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/modernc.org/memory@v1.11.0"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"modernc.org/memory"
)

func main() {
	var alloc memory.Allocator
	defer func() {
		if err := alloc.Close(); err != nil {
			fmt.Fprintf(os.Stderr, "alloc.Close failed: %v\n", err)
			os.Exit(1)
		}
	}()

	// 1. Test Malloc
	buf, err := alloc.Malloc(128)
	if err != nil {
		fmt.Fprintf(os.Stderr, "alloc.Malloc(128) failed: %v\n", err)
		os.Exit(1)
	}
	if len(buf) != 128 {
		fmt.Fprintf(os.Stderr, "expected len 128, got %d\n", len(buf))
		os.Exit(1)
	}

	// Write pattern to allocated buffer
	for i := 0; i < len(buf); i++ {
		buf[i] = byte(i % 256)
	}

	// 2. Test Realloc (expanding buffer)
	buf, err = alloc.Realloc(buf, 256)
	if err != nil {
		fmt.Fprintf(os.Stderr, "alloc.Realloc(buf, 256) failed: %v\n", err)
		os.Exit(1)
	}
	if len(buf) != 256 {
		fmt.Fprintf(os.Stderr, "expected len 256 after Realloc, got %d\n", len(buf))
		os.Exit(1)
	}

	// Verify original contents preserved
	for i := 0; i < 128; i++ {
		if buf[i] != byte(i%256) {
			fmt.Fprintf(os.Stderr, "data mismatch at index %d after Realloc: expected %d, got %d\n", i, byte(i%256), buf[i])
			os.Exit(1)
		}
	}

	// 3. Test Free
	if err := alloc.Free(buf); err != nil {
		fmt.Fprintf(os.Stderr, "alloc.Free failed: %v\n", err)
		os.Exit(1)
	}

	// 4. Test Calloc (zero-initialized allocation)
	zeroBuf, err := alloc.Calloc(64)
	if err != nil {
		fmt.Fprintf(os.Stderr, "alloc.Calloc(64) failed: %v\n", err)
		os.Exit(1)
	}
	if len(zeroBuf) != 64 {
		fmt.Fprintf(os.Stderr, "expected len 64 from Calloc, got %d\n", len(zeroBuf))
		os.Exit(1)
	}

	expectedZeros := make([]byte, 64)
	if !bytes.Equal(zeroBuf, expectedZeros) {
		fmt.Fprintf(os.Stderr, "expected Calloc buffer to be zero-filled\n")
		os.Exit(1)
	}

	if err := alloc.Free(zeroBuf); err != nil {
		fmt.Fprintf(os.Stderr, "alloc.Free(zeroBuf) failed: %v\n", err)
		os.Exit(1)
	}

	fmt.Println("modernc.org/memory allocator contract verified successfully")
}

Seeder de origen

anónimo