Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong variable (blob) used instead of bin in buffer re-encode mismatch error #28

Open
KindKillerwhale opened this issue Jan 12, 2025 · 0 comments

Comments

@KindKillerwhale
Copy link

Description

There's a minor but confusing bug in the ssz/tests/consensus_specs_test.go:fuzzConsensusSpecType function line:835. Specifically, in the buffer leftover path, we store the re-encoded bytes in a variable named bin, but the error message references a variable named blob (used in the stream leftover path). This leads to incorrect or misleading data being shown in the error logs.

Reference

File: tests/consensus_specs_test.go

bin := make([]byte, ssz.SizeOnFork(obj, ssz.ForkFuture))
if err := ssz.EncodeToBytesOnFork(bin, obj, ssz.ForkFuture); err != nil {
    t.Fatalf("failed to re-encode buffer from used object: %v", err)
}
if !bytes.Equal(bin, inSSZ) {
    prefix := commonPrefix(bin, inSSZ)
    t.Fatalf("re-encoded buffer from used object mismatch: have %x, want %x, common prefix %d, have left %x, want left %x",
        blob, inSSZ, len(prefix), bin[len(prefix):], inSSZ[len(prefix):])
}

Suggested Fix

Simply replace blob with bin in that error message. Here's a minimal patch:

 if !bytes.Equal(bin, inSSZ) {
     prefix := commonPrefix(bin, inSSZ)
    t.Fatalf("re-encoded buffer from used object mismatch: have %x, want %x, common prefix %d, have left %x, want left %x",
-        blob, inSSZ, len(prefix), bin[len(prefix):], inSSZ[len(prefix):])
+        bin, inSSZ, len(prefix), bin[len(prefix):], inSSZ[len(prefix):])
 }

This ensures the error message accurately shows the content of bin (the actual buffer re-encode), instead of the variable from the stream leftover path.

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

No branches or pull requests

1 participant