Skip to content

sszgen: fix bitfield and byte list validation - #27

Open
syjn99 wants to merge 5 commits into
mainfrom
fix/sszgen-validation
Open

syjn99 wants to merge 5 commits into
mainfrom
fix/sszgen-validation

Conversation

@syjn99

@syjn99 syjn99 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member
  • Add sszgen/testutil/genfixture: committed generator output that tests compile and run, pinned by TestGenFixture.
  • Reject nonzero padding bits of Bitvector2/Bitvector4 when decoding and encoding (ssz.ValidateBitvector, ssz.ErrBitvectorPadding).
  • Bitlist encoder checks the limit in bits and the delimiter bit with ssz.ValidateBitlist (now wraps ErrListTooBig), as the decoder does.
  • Decoder bounds []byte lists by ssz-max, also progressive ones that set ssz-max (as for other lists since prysm#17412).
  • Remove the unreachable off > size check after the first-offset check.

Prysm develop regenerated with this branch: patch

🤖 Generated with Claude Code

There is no test that compiles or runs a generated code in methodical-ssz. This commit adds a new package called `genfixture` for testing, which will be a groundwork for the later bug fixes.
For Bitvector[N] with N%8 != 0, the spec requires the unused high bits
of the last byte to be zero. The generated decoder accepted 0x10 as a
Bitvector4, and the encoder encoded such a value.

Add `ssz.ValidateBitvector` and `ssz.ErrBitvectorPadding`, and call the
check from the generated decoder and encoder for `go-bitfield` `Bitvector2`
and `Bitvector4`. `Bitvector2` was not supported before and is now.

Now the length check for bitvectors in the encoder (`MarshalSSZTo`) is replaced to new validation function.
The Bitlist encoder compared the byte length with ssz-max, which is a
limit in bits. With ssz-max:"2048" it encoded 258 to 2048 bytes, and
the decoder of the same type rejected the output. It also encoded an
empty slice and a last byte of 0, which have no delimiter bit.

The encoder now calls ssz.ValidateBitlist. A progressive bitlist calls
ssz.ValidateProgressiveBitlist, because the spec type has no limit.

ssz.ValidateBitlist now wraps ssz.ErrListTooBig when the bitlist is
longer than its limit. The old encoder check returned ErrListTooBig, so
callers that match it keep working.
The container decoder checks that the first offset equals the fixed
size, and UnmarshalSSZ already returns ErrSize when the input is
shorter than the fixed size. So the next `off > size` check can never
fail. Remove it. Behavior does not change.
The generated decoder copied a []byte list with ssz-max without a
length check. For example, it decoded an ExecutionPayloadDeneb with 33
bytes of ExtraData (List[byte, 32]). The spec rejects this, and the
generated encoder and HashTreeRoot of the same type already reject it.

The decoder now returns ErrListTooBig, as for other lists. Progressive
byte lists with ssz-max get the same check, as other progressive lists
do. Bitlists do not change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant