CodeSampleX

Sample

github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2: profile.Parse

Verified sample for golang github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2: profile.Parse. The contract ran on go 1.26 · linux debian/x64 · docker…

sha256:9c665b2fcc7551be88d0512f8c07635a12959f6f6ea25f6992008cabb2658d1a

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

Verification-run environments

Environment Contract Stages Run
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-29

Case

HOW
Goal
verify github.com/google/pprof/profile.Parse in pkg:golang/github.com/google/pprof@v0.0.0-20201218002935-b9804c9f04c2
Packages
Symbols
  • github.com/google/pprof/profile.Parse
Environment
go 1.26.6
Created
2026-10-29T03:50:36Z

Contract

  1. profile.Profile creates and validates a structured cpu/memory profile with CheckValid
  2. profile.Profile.Write serializes the profile into gzip-compressed protobuf format
  3. profile.Parse parses serialized profile data and restores samples, locations, and functions

Files

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

Download the source artifact (tar.gz)

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 github.com/google/pprof/profile.Parse in pkg:golang/github.com/google/pprof@v0.0.0-20201218002935-b9804c9f04c2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/pprof@v0.0.0-20201218002935-b9804c9f04c2
Demonstrate these symbols/APIs:
  - github.com/google/pprof/profile.Parse

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:ddd3e90578d071b77b0f7141622a562f7a9356d119fc348d4b30fedcaede4c85","contract":["profile.Profile creates and validates a structured cpu/memory profile with CheckValid","profile.Profile.Write serializes the profile into gzip-compressed protobuf format","profile.Parse parses serialized profile data and restores samples, locations, and functions"],"goal":"verify github.com/google/pprof/profile.Parse in pkg:golang/github.com/google/pprof@v0.0.0-20201218002935-b9804c9f04c2","kind":"HOW","packages":["pkg:golang/github.com/google/pprof@v0.0.0-20201218002935-b9804c9f04c2"],"schemaVersion":1,"symbols":["github.com/google/pprof/profile.Parse"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/google/pprof@v0.0.0-20201218002935-b9804c9f04c2"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/pprof@v0.0.0-20201218002935-b9804c9f04c2","symbols":["github.com/google/pprof/profile.Parse"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.25.0

require github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2
go.sum
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2 h1:LR89qFljJ48s990kEKGsk213yIJDPI4205OKOzbURK8=
github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
sample.go
package sample

import (
	"bytes"
	"io"

	"github.com/google/pprof/profile"
)

// BuildSampleProfile constructs a valid profile with sample type, functions, locations, and samples.
func BuildSampleProfile(functionName, filename string, line int64, sampleCount, cpuNanos int64) (*profile.Profile, error) {
	p := &profile.Profile{
		SampleType: []*profile.ValueType{
			{Type: "samples", Unit: "count"},
			{Type: "cpu", Unit: "nanoseconds"},
		},
		PeriodType: &profile.ValueType{Type: "cpu", Unit: "nanoseconds"},
		Period:     10000000,
	}

	fn := &profile.Function{
		ID:         1,
		Name:       functionName,
		SystemName: functionName,
		Filename:   filename,
		StartLine:  line,
	}
	p.Function = []*profile.Function{fn}

	loc := &profile.Location{
		ID: 1,
		Line: []profile.Line{
			{
				Function: fn,
				Line:     line + 5,
			},
		},
	}
	p.Location = []*profile.Location{loc}

	s := &profile.Sample{
		Location: []*profile.Location{loc},
		Value:    []int64{sampleCount, cpuNanos},
	}
	p.Sample = []*profile.Sample{s}

	if err := p.CheckValid(); err != nil {
		return nil, err
	}

	return p, nil
}

// SerializeProfile writes a Profile to an io.Writer in standard pprof format.
func SerializeProfile(p *profile.Profile, w io.Writer) error {
	return p.Write(w)
}

// ParseProfile parses a serialized pprof stream from an io.Reader.
func ParseProfile(r io.Reader) (*profile.Profile, error) {
	return profile.Parse(r)
}

// EncodeAndDecode serializes and re-parses a profile, returning the decoded profile.
func EncodeAndDecode(p *profile.Profile) (*profile.Profile, error) {
	var buf bytes.Buffer
	if err := p.Write(&buf); err != nil {
		return nil, err
	}
	return profile.Parse(&buf)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/google/pprof/profile.Parse in pkg:golang/github.com/google/pprof@v0.0.0-20201218002935-b9804c9f04c2",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/pprof@v0.0.0-20201218002935-b9804c9f04c2"
  ],
  "symbols": [
    "github.com/google/pprof/profile.Parse"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/google/pprof/profile"
	"sample"
)

func main() {
	// Assertion 1: profile.Profile creates and validates a structured cpu/memory profile with CheckValid
	p, err := sample.BuildSampleProfile("worker.processTask", "worker.go", 10, 5, 50000000)
	if err != nil {
		fmt.Fprintf(os.Stderr, "BuildSampleProfile failed: %v\n", err)
		os.Exit(1)
	}

	var _ *profile.Profile = p
	if err := p.CheckValid(); err != nil {
		fmt.Fprintf(os.Stderr, "p.CheckValid failed: %v\n", err)
		os.Exit(1)
	}

	if len(p.Sample) != 1 {
		fmt.Fprintf(os.Stderr, "expected 1 sample, got %d\n", len(p.Sample))
		os.Exit(1)
	}

	// Assertion 2: profile.Profile.Write serializes the profile into gzip-compressed protobuf format
	var buf bytes.Buffer
	if err := p.Write(&buf); err != nil {
		fmt.Fprintf(os.Stderr, "p.Write failed: %v\n", err)
		os.Exit(1)
	}

	if buf.Len() == 0 {
		fmt.Fprintf(os.Stderr, "serialized buffer is empty\n")
		os.Exit(1)
	}

	// Assertion 3: profile.Parse parses serialized profile data and restores samples, locations, and functions
	parsed, err := profile.Parse(&buf)
	if err != nil {
		fmt.Fprintf(os.Stderr, "profile.Parse failed: %v\n", err)
		os.Exit(1)
	}

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

	if len(parsed.Sample) != 1 {
		fmt.Fprintf(os.Stderr, "expected 1 sample in parsed profile, got %d\n", len(parsed.Sample))
		os.Exit(1)
	}

	if parsed.Sample[0].Value[0] != 5 || parsed.Sample[0].Value[1] != 50000000 {
		fmt.Fprintf(os.Stderr, "parsed sample values mismatch: got %v, expected [5, 50000000]\n", parsed.Sample[0].Value)
		os.Exit(1)
	}

	if len(parsed.Function) != 1 || parsed.Function[0].Name != "worker.processTask" {
		fmt.Fprintf(os.Stderr, "parsed function mismatch\n")
		os.Exit(1)
	}

	if len(parsed.Location) != 1 || len(parsed.Location[0].Line) != 1 || parsed.Location[0].Line[0].Line != 15 {
		fmt.Fprintf(os.Stderr, "parsed location line mismatch\n")
		os.Exit(1)
	}

	fmt.Println("All pprof profile contract assertions passed.")
}

Origin Seeder

anonymous