Skip to content

Add SCSpecTypeUDTV2 with a type id - #310

Closed
leighmcculloch wants to merge 2 commits into
mainfrom
scspec-udt-v2-id-field-9jgp9b
Closed

Add SCSpecTypeUDTV2 with a type id#310
leighmcculloch wants to merge 2 commits into
mainfrom
scspec-udt-v2-id-field-9jgp9b

Conversation

@leighmcculloch

@leighmcculloch leighmcculloch commented Jul 29, 2026

Copy link
Copy Markdown
Member

Warning

Root of a stack of PRs that thread this field through the Rust libraries and the SDK. A valid merge order:

  1. this PR
  2. Add borrowed Ref variants of generated types rs-stellar-xdr#560 — borrowed Ref variants of the generated types
  3. Add const XDR serialization on Ref types rs-stellar-xdr#562 — const XDR serialization on those Ref types
  4. Regenerate with SCSpecTypeUDTV2 rs-stellar-xdr#564 — regenerate with SCSpecTypeUDTV2
  5. Bump stellar-xdr for SCSpecTypeUDTV2 rs-soroban-env#1714 — re-pin to that regeneration
  6. Encode contract spec XDR at const evaluation time rs-soroban-sdk#1965 — encode contract spec XDR at const evaluation time
  7. Reference user-defined types by id rs-soroban-sdk#1966 — reference user-defined types by id

What

Add SCSpecTypeUDTV2, a second form of user-defined type reference that identifies the type it references solely by an 8-byte opaque id, and a SC_SPEC_TYPE_UDT_V2 arm on SCSpecTypeDef holding it. The id is opaque here; how it is derived is left to the spec producer, and the Rust SDK derives it from the referenced type's own definition.

A reference carries no name. The name of a user-defined type lives on the definition entry the id identifies, so a consumer that wants the name resolves the id against the definitions in the same spec.

Why

A SCSpecTypeUDT reference carries only a name, so a name is the only thing tying a reference to the definition it refers to. That is too weak to check anything against: names collide across libraries, and a definition whose shape changes while its name stays the same is indistinguishable from one that did not, so a consumer cannot tell whether the UdtStruct a function accepts is the UdtStruct it holds a definition for. Carrying an id that identifies the referenced type by content makes the link verifiable, and makes it well-defined for types that reference each other or themselves.

Carrying the id instead of the name, rather than alongside it, keeps one thing identifying the referenced type instead of two that can disagree — there is no way to express a reference whose name says one type and whose id says another. Adding a variant rather than a field on SCSpecTypeUDT keeps every existing spec readable unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant