Encode a Cairo u256 without swapping its limbs

A Starknet contract accepting a u256 receives two field elements. A single-element test with a small number may never expose a reversed limb order in an integration.

Exercise the first value above a limb boundary

Split the integer into its low 128 bits and its remaining high 128 bits. Serialize the low limb first. Decode the example back into a full integer by adding low to high multiplied by 2^128.

value = 2^128 + 42
low = 42
high = 1
calldata = [42, 1]

If a decoder instead treats the first element as the high limb, it reconstructs 42 times 2^128 plus one. Choose fixtures with different nonzero limbs and calculate using integers that preserve all 256 bits.

Apply the type’s range checks

Each limb must fit u128 even though the wire element is a felt. A generic felt parser can accept a larger value that the contract’s u256 deserializer rejects. Check both limbs before submitting calldata. starknet.io The Cairo Programming Language