Skip to content

fix: remove DecodeVanityData and return vanityData as raw hex#88

Merged
eomti-wm merged 2 commits into
devfrom
fix/vanity-data-decoding
Jun 24, 2026
Merged

fix: remove DecodeVanityData and return vanityData as raw hex#88
eomti-wm merged 2 commits into
devfrom
fix/vanity-data-decoding

Conversation

@eomti-wm

@eomti-wm eomti-wm commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Overview

Prevent potential runtime panics when decoding invalid block vanity data by enhancing error validation and type assertions.

Problem

When decoding a block's vanity data, accessing the resulting slice prior to verifying the decoding status causes an index out-of-range panic if the decoding fails. Additionally, performing type assertions on the decoded interfaces without validation causes interface conversion panics on malformed block data, leading to node instability.

Initial Approach — Superseded by Design Decision below

Solution

Ensure that decoding errors and slice lengths are validated immediately after decoding the bytes. Check the success of all subsequent type assertions before using the values.

Changes

  • Add error check and slice length validation right after decoding the vanity data
  • Validate type assertion success for all decoded fields to prevent runtime panics

Design Decision: Remove DecodeVanityData

While investigating the panic fixes above, a deeper structural issue was identified that led to a change in approach — removing DecodeVanityData entirely rather than applying defensive guards.

1. No protocol-enforced format
VanityData is an unconstrained 32-byte buffer. The protocol imposes no format requirement; validators can write arbitrary bytes. Defensively guarding against decode failures treats a symptom rather than the root cause.

2. Implicit cross-package coupling
DecodeVanityData hardcodes the RLP schema [uint, string, string, string] produced by eth package makeExtraData(). Any change to the encoding side in the eth package would silently break the decoding side in the wbft package with no compile-time signal.

3. No consensus role
The consensus engine never reads or validates VanityData content during block verification. The field serves purely as a 32-byte buffer for node metadata, with no functional impact on consensus.

Revised Changes

  • Remove DecodeVanityData
  • Return vanityData as a raw hex string in GetWbftExtraInfo, consistent with other byte fields (randaoReveal, seal signatures)

- Add error and slice length checks after RLP decoding to prevent
  out-of-range panic
- Validate type assertion results to prevent interface conversion
  panic
@eomti-wm eomti-wm self-assigned this Jun 15, 2026
@eomti-wm eomti-wm added the bug Something isn't working label Jun 15, 2026

@avinashkamat48 avinashkamat48 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guard logic now handles malformed RLP and wrong element types, but the PR does not appear to add a regression test for the panic cases it fixes. A small table test for DecodeVanityData with too-short lists and non-[]byte values in positions 0-3 would lock in the new fallback behavior and prevent a future refactor from reintroducing the same type assertion panic.

Comment thread consensus/wbft/backend/api.go Outdated
DecodeVanityData implicitly assumed the RLP schema produced by the eth
package, creating an unvalidated cross-package coupling with no
compile-time signal on schema changes. Additionally, VanityData has no
protocol-enforced format, making any decode assumption inherently
fragile and a source of potential runtime panics.

Remove DecodeVanityData and return vanityData as a raw hex string in
GetWbftExtraInfo, consistent with other byte fields.
@eomti-wm eomti-wm changed the title fix: prevent runtime panic in DecodeVanityData fix: remove DecodeVanityData and return vanityData as raw hex Jun 16, 2026
@eomti-wm

Copy link
Copy Markdown
Contributor Author

During the panic fix investigation, a structural issue was identified in DecodeVanityData that led to removing the function rather than patching it.

The function implicitly depends on the RLP schema defined in eth package makeExtraData(). This creates a hidden coupling between the eth and wbft packages — a change on the encoding side would silently break the decoding side with no compile-time signal.

Furthermore, VanityData has no protocol-enforced format. It is a free 32-byte buffer with no consensus-layer validation, making any format assumption inherently fragile.

Removing DecodeVanityData and returning raw hex eliminates both the cross-package coupling and the entire class of decode-related panics at the source.

@hominlee-wemade hominlee-wemade left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@colinkim colinkim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@0xmhha 0xmhha left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eomti-wm eomti-wm merged commit 57d52f7 into dev Jun 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants