Skip to content

[Flow EVM] Implement ABI encoding/decoding for arrays of Solidity tuples#8371

Merged
m-Peter merged 2 commits intomasterfrom
mpeter/abi-encode-tuple-arrays
Feb 6, 2026
Merged

[Flow EVM] Implement ABI encoding/decoding for arrays of Solidity tuples#8371
m-Peter merged 2 commits intomasterfrom
mpeter/abi-encode-tuple-arrays

Conversation

@m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Jan 29, 2026

Closes: #8370
Related: onflow/FlowYieldVaultsEVM#40

Summary by CodeRabbit

  • New Features

    • Support for encoding and decoding Cadence structs as EVM-compatible tuples in ABI operations, including proper handling of struct arrays for correct roundtrip conversion.
  • Tests

    • Added test coverage validating ABI encoding and decoding of arrays of structs, ensuring roundtrip fidelity.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

Added context-aware type resolution and tuple-detection to ABI encoding/decoding, enabling Cadence struct arrays to be encoded/decoded as Solidity tuples by plumbing context through goType and adjusting array element handling for tuple-encodable composites.

Changes

Cohort / File(s) Summary
ABI encoding core
fvm/evm/impl/abi.go
Added context parameter to goType; perform geth ABI lookup and return tuple types for tuple-encodable composites; propagate context through recursive calls; detect isTuple for composite element types and adjust array element encoding (pointer indirection when tuple-backed).
Tests
fvm/evm/stdlib/contract_test.go
Added two test blocks asserting ABI encode/decode roundtrip for arrays of structs mapped to Solidity tuple types, verifying element values and gas gauge totals.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Input: Cadence Array
    participant Encoder as ABI Encoder
    participant TypeResolver as goType (with context)
    participant ElementHandler as Element Encoder
    participant Output as EVM Bytes

    Client->>Encoder: encodeABI([struct1, struct2,...])
    Encoder->>TypeResolver: goType(context, arrayElementType, evmTypeIDs)
    TypeResolver->>TypeResolver: resolve basic type / geth ABI type
    TypeResolver-->>Encoder: reflect.Type (+ isTuple flag if tuple-encodable)
    Encoder->>ElementHandler: iterate elements
    ElementHandler->>ElementHandler: if isTuple => indirect pointer if needed
    ElementHandler-->>Encoder: prepared element values
    Encoder->>Output: pack elements as tuple-encoded ABI
    Output-->>Client: return encoded bytes
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • janezpodhostnik
  • holyfuchs
  • fxamacker

Poem

🐰 I hopped through types with a curious stare,
Context in paw and tuples to share,
Arrays of structs now snug in a row,
Encoded as tuples — off they go! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: implementing ABI encoding/decoding for arrays of Solidity tuples, which matches the pull request objectives.
Linked Issues check ✅ Passed The code changes successfully implement ABI encoding/decoding for arrays of Solidity tuples as required by issue #8370, with context parameter propagation and tuple-aware array handling.
Out of Scope Changes check ✅ Passed All changes are directly related to the objective of enabling ABI encoding/decoding for arrays of Solidity tuples; no out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mpeter/abi-encode-tuple-arrays

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 29, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@codecov-commenter
Copy link

codecov-commenter commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 0% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
fvm/evm/impl/abi.go 0.00% 18 Missing ⚠️

📢 Thoughts on this report? Let us know!

@m-Peter m-Peter force-pushed the mpeter/abi-encode-tuple-arrays branch from 8dd3fb0 to 9846bf6 Compare January 30, 2026 10:18
@m-Peter m-Peter marked this pull request as ready for review January 30, 2026 10:19
@m-Peter m-Peter requested a review from a team as a code owner January 30, 2026 10:19
// - `EVM.EVMBytes4`
// - `EVM.EVMBytes32`
semaType := interpreter.MustConvertStaticToSemaType(staticType, context)
if compositeType := asTupleEncodableCompositeType(semaType); compositeType != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case where compositeType != nil , we are not making use of the compositeType, instead, we are reading from the staticType and context all over again.

I feel we might be able to get rid of this check, just rely on gethABIType to return ok, and check if ok == true, for when the type is a tuple. In other words, if compositeType != nil, then ok must be true, and if it's false, then it should be a fatal error, no?

Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea @zhangchiqing 🚀 gethABIType already makes the necessary check by calling asTupleEncodableCompositeType, so no need to do it here again. This also has the advantage that we can perform this check without caring about the special/reserved Cadence structs defined on the EVM system contract.

Updated in 4ccde5a .

@m-Peter m-Peter force-pushed the mpeter/abi-encode-tuple-arrays branch from 9846bf6 to 4ccde5a Compare February 6, 2026 14:56
@m-Peter m-Peter requested a review from zhangchiqing February 6, 2026 16:41
Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@m-Peter m-Peter added this pull request to the merge queue Feb 6, 2026
Merged via the queue into master with commit 9555201 Feb 6, 2026
61 checks passed
@m-Peter m-Peter deleted the mpeter/abi-encode-tuple-arrays branch February 6, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Flow EVM] Implement ABI encoding/decoding for arrays of Solidity tuples

4 participants