Skip to content

SNIP-12 Incorrect encoding for empty enum variant #1341

@sgc-code

Description

@sgc-code

Describe the bug
Regarding SNIP-12.
Incorrect encoding for enum with no args

let consider an enum like this:

"Fee Mode": [
    { name: "No Fee", type: "()" },
    { name: "Pay Fee", type: "(uint128)" },
],

when trying to encode the first variant:
{ "No Fee": [] }

sn.js will calculate it like:
hashMethod([variantIndex, 0])

but it should be
hashMethod([typeHash, variantIndex])

there are two bugs in this example:

  • first it's missing the typehash but that was already fixed in fix: correct enum typed data hashing #1281
  • the seconded issue is the extra 0 at the end. this is the bug i want to report here and i happens only when the enum variant has no arguments

To Reproduce
Steps to reproduce the behavior:

Try to encode a type with an enum like this one

"Fee Mode": [
    { name: "No Fee", type: "()" },
    { name: "Pay Fee", type: "(uint128)" },
],

Expected behavior
Encoding should follow the spec and add no extra 0

Screenshots

Desktop (please complete the following information):

  • Node version: 18
  • Starknet.js version: v6.23.1 (latest)

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions