Skip to content

Replace COA.call with COA.callWithSigAndArgs for reduced computation cost#77

Draft
m-Peter wants to merge 1 commit intomainfrom
mpeter/optimize-evm-call-usage
Draft

Replace COA.call with COA.callWithSigAndArgs for reduced computation cost#77
m-Peter wants to merge 1 commit intomainfrom
mpeter/optimize-evm-call-usage

Conversation

@m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Mar 20, 2026

Related: onflow/flow-go#8401
Closes: #76

Description

Previously, to perform contract calls using a COA, it was necessary to produce the callData on Cadence side:

let calldata = EVM.encodeABIWithSignature(signature, args)

To be able to ABI-decode the returned data from the COA call, another step was needed:

let decoded = EVM.decodeABI(types: [Type<[UInt256]>()], data: res.data)
let amountsOut = decoded[0] as! [UInt256]

After doing some profiling on Cadence transactions, the computation cost of ABI encoding/decoding, amounted to about 15%-20% of the total computation, which is not trivial.

To optimize this case, we have a new wrapper function, callWithSigAndArgs, which does all this more efficiently:

coa.callWithSigAndArgs(
    to: to,
    signature: "approve(address,uint256)",
    args: [self.routerAddress, evmAmountIn],
    gasLimit: gasLimit,
    value: valueBalance.attoflow,
    resultTypes: [Type<[UInt256]>()]
)

We do the same for dryCall, by replacing it with dryCallWithSigAndArgs .

NOTE: CI is failing because we still need to deploy the EVM system contract on testnet/mainnet, for these new functions to be available.

@m-Peter m-Peter self-assigned this Mar 20, 2026
@m-Peter m-Peter force-pushed the mpeter/optimize-evm-call-usage branch from ae6fa70 to 12290b2 Compare March 20, 2026 11:54
@m-Peter m-Peter force-pushed the mpeter/optimize-evm-call-usage branch from 12290b2 to 85dc5f3 Compare March 20, 2026 12:09
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.

[Optimization] Replace call & dryCall with their optimized versions

1 participant