02Sheet 02.03.020 · Entries

Map keys that collide

A contract stores and emits a map with five distinct keys that all read as "1" once converted to a native object. A lossy reader keeps one.

FIG. · Where it sits · inside LedgerCloseMetaCAP-0046 · H-B2
ContractDataEntry.val
ContractEvent.body.data
SorobanTransactionMeta.returnValue

The shape

An ScMap may hold keys of different types that print the same: u32 1, i32 1, u64 1, the string "1" and the symbol "1" are five distinct, correctly ordered keys on chain. Converting the map to a native object keyed by text collapses them. js-stellar-sdk's scValToNative silently kept one of them (#1789). This entry is real stellar-core output: a contract wrote the map to storage, returned it and emitted it in an event.

The five keys are u32 1, i32 1, u64 1, the string "1" and the symbol 1. Each maps to a different value (10, 20, 30, 40, 50), so a conversion that drops entries is easy to detect.

Variants

VariantProtocolNetworkSourceSizesha256
p30-mainnet-generatedP30mainnet passphrasegenerated by stellar-core v30.0.02,972 B744986731d97…
p28-mainnet-generatedP28mainnet passphrasegenerated by stellar-core v30.0.02,964 B6d54aaf35a75…
p30-testnet-generatedP30testnet passphrasegenerated by stellar-core v30.0.02,972 Ba70bc215e806…
p28-testnet-generatedP28testnet passphrasegenerated by stellar-core v30.0.02,964 B46fed2036c0f…

What a correct reader returns

This entry has an SDK check (1 of 201 entries do). It is a rule for the SDK's own helper, not a value: keep all five entries, or refuse the map. Never return fewer.

Not run yet

The schema says SDK checks belong to the conformance runner, but no tool runs them yet. Today the runner uses its own vectors, below.
A correct reader findsValueBacked by
The contract wrote a persistent entry keyed collide whose value is a 5-entry map with keys u32 1, i32 1, u64 1, string "1", symbol "1" (in core's order).some change where 7 fields matchconstructionsnapshotcorewalker
The event emitted by the call carries the same map with all 5 entries.length 5constructionsnapshot
The return value is the same 5-entry map.length 5constructionsnapshot
Each key maps to a different value (10, 20, 30, 40, 50), so a lossy conversion is detectable.50constructionsnapshotcorewalker
SDK checkMust
Native projection of the event's map keeps all five entries or rejects the map; it never silently drops one.return 5 entries, or raise an error; returning fewer than 5 is a failure (js-stellar-sdk#1789)

What it reproduces

js-stellar-sdk#1789

make conformance runs a vector with the same kind of collision (a two-entry map whose keys both read as "1") through js-stellar-sdk builds before and after the fix. The recorded matrix shows 17.2.0 and 17.2.1 keeping 1 of 2 entries, and 17.3.0 rejecting the map.

Check it yourself

make verify
make conformance

On this page