Skip to content

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

Merged
nchamo merged 4 commits into
merge-train/fairiesfrom
nchamo/abi-return-type-single
Jul 31, 2026
Merged

nchamo merged 4 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
Comment thread yarn-project/stdlib/src/contract/artifact_hash.ts Outdated
Comment thread docs/docs-developers/docs/resources/migration_notes.md
Comment thread docs/docs-developers/docs/resources/migration_notes.md
@nchamo
nchamo enabled auto-merge (squash) July 31, 2026 23:12
@nchamo
nchamo merged commit 5a89c08 into merge-train/fairies Jul 31, 2026
12 checks passed
@nchamo
nchamo deleted the nchamo/abi-return-type-single branch July 31, 2026 23:38
rangozd pushed a commit to rangozd/aztec-packages that referenced this pull request Aug 5, 2026
BEGIN_COMMIT_OVERRIDE
fix(pxe): validate a BoundedVec against its storage array on
deserialization (AztecProtocol#25035)
chore: add disclaimers on poc contracts (AztecProtocol#24975)
chore: begin nr constant cleanup (AztecProtocol#25014)
fix(txe): authorize sync_state utility calls in inlined contexts
(AztecProtocol#25034)
refactor(stdlib): a function's return type is a single optional AbiType
(AztecProtocol#25066)
feat(pxe): hash-pinned node read cache (AztecProtocol#24969)
feat(noir-projects): publish compiled protocol artifacts to npm (AztecProtocol#25075)
fix(ci): trim GitHub commit API response in upload_benchmarks to avoid
E2BIG on large merge commits (AztecProtocol#25077)
END_COMMIT_OVERRIDE
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.

2 participants