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 encoding for branch and extension for inlined data. #391

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

damian-orzechowski
Copy link
Contributor

Fix RLP encoding for small inlined data:

  • Branch - when slicing target span to write correct sequence length, the target position is leaving extra 0 byte for content length < 56
  • Extension - should write child's Keccak or Rlp - contentLength already takes that into account

Copy link
Contributor

@Scooletz Scooletz left a comment

Choose a reason for hiding this comment

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

One change request. The fix itself: 👍

@@ -649,7 +649,9 @@ private void EncodeBranch(scoped in Key key, scoped in ComputeContext ctx, scope
// Write length of length in front of the payload, resetting the stream properly
var end = stream.Position;
var actualLength = end - initialShift;
var lengthOfLength = Rlp.LengthOfLength(actualLength) + 1;
var lengthOfLength = Rlp.LengthOfLength(actualLength);
if (actualLength >= 56) //to match StartSequence
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have it extracted as a const under Rlp maybe? Then both Rlp.LengthOfLength and this place could refer to it properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added constant in Rlp

@@ -692,7 +694,10 @@ private void EncodeExtension(scoped in Key key, scoped in ComputeContext ctx, sc
RlpStream stream = new(pooled.Span.Slice(slice, totalLength));
stream.StartSequence(contentLength);
stream.Encode(span);
stream.Encode(keccakOrRlp.Keccak);
if (keccakOrRlp.DataType == KeccakOrRlp.Type.Rlp)
Copy link
Contributor

Choose a reason for hiding this comment

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

Clearly, after following the test, this check was missing.

Copy link

Code Coverage

Package Line Rate Branch Rate Health
Paprika 85% 80%
Summary 85% (4500 / 5305) 80% (1402 / 1761)

Minimum allowed line rate is 75%

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