Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the EVM.encodeABIWithSignature and EVM.decodeABIWithSignature functions #5189

Merged

Conversation

m-Peter
Copy link
Contributor

@m-Peter m-Peter commented Dec 30, 2023

These functions can be used to ABI encode/decode function calls, along with their arguments.

Example usage:

// bytes for address 0x7A58c0Be72BE218B41C608b7Fe7C5bB630736C71
let address = EVM.EVMAddress(
    bytes: [
        122, 88, 192, 190, 114, 190, 33, 139, 65, 198,
        8, 183, 254, 124, 91, 182, 48, 115, 108, 113
    ]
)

// ABI encode a function call with its arguments
let data = EVM.encodeABIWithSignature(
    "withdraw(address,uint256)",
    [address, UInt256(250)]
)

// ABI decode a function call with its arguments
// Note: We can probably infer the types with some string manipulation on the given signature
let values = EVM.decodeABIWithSignature(
    "withdraw(address,uint256)",
    types: [Type<EVM.EVMAddress>(), Type<UInt256>()],
    data: data
)

@m-Peter
Copy link
Contributor Author

m-Peter commented Jan 3, 2024

cc @turbolent @sisyphusSmiling I am not able to add you as reviewers.

Copy link
Contributor

@sisyphusSmiling sisyphusSmiling left a comment

Choose a reason for hiding this comment

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

Method interfaces & Cadence implementation LGTM!

@m-Peter m-Peter force-pushed the abi-encoding-decoding-function-call branch from 98117ae to 5279398 Compare January 4, 2024 12:53
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.

Looks good!

Implementing this in Cadence is nice, but also has a bit of an overhead compared to a native implementation in Go. For now this should not be a problem, but this might be worth optimizing in the future if needed.

@m-Peter
Copy link
Contributor Author

m-Peter commented Jan 4, 2024

Sounds good 👍 It shouldn't take much effort to implement them natively, if we decide to optimize things.

@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (de63803) 56.36% compared to head (0bcb7c9) 56.34%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5189      +/-   ##
==========================================
- Coverage   56.36%   56.34%   -0.02%     
==========================================
  Files         994      994              
  Lines       94848    94848              
==========================================
- Hits        53461    53443      -18     
- Misses      37416    37434      +18     
  Partials     3971     3971              
Flag Coverage Δ
unittests 56.34% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@turbolent
Copy link
Member

It seems like one of the tests fails, indicating the state commitment changes. I think this is because the EVM contract changed, and as it is deployed when bootstrapping, it influences the state commitment?

@ramtinms Can you please confirm?

@m-Peter
Copy link
Contributor Author

m-Peter commented Jan 9, 2024

Ah, I see, I wasn't aware of that. Good point 👍

@m-Peter m-Peter force-pushed the abi-encoding-decoding-function-call branch from 777e121 to 5279398 Compare January 9, 2024 18:06
…ctions

These functions can be used to ABI encode/decode function calls,
along with their arguments.
@m-Peter m-Peter force-pushed the abi-encoding-decoding-function-call branch from 5279398 to 0bcb7c9 Compare January 9, 2024 18:08
@franklywatson franklywatson added this pull request to the merge queue Jan 9, 2024
Merged via the queue into onflow:master with commit 205d50a Jan 9, 2024
51 checks passed
@m-Peter m-Peter deleted the abi-encoding-decoding-function-call branch January 10, 2024 09:15
This pull request was closed.
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.

5 participants