Skip to content

Encoding FixedBytes uses left-padding instead of right-padding #213

@2-towns

Description

@2-towns

The FixedBytes should be encoded by adding trailing zeros (so right padding).

The following test is currently failing:

test "keeps compatibility with FixedBytes":
  let bytes16 = FixedBytes[16](randomBytes[16]())
  check encode(bytes16) == @(bytes16.data) & 16.zeroes

  let bytes32 = FixedBytes[32](randomBytes[32]())
  check encode(bytes32) == @(bytes32.data)

  let bytes33 = FixedBytes[33](randomBytes[33]())
  check encode(bytes33) == @(bytes33.data) & 31.zeroes

The error is:

Check failed: encode(bytes16) == @(bytes16.data) & 16.zeroes
    encode(bytes16) was @[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 123, 248, 85, 22, 17, 155, 159, 163, 175, 32, 209, 119, 44, 3, 33]
    @(bytes16.data) & 16.zeroes was @[22, 123, 248, 85, 22, 17, 155, 159, 163, 175, 32, 209, 119, 44, 3, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

So the current encoding for FixedBytes is using left padding, but it should be using right padding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions