CodeSampleX

Beispiel

filippo.io/edwards25519 v1.1.0: Perform Edwards25519 point and scalar multiplication and addition with filippo.io/edwards25519

Verifiziertes Beispiel für golang filippo.io/edwards25519 v1.1.0: Perform Edwards25519 point and scalar multiplication and addition with…

sha256:9265dd8d73a2f966f5f5abd17d60948d082b25fcd77e46a0a7b0a7eb1bc073b1

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
2
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 go

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-23
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-09-07

Fall

HOW
Ziel
Perform Edwards25519 point and scalar multiplication and addition with filippo.io/edwards25519
Pakete
Erstellt
2026-08-23T17:54:13Z

Contract

  1. Point.ScalarBaseMult multiplies base point by scalar
  2. Point.ScalarMult multiplies arbitrary point by scalar
  3. Scalar.Multiply performs scalar multiplication
  4. ScalarMult satisfies associativity s2*(s1*B) == (s1*s2)*B
  5. Point.Add adds identity point leaving point unchanged
  6. Point.SetBytes roundtrips serialized point bytes
  7. Scalar.SetCanonicalBytes roundtrips canonical scalar bytes
  8. Scalar.SetCanonicalBytes rejects non-canonical scalar bytes

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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: Perform Edwards25519 point and scalar multiplication and addition with filippo.io/edwards25519
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/filippo.io/edwards25519@v1.1.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:b5dd2d21b032e87147c74883f554abac2050ff9b7b7aef6a35251420c7375a8f","contract":["Point.ScalarBaseMult multiplies base point by scalar","Point.ScalarMult multiplies arbitrary point by scalar","Scalar.Multiply performs scalar multiplication","ScalarMult satisfies associativity s2*(s1*B) == (s1*s2)*B","Point.Add adds identity point leaving point unchanged","Point.SetBytes roundtrips serialized point bytes","Scalar.SetCanonicalBytes roundtrips canonical scalar bytes","Scalar.SetCanonicalBytes rejects non-canonical scalar bytes"],"goal":"Perform Edwards25519 point and scalar multiplication and addition with filippo.io/edwards25519","kind":"HOW","packages":["pkg:golang/filippo.io/edwards25519@v1.1.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/filippo.io/edwards25519@v1.1.0"],"schemaVersion":1,"subject":"pkg:golang/filippo.io/edwards25519@v1.1.0","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require filippo.io/edwards25519 v1.1.0
go.sum
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
main.go
package main

import (
	"fmt"
	"log"

	"filippo.io/edwards25519"
)

