fix: truncate every shred to canonical size in duplicate detection - #102
Open
latent-9 wants to merge 1 commit into
Open
fix: truncate every shred to canonical size in duplicate detection#102latent-9 wants to merge 1 commit into
latent-9 wants to merge 1 commit into
Conversation
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
get_payloadinsideis_shred_duplicateonly truncates resigned shreds to their canonical size. A non-resigned shred padded with extra trailing bytes therefore compares unequal to its unpadded twin and is treated as a duplicate, so aDuplicateBlockProofbuilt from one genuinely signed shred and a padded copy of it records a violation against a leader that never equivocated.Why
Shred::new_from_payloaddoes not truncate the payload to the canonical shred size, andget_payloadreturns the full payload for non-resigned shreds:merkle_root()and the header getters read fixed offsets, so trailing bytes past the canonical size are ignored: a padded copy keeps the same merkle root, the same valid leader signature, and the same slot, index, and shred type. The only differenceis_shred_duplicateobserves is the byte length, socheck_shredsreturnsOk(())and stores a violation for a leader that did not equivocate.Upstream agave truncates every merkle shred to its canonical size at construction (
ledger/src/shred/merkle.rs,payload.truncate(Self::SIZE_OF_PAYLOAD)), which is why itsis_shred_duplicateis safe with the same non-resigned branch.Change
Always truncate to
proof_offset + proof_sizeinget_payload. For a non-resigned shred this equals the canonical size, so it strips only the trailing padding and never drops a real payload difference. Resigned shreds are unaffected, since their retransmitter signature still sits pastproof_offset + proof_size.Test
test_non_canonical_padding_payload_proof_invalidbuilds a non-resigned data shred and a non-resigned coding shred, pads each payload with one trailing byte, and asserts the proof is rejected withInvalidPayloadProof. It fails before the change (the padded shred is accepted as a duplicate) and passes after, and the existing tests continue to pass.Fixes #101