Skip to content

test(state_transition): harden PKIX load bounds and document trust boundary - #549

Draft
5t4rg4z3r wants to merge 2 commits into
ChainSafe:mainfrom
5t4rg4z3r:pkix-trust-boundary-539
Draft

test(state_transition): harden PKIX load bounds and document trust boundary#549
5t4rg4z3r wants to merge 2 commits into
ChainSafe:mainfrom
5t4rg4z3r:pkix-trust-boundary-539

Conversation

@5t4rg4z3r

@5t4rg4z3r 5t4rg4z3r commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Motivation

pkix.load and pkix.save handle an application-owned local cache snapshot, but nothing in the code said so. A reader could reasonably mistake the loader's framing, ABI, bounds, and checksum checks for input validation and pass the file an operator-supplied path. The existing bounds tests asserted only the returned error, so they could not distinguish a header rejected before allocation from one rejected because an allocation failed, which is the property that actually matters for a crafted header.

Closes #539.

Description

  • Document the PKIX trust boundary as application-owned local cache data on the Zig module, the load function, and the bindings/src/pubkeys.d.ts declarations.
  • Add expectLoadRejectedWithoutAllocation, which asserts a rejection happened with zero allocation attempts rather than because of a failed one.
  • Cover crafted headers that declare oversized entry counts, an all-zero file, and a short file.
  • Cover spare capacity clamping, so a header declaring 1 << 30 capacity still honors the caller limit.
  • Cover payload and header corruption: bit flips across the key and affine regions, an entry reorder, and both checksum fields.

No behavior change. The loader's existing capacity and file-size bounds are unchanged.

Verification

  • zig build test:state_transition test:ssz test:bls (376 passed)
  • zig fmt --check src bindings test bench examples scripts build.zig
  • pnpm lint
  • pnpm exec vitest run bindings/test/pubkeys.test.ts (19 passed)

Spec and ERA suites were not run locally; their download steps are absent in my environment and this change touches no consensus, SSZ, or ERA behavior.

This PR was written by an AI agent (stargazer), supervised by a human.

…undary

Document the PKIX trust boundary as application-owned local cache only and
add test coverage for crafted headers and corrupt payload fixtures.

Refs ChainSafe#539
@5t4rg4z3r
5t4rg4z3r requested a review from a team as a code owner August 8, 2026 17:05
@spiral-ladder
spiral-ladder marked this pull request as draft August 8, 2026 17:06
@spiral-ladder

Copy link
Copy Markdown
Member

just testing stargazer out

Comment thread bindings/src/pubkeys.d.ts Outdated
Comment on lines +25 to +29
* The file is application-owned local cache data, in the same trust class as the application's
* database files. The caller must keep it under a private cache directory and must scope the path
* to one network. PKIX stores no network identifier. The loader checks framing, ABI
* compatibility, bounds, and a checksum to detect corruption or an incompatible build.
* It does not authenticate the file. Do not pass an operator-supplied or network-sourced path.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very verbose and a repeat of what's in pkix.zig, can u just refer readers to that file's top level doc comment for trust assumptions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3a2fec1. The .d.ts block is now two lines that point to the top-level doc comment in src/state_transition/cache/pkix.zig. The full trust assumptions stay in one place.

Verification: zig fmt --check src bindings test bench examples scripts build.zig, pnpm lint (10 pre-existing warnings, none in pubkeys.d.ts), zig build test:state_transition (123/123 pass).

This reply was written by an AI agent (stargazer), supervised by a human.

Replace the duplicated trust boundary text in pubkeys.d.ts with a pointer
to the top-level doc comment in src/state_transition/cache/pkix.zig.

Refs ChainSafe#539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Harden PKIX load before production load/save use

2 participants