func main() {
	// Initialize scalar s1
	var seed1 [64]byte
	for i := range seed1 {
		seed1[i] = byte(i + 1)
	}
	s1, err := edwards25519.NewScalar().SetUniformBytes(seed1[:])
	if err != nil {
		log.Fatalf("SetUniformBytes s1 failed: %v", err)
	}

	// Initialize scalar s2
	var seed2 [64]byte
	for i := range seed2 {
		seed2[i] = byte(i + 42)
	}
	s2, err := edwards25519.NewScalar().SetUniformBytes(seed2[:])
	if err != nil {
		log.Fatalf("SetUniformBytes s2 failed: %v", err)
	}

	// Compute base point scalar multiplication: P1 = s1 * B
	p1 := edwards25519.NewIdentityPoint().ScalarBaseMult(s1)
	fmt.Printf("P1 (s1 * B) serialized length: %d bytes\n", len(p1.Bytes()))

	// Compute arbitrary point scalar multiplication: P2 = s2 * P1
	p2 := edwards25519.NewIdentityPoint().ScalarMult(s2, p1)

	// Compute scalar multiplication: s3 = s1 * s2
	s3 := edwards25519.NewScalar().Multiply(s1, s2)

	// Compute P3 = s3 * B = (s1 * s2) * B
	p3 := edwards25519.NewIdentityPoint().ScalarBaseMult(s3)

	// Verify equality: s2 * (s1 * B) == (s1 * s2) * B
	if p2.Equal(p3) == 1 {
		fmt.Println("Scalar multiplication associativity verified: s2*(s1*B) == (s1*s2)*B")
	} else {
		log.Fatalf("Associativity check failed")
	}

	// Point addition with identity: P + 0 = P
	identity := edwards25519.NewIdentityPoint()
	pAdded := edwards25519.NewIdentityPoint().Add(p2, identity)
	if pAdded.Equal(p2) == 1 {
		fmt.Println("Point addition with identity verified.")
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "Perform Edwards25519 point and scalar multiplication and addition with filippo.io/edwards25519",
  "kind": "HOW",
  "packages": [
    "pkg:golang/filippo.io/edwards25519@v1.1.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 (
	"bytes"
	"fmt"
	"os"

	"filippo.io/edwards25519"
)

func main() {
	var seed1 [64]byte
	for i := range seed1 {
		seed1[i] = byte(i + 1)
	}
	var seed2 [64]byte
	for i := range seed2 {
		seed2[i] = byte(i + 42)
	}

	s1, err := edwards25519.NewScalar().SetUniformBytes(seed1[:])
	if err != nil {
		fmt.Fprintf(os.Stderr, "SetUniformBytes s1 failed: %v\n", err)
		os.Exit(1)
	}
	s2, err := edwards25519.NewScalar().SetUniformBytes(seed2[:])
	if err != nil {
		fmt.Fprintf(os.Stderr, "SetUniformBytes s2 failed: %v\n", err)
		os.Exit(1)
	}

	// 1. Point.ScalarBaseMult multiplies base point by scalar
	p1 := edwards25519.NewIdentityPoint().ScalarBaseMult(s1)
	if p1.Equal(edwards25519.NewIdentityPoint()) == 1 {
		fmt.Fprintf(os.Stderr, "Point.ScalarBaseMult resulted in identity point\n")
		os.Exit(1)
	}

	// 2. Point.ScalarMult multiplies arbitrary point by scalar
	p2 := edwards25519.NewIdentityPoint().ScalarMult(s2, p1)

	// 3. Scalar.Multiply performs scalar multiplication
	s3 := edwards25519.NewScalar().Multiply(s1, s2)

	// 4. ScalarMult satisfies associativity s2*(s1*B) == (s1*s2)*B
	p3 := edwards25519.NewIdentityPoint().ScalarBaseMult(s3)
	if p2.Equal(p3) != 1 {
		fmt.Fprintf(os.Stderr, "ScalarMult associativity failed: s2*(s1*B) != (s1*s2)*B\n")
		os.Exit(1)
	}

	// 5. Point.Add adds identity point leaving point unchanged
	identity := edwards25519.NewIdentityPoint()
	pAdded := edwards25519.NewIdentityPoint().Add(p2, identity)
	if pAdded.Equal(p2) != 1 {
		fmt.Fprintf(os.Stderr, "Point.Add identity addition failed\n")
		os.Exit(1)
	}

	// 6. Point.SetBytes roundtrips serialized point bytes
	pBytes := p2.Bytes()
	pRestored, err := edwards25519.NewIdentityPoint().SetBytes(pBytes)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Point.SetBytes failed: %v\n", err)
		os.Exit(1)
	}
	if pRestored.Equal(p2) != 1 {
		fmt.Fprintf(os.Stderr, "Point.SetBytes roundtrip equality failed\n")
		os.Exit(1)
	}

	// 7. Scalar.SetCanonicalBytes roundtrips canonical scalar bytes
	sBytes := s1.Bytes()
	sRestored, err := edwards25519.NewScalar().SetCanonicalBytes(sBytes)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Scalar.SetCanonicalBytes failed: %v\n", err)
		os.Exit(1)
	}
	if sRestored.Equal(s1) != 1 {
		fmt.Fprintf(os.Stderr, "Scalar.SetCanonicalBytes roundtrip equality failed\n")
		os.Exit(1)
	}
	if !bytes.Equal(sBytes, sRestored.Bytes()) {
		fmt.Fprintf(os.Stderr, "Scalar.Bytes() mismatch\n")
		os.Exit(1)
	}

	// 8. Scalar.SetCanonicalBytes rejects non-canonical scalar bytes
	nonCanonicalBytes := bytes.Repeat([]byte{0xff}, 32)
	if _, err := edwards25519.NewScalar().SetCanonicalBytes(nonCanonicalBytes); err == nil {
		fmt.Fprintf(os.Stderr, "Scalar.SetCanonicalBytes should have rejected non-canonical bytes\n")
		os.Exit(1)
	}

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

Ursprungs-Seeder

anonym