Repository navigation
Conversation
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.
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.
sszgen/testutil/genfixture: committed generator output that tests compile and run, pinned byTestGenFixture.Bitvector2/Bitvector4when decoding and encoding (ssz.ValidateBitvector,ssz.ErrBitvectorPadding).ssz.ValidateBitlist(now wrapsErrListTooBig), as the decoder does.[]bytelists byssz-max, also progressive ones that setssz-max(as for other lists since prysm#17412).off > sizecheck after the first-offset check.Prysm
developregenerated with this branch: patch🤖 Generated with Claude Code