Count elements correctly in a Cairo array of enums

A Cairo array prefix counts logical elements, even when different enum variants occupy different numbers of felts. A decoder that counts the raw payload length will overrun the next argument.

Follow the ABI one variant at a time

The illustrative enum declares a unit variant at index zero and a u256 variant at index one. The first felt in the array is two. The next felt selects None and consumes no variant payload.

enum Choice { None, Amount: u256 }
[None, Amount(2^128)] → [2, 0, 1, 0, 1]

The next selector is one. Read two more felts for Amount, low zero and high one. At this point exactly two elements have been consumed. A following function argument starts after those five felts.

Use declaration order from the deployed ABI

Enum variant indices follow their declaration order. An added or reordered variant can change the interpretation of existing input if the consumer uses the wrong ABI. Reject unknown selectors or truncated payloads explicitly. starknet.io The Cairo Programming Language