feat(codec): add Zeroed type - #4484
Open
ygd58 wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4b3319a. Configure here.
Author
|
Addressed all 3 Bugbot findings in the follow-up commit:
Verified on a real toolchain (rustc >= 1.95, which I don't have access to directly): |
Adds Zeroed, a wrapper representing exactly n zero bytes. Useful for padding or reserving space in an encoding, and doubles as an assertion that a reserved region was actually left untouched: decoding rejects any input where one of the n bytes is non-zero. n is not stored on the wire; the reader supplies it externally via Read::Cfg = usize, the same way a fixed-length array's length is part of its type rather than its encoding. Implements Write/EncodeSize/Read following the same shape as Bytes (codec/src/types/bytes.rs), minus the length prefix (n comes from Cfg here rather than being self-describing). write() uses BufMut::put_bytes rather than allocating a temporary zero buffer. Adds unit tests for round-tripping, rejecting a non-zero byte, rejecting a short buffer, and is_empty(). Also adds the arbitrary-gated conformance test block following the same pattern as Bytes's, but I could not generate the actual conformance.toml baseline entry myself — that requires running `just regenerate-conformance -p commonware-codec`, which needs a real build (this workspace requires rustc >= 1.95, which I don't have in my environment). Whoever picks this up for review will need to run that before the conformance suite passes. Closes commonwarexyz#1703
Generated via: RUSTFLAGS="--cfg generate_conformance_tests" just regenerate-conformance -p commonware-codec Verified: just test -p commonware-codec zeroed -> 46 passed, 0 failed
- read_cfg: use the existing util::ensure_zeros helper (chunk-at-a-time, no allocation) instead of copying into a Vec and scanning it — duplicated logic Bugbot flagged as already covered by that helper. - EncodeSize: override encode_inline_size to return 0. write_bufs pushes the zero region as a separate Bytes chunk via BufsMut::push rather than writing it inline, so the inline buffer shouldn't also reserve n bytes for it — previously it did, plus the separate n-byte push allocation, double-reserving memory on the pooled encode path. - Add test_zeroed_write_bufs_matches_write, asserting write_bufs output is byte-identical to write via the existing TrackingWriteBuf test double (types/mod.rs), following the project's learned rule that write_bufs overrides need a wire-format equivalence test. Addresses all 3 findings from Cursor Bugbot's review of 4b3319a. write() itself is unchanged, so the conformance.toml baseline from the prior commit still applies — no regeneration needed.
ygd58
force-pushed
the
feat/codec-zeroed-type
branch
from
August 23, 2026 14:35
26f2768 to
a33c7d5
Compare
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.

What
Adds
Zeroed, a wrapper representing exactlynzero bytes — closes #1703.Useful for padding or reserving space in an encoding, and doubles as an assertion that a reserved region was actually left untouched: decoding rejects any input where one of the
nbytes is non-zero.nis not stored on the wire; the reader supplies it externally viaRead::Cfg = usize, the same way a fixed-length array's length is part of its type rather than its encoding.Implementation
Implements
Write/EncodeSize/Readfollowing the same shape asBytes(codec/src/types/bytes.rs), minus the length prefix (ncomes fromCfghere rather than being self-describing).write()usesBufMut::put_bytesrather than allocating a temporary zero buffer.Testing
Unit tests for round-tripping (n = 0, 1, 8, 300), rejecting a non-zero byte, rejecting a short buffer, and
is_empty().Added the
arbitrary-gated conformance test block following theBytespattern, and generated the baseline:Both commits included — the type itself, and the generated conformance baseline as a separate commit so the hash's provenance is clear.
Closes #1703