[Flow EVM] Implement ABI encoding/decoding for arrays of Solidity tuples#8371
[Flow EVM] Implement ABI encoding/decoding for arrays of Solidity tuples#8371
Conversation
📝 WalkthroughWalkthroughAdded 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
8dd3fb0 to
9846bf6
Compare
fvm/evm/impl/abi.go
Outdated
| // - `EVM.EVMBytes4` | ||
| // - `EVM.EVMBytes32` | ||
| semaType := interpreter.MustConvertStaticToSemaType(staticType, context) | ||
| if compositeType := asTupleEncodableCompositeType(semaType); compositeType != nil { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 .
9846bf6 to
4ccde5a
Compare
Closes: #8370
Related: onflow/FlowYieldVaultsEVM#40
Summary by CodeRabbit
New Features
Tests