Skip to content

refactor(stdlib): a function's return type is a single optional AbiType - #25066

Open
nchamo wants to merge 3 commits into
merge-train/fairiesfrom
nchamo/abi-return-type-single
Open

refactor(stdlib): a function's return type is a single optional AbiType#25066
nchamo wants to merge 3 commits into
merge-train/fairiesfrom
nchamo/abi-return-type-single

Conversation

@nchamo

@nchamo nchamo commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Why we are doing this

FunctionAbi.returnTypes is an AbiType[], but it can only ever hold zero or one entry: Noir emits
return_type: AbiType | null, and a function returning several values expresses them as a single tuple type. The list
shape invites callers to handle a case that cannot occur, and every consumer that wants the return type has to reach
for index 0 and decide what an empty list means.

Our fix

FunctionAbi gains a single optional returnType, and returnTypes stays as a deprecated field written alongside it,
so artifacts and RPC payloads serialized before this change still resolve. Both are read through
getFunctionReturnType, which prefers the singular field and falls back to the deprecated list. Reading a list with
more than one entry throws rather than silently dropping the extra entries, since the value feeds contract class ids.

computeFunctionMetadataHash keeps hashing the type as a one-element list. That preimage is what contract class ids and
therefore deployed addresses are derived from, so its shape is frozen regardless of how the field is stored; the
standard-contract address pins confirm nothing moved.

FunctionCall gets the same treatment on the wire: returnType is the field, returnTypes is accepted on parse and
emitted on serialization for peers that still require it.

Decoding is split by role, which the old single entry point conflated:

  • decodeFromAbi takes the one type a function returns (or undefined) and returns one decoded value. A function that
    returns nothing now decodes to undefined where it previously produced [].
  • decodeEachFromAbi takes a list of types and returns one decoded value per type, which is how a function's arguments
    are encoded. It always returns a list, fixing a latent bug where a single-argument function decoded to a bare value
    and callers indexing [0] got undefined.

Fixes #25040

@nchamo nchamo self-assigned this Jul 30, 2026
@nchamo nchamo added ci-draft Run CI on draft PRs. ci-no-fail-fast Sets NO_FAIL_FAST in the CI so the run is not aborted on the first failure labels Jul 30, 2026
@nchamo nchamo changed the title refactor(stdlib)!: a function's return type is a single optional AbiType refactor(stdlib): a function's return type is a single optional AbiType Jul 30, 2026
@nchamo
nchamo marked this pull request as ready for review July 30, 2026 18:33
@nchamo
nchamo requested a review from nventuro July 30, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-draft Run CI on draft PRs. ci-no-fail-fast Sets NO_FAIL_FAST in the CI so the run is not aborted on the first failure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant