Add abi.decodeCall
reciprocal function of abi.encodeCall
#15154
Labels
closed due inactivity
The issue/PR was automatically closed due to inactivity.
feature
stale
The issue/PR was marked as stale because it has been open for too long.
Abstract
The
abi.encodeCall
function is very useful as the type information can be defined in common interfaces used across source files. For example:However, decoding the result is very awkward,
abi.encodeCall
returnsbytes memory
and includes the function selector, but you can't easily slice the result to skip the 4 byte function selector and must re-specify the arguments of the function which is being encoded.In an ideal world, the following would work:
Motivation
Many contracts pass function calls around or interpret them in one way or another, especially now that bridging protocols and account abstraction is pervasive. However, the need to explicitly specify the types used when decoding can lead to subtle errors where the data is decoded but is interpreted as the wrong type, or it can make refactoring tedious during development.
Using structures defined in common files is one way to address this problem, as is (ab)using the Solidity auto-generated function call dispatch routines in contracts.
But really, it would be useful to round-trip encoded calls.
Specification
abi.decodeCall(function functionPointer, (...), bytes memory) returns (...)
: ABI-decodes a call tofunctionPointer
with the given data. Performs a full type-check ensuring the return types match the function signature. Encoded function signature must match thefunctionPointer
.The text was updated successfully, but these errors were encountered: