Represent membership separately from zero in a Cairo storage map

Reading a never-written key from a map of unsigned amounts gives the default zero value. An application using zero as proof of absence cannot distinguish a registered account whose balance was spent.

Reproduce the ambiguous read

In a test contract, register A, credit it, then spend its balance completely. Leave B untouched. Read the mapping through its storage access methods. Both accounts now yield zero in the illustrated amount map.

credits[A] = 0  // registered account, no credit
credits[B] = 0  // address never registered

If registration matters independently of funds, store an explicit membership flag or a storage representation with a distinguishable empty case. Update registration and amount consistently on every path that creates or closes an account.

Plan enumeration separately

A storage Map does not maintain an iterable list of all keys. If an application needs to enumerate registered accounts, maintain a suitable index or derive candidates from contract events and verify current membership. An amount read alone cannot reconstruct the set. starknet.io The Cairo Programming Language