refactor(testing): base tamper specs on StrictBaseModel - #909
Merged
tcoratger merged 1 commit intoJun 10, 2026
Merged
Conversation
The proof and signature tamper specs inherited raw pydantic.BaseModel, the only models in the package to do so. They lacked the frozen, strict, and extra-forbid constraints every other spec and fixture model carries through StrictBaseModel. Base them on StrictBaseModel for consistency. The specs are immutable value tags applied during generation and are never mutated, so freezing them is safe. All construction sites already pass correctly typed values, so strict validation accepts them unchanged. The empty-model union members still preserve their exact type through validation, so the match dispatch over each tamper is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The proof and signature tamper specs in
verify_proofs.py(5 classes) andverify_signatures.py(6 classes) inherited rawpydantic.BaseModel— the only models in the package to do so. Every other spec and fixture model inheritsStrictBaseModel/CamelModel, which adds:frozen=True— no mutation after constructionstrict=True— no implicit type coercionextra="forbid"— unknown fields rejectedpopulate_by_name=TrueA latent inconsistency in a reference codebase.
What this does
Bases all eleven tamper specs on
StrictBaseModel. These are immutable value tags applied during generation and consumed bymatchdispatch — never mutated — so freezing is safe, and all construction sites already pass correctly typed values (ValidatorIndex(...)for typed fields, plainintforintfields), so strict validation accepts them unchanged.Why it's behavior-preserving
The
SignedBlockTamper/SingleMessageTamper/MultiMessageTamperunions include several structurally identical empty models, so the concern was whether validation might coerce one empty tamper into a sibling and break thematchdispatch. Verified it does not:Pydantic v2 keeps an exact union-member instance as-is (
revalidate_instancesdefaults to never), so dispatch is unchanged.Testing
just checkpasses (lint, format, ty, codespell, mdformat).verify_proofs+verify_signaturespasses; tamper paths emit their distinct rejection reasons (INVALID_BLOCK_PROOF,INVALID_SIGNATURE).frozenrejects post-construction mutation.🤖 Generated with Claude Code