-
Notifications
You must be signed in to change notification settings - Fork 176
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
[Flow EVM] Add support for ABI
encoding/decoding of Solidity byte
types
#6553
base: master
Are you sure you want to change the base?
[Flow EVM] Add support for ABI
encoding/decoding of Solidity byte
types
#6553
Conversation
caf56eb
to
d004ec5
Compare
ABI
encoding/decoding support for Solidity byte
typesABI
encoding/decoding of Solidity byte
types
ABI
encoding/decoding of Solidity byte
typesABI
encoding/decoding of Solidity byte
types
Great work adding support for more types! I had a look at the documentation at https://docs.soliditylang.org/en/latest/types.html#fixed-size-byte-arrays, and from what I understood, the Solidity Why do we need the "wrapper types", like |
@turbolent Let me explain this with a working example, to illustrate the differences: let bytes4 = '0x050a0f14' // these are the values 5, 10, 15, 20 in hex
let abiEncoded = web3.eth.abi.encodeParameter('bytes4', bytes4)
assert.equal(
abiEncoded,
'0x050a0f1400000000000000000000000000000000000000000000000000000000'
)
let uint8four = [5, 10, 15, 20] // this is the same value as `bytes4` variable above
abiEncoded = web3.eth.abi.encodeParameter('uint8[4]', uint8four)
assert.equal(
abiEncoded,
'0x0000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000f0000000000000000000000000000000000000000000000000000000000000014'
)
let bytes = '0x050a0f14'
abiEncoded = web3.eth.abi.encodeParameter('bytes', bytes)
assert.equal(
abiEncoded,
'0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004050a0f1400000000000000000000000000000000000000000000000000000000'
) The Solidity Right now, we have mapped the Cadence dynamic-sized & fixed-sized arrays, to Solidity arrays:
Which means that we need to somehow control the ABI encoding/decoding of Solidity
These are the most commonly used Solidity |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6553 +/- ##
==========================================
+ Coverage 41.28% 41.33% +0.05%
==========================================
Files 2031 2031
Lines 145883 146072 +189
==========================================
+ Hits 60222 60385 +163
- Misses 79442 79461 +19
- Partials 6219 6226 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Thank you for the explanation, it makes sense now! Initially I assumed that the byte types were just aliases, but I understand now that they are independent types, to allow for more compact encoding. Ideally we would probably like to have a type like The code looks good, and adding support for the common types makes sense. Maybe we can consider generating the code for all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
As the EVM contract change, the state commitments need to be updated as well. You can just use the new reported values as the expected values. |
0f7e0b1
to
f067110
Compare
Updated in f067110 |
Out of curiosity, can we do something like |
That would be nice, and the ideal solution. However, Cadence does not support generic types defined in Cadence programs yet, and further, it only supports generic parameters which are types at the moment, there is no support for generic parameters like numeric constants yet (see e.g. "const generics" in Rust) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! 👏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Closes: #5365
Support
ABI
encoding/decoding the following Soliditybyte
types:bytes
&bytes[]
bytes4
&bytes4[]
bytes32
&bytes32[]
Note: A contract upgrade for
EVM
system contract is needed.The test payloads have been generated with the help of: https://abi.hashex.org/