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

fix: ignore extra data in discv4 messages #110

Merged
merged 7 commits into from
Jul 3, 2024

Conversation

MegaRedHand
Copy link
Collaborator

@MegaRedHand MegaRedHand commented Jul 2, 2024

Motivation

According to the spec:

Implementations should ignore any additional elements in the packet-data list as well as any extra data after the list.

We're currently failing if any of that happens.

Description

This PR introduces Decoder::finish_unchecked, which ignores any trailing bytes instead of failing, and uses that to allow for additional elements inside the packet-data. Also, it replaces some usage of RLPDecode::decode with RLPDecode::decode_unfinished to allow for extra data after the message.

As an extra, it refactors out the big match inside of both Message encode and decode functions, since it's expected those will change often in the next PRs.

Related to #17

@MegaRedHand MegaRedHand self-assigned this Jul 2, 2024
@MegaRedHand MegaRedHand requested a review from a team as a code owner July 2, 2024 16:23
@MegaRedHand MegaRedHand merged commit eaeb9ce into main Jul 3, 2024
3 checks passed
@MegaRedHand MegaRedHand deleted the decoder-finish_ignore_trailing branch July 3, 2024 12:08
mpaulucci pushed a commit to mpaulucci/lambda_ethereum_rust that referenced this pull request Oct 16, 2024
**Motivation**

According to the spec:
> Implementations should ignore any additional elements in the
`packet-data` list as well as any extra data after the list.

We're currently failing if any of that happens.

**Description**

This PR introduces `Decoder::finish_unchecked`, which ignores any
trailing bytes instead of failing, and uses that to allow for additional
elements inside the packet-data. Also, it replaces some usage of
`RLPDecode::decode` with `RLPDecode::decode_unfinished` to allow for
extra data after the message.

As an extra, it refactors out the big `match` inside of both `Message`
encode and decode functions, since it's expected those will change often
in the next PRs.

Related to lambdaclass#17
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

Successfully merging this pull request may close these issues.

2 participants