Files
Abhishek Krishna b5a04b9850 test(kzg4844): add EIP-4844 KAT vectors + non-canonical scalar rejection (TESTING_GAPS §1.9)
Addresses TESTING_GAPS.md §1.9 (HIGH severity), which flagged that
kzg4844/contract_test.go has no EIP-4844 reference KAT, no trusted_setup
verification, and no rejection test for blob field elements >= the
BLS12-381 scalar field modulus. The existing createValidBlob helper
uses small values intentionally and never asserts the modulus boundary;
silent reduction at that boundary would be consensus-splitting.

New file: kzg4844/kat_test.go
  - TestKZG4844_VectorsManifestParses
  - TestKZG4844_TrustedSetupInitialized
      Asserts the precompile commit equals a freshly-built
      NewContext4096Secure commit, pinning the trusted setup to the
      official Ethereum KZG ceremony parameters shipped by go-kzg-4844.
  - TestBlobToCommitment_AgainstEIP4844Vectors
      - all_zero_blob: commitment is G1 point at infinity (0xc0 || 47*0)
        per consensus-specs polynomial-commitments.md.
      - single_one_at_index_0: precompile result == direct library result,
        and is provably NOT the point at infinity.
  - TestBlobToCommitment_RejectsOversizedFieldElement
      Three cases: field element == r, == r+1, and all-0xFF. All MUST
      error rather than silently reduce.
  - TestBlobToCommitment_RejectsNilBlob, _RejectsShortBlob
      Input-validation negatives.
  - TestComputeKZGProof_KnownAnswer
      Precompile proof bytes and y bytes equal reference library output.
  - TestVerifyKZGProof_ValidRejectsTampered
      Round-trip commit/prove/verify; then independently tampers
      commitment, z, y, and proof bytes and asserts none verify as 0x01.

New file: kzg4844/testdata/eip4844_vectors.json (~2 KiB)
  Manifest of vector names, sources, and rationale. Blob bytes are not
  embedded (a 128 KiB all-zero blob need not be in testdata) — the
  manifest documents the intent and source attribution.

Does not modify any existing source file. No overlap with PR #1.
go vet ./kzg4844/... and go test ./kzg4844/... -count=1 pass.
2026-06-01 11:11:11 +00:00

36 lines
2.1 KiB
JSON

{
"_meta": {
"description": "Known-answer test vectors for EIP-4844 KZG operations.",
"vectors": [
{
"name": "all_zero_blob",
"source": "EIP-4844 spec / consensus-specs polynomial-commitments.md G1_POINT_AT_INFINITY",
"blob_pattern": "all zero bytes (4096 zero field elements)",
"commitment_hex": "c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"note": "Polynomial commitment of the zero polynomial is the identity element in G1, serialized as 0xc0 followed by 47 zero bytes (BLS12-381 compressed infinity point)."
},
{
"name": "single_one_at_index_0",
"source": "Self-consistency: hand-constructed input, expected output computed by github.com/crate-crypto/go-kzg-4844 v1.1.0 ContextSecure (Ethereum trusted setup ceremony).",
"blob_pattern": "blob[31] = 0x01, all other bytes zero (one field element of value 1 at evaluation point 0, others zero)",
"commitment_hex": "",
"note": "Cross-checks precompile path against direct library call; commitment_hex is computed dynamically and compared with library output to detect divergence between the precompile and the reference library."
},
{
"name": "modulus_field_element",
"source": "EIP-4844 / consensus-specs validate_blob — BLS_MODULUS = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001 (BLS12-381 scalar field r)",
"blob_pattern": "blob[0:32] = BLS_MODULUS (big-endian); remaining bytes zero",
"commitment_hex": "REJECT",
"note": "Field element equal to r MUST be rejected as non-canonical (DeserializeBlob -> ErrNonCanonicalScalar). Silent modular reduction would be consensus-splitting."
},
{
"name": "modulus_plus_one_field_element",
"source": "EIP-4844 / consensus-specs validate_blob",
"blob_pattern": "blob[0:32] = BLS_MODULUS + 1 (big-endian); remaining bytes zero",
"commitment_hex": "REJECT",
"note": "Field element > r must also be rejected."
}
]
}
}