onflow / developer-grants

Grants for developers that contribute to the broader developer ecosystem
Apache License 2.0
50 stars 18 forks source link

Flow <-> EVM Interoperability #241

Closed m-Peter closed 10 months ago

m-Peter commented 11 months ago

ABI encoding/decoding functionality for Cadence

Grant category

Please select one:

Description

The Axelar cross-chain integration work needs the Ethereum ABI.encode() and ABI.decode() functionality made available, ideally as a native Cadence language function owing to the difficulty of implementing the same logic directly in Cadence code due to the byte level handling. This need will doubtless also arise for other aspects of EVM integration in future since ABIs are very common.

Problem statement

ABI (Application Binary Interface) is the standard for interacting with Ethereum smart contracts. Data is encoded based on its type, and because the encoded result doesn't contain type information, it is necessary to indicate their types when decoding.

Proposed solution

Introduce two natively-implemented methods on the EVM contract, for ABI encoding/decoding:

A sample usage of the two above functions can be seen below:

// Encode & decode `String`, `UInt64` and `Bool`
var data = EVM.encodeABI(["John Doe", UInt64(33), false])
let types = [Type<String>(), Type<UInt64>(), Type<Bool>()]
var values = EVM.decodeABI(types, data: data)

// Assert the decoded values 
assert(values.length == 3)
assert((values[0] as! String) == "John Doe")
assert((values[1] as! UInt64) == UInt64(33))
assert((values[2] as! Bool) == false)

We make use of Cadence type-system, and map each supported type to its Solidity counterpart.

Impact

These functions would allow developers to create data packages that would be portable between Flow and EVM as well as generate EVM function calls/signatures on Flow.

Milestones and funding

Milestone Deliverables Timeline Risks USD proposal
1 - Functions Implementation Merge https://github.com/onflow/flow-go/pull/5024 3 weeks - 4500 $
1 - Metering Properly meter the computation of these 2 functions, based on the encoded/decoded payload 2 weeks - 2500 $

Total funding proposed: 7000 $

Team

Name Role Bio Contact
Ardit Marku Back-end Engineer A seasoned back-end engineer with a focus on problem solving and designing robust software systems. Over 9 years of experience building high-traffic search engines, marketplaces, exchanges and in-house analytics solutions. Led cross-functional teams to deliver both web and mobile apps, participating in all steps of the software development lifecycle. Open source lover and advocate. markoupetr@gmail.com m_peter
m-Peter commented 11 months ago

@franklywatson Both milestones of this grant have been completed:

Could you please review the completion? If it is accepted, we can close this :pray: