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 abi.encodeError #14974
Add abi.encodeError #14974
Conversation
Thank you for your contribution to the Solidity compiler! A team member will follow up shortly. If you haven't read our contributing guidelines and our review checklist before, please do it now, this makes the reviewing process and accepting your contribution smoother. If you have any questions or need our help, feel free to post them in the PR or talk to us directly on the #solidity-dev channel on Matrix. |
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.
Needs some semantic tests as well. A changelog entry as well.
abi.encodeError(g, (1)); | ||
} | ||
// ---- | ||
// TypeError 3510: (56-57): Expected an error type. Cannot use functions for abi.encodeError. |
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.
Needs another case for library functions.
This CI error: https://app.circleci.com/pipelines/github/ethereum/solidity/33577/workflows/8c3156a6-35f8-4aeb-b6e3-18f80f4cb6cf/jobs/1512784 is because the test file name is wrong, see: |
Yes, i'm still working on the testing part. Edit: should be good now |
Apparently, in the semantic tests, the returned Is that supposed to happen? |
Could be just another instance of #13989. The issue is about fixed bytes, but maybe it affects |
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.
This needs documentation entries in https://docs.soliditylang.org/en/v0.8.23/cheatsheet.html and https://docs.soliditylang.org/en/v0.8.23/units-and-global-variables.html#abi-encoding-and-decoding-functions (at least, there may be other places, but those are the main ones I guess).
I think the implementation is good, just left some minor suggestions. However, I think we could avoid the duplicated code with some if
s and ternary conditions and have it all in one typeCheckABIEncodeCallFunctionOrError
(or something like that), but I don't consider that should impede this PR from being merged.
Co-authored-by: matheusaaguiar <95899911+matheusaaguiar@users.noreply.github.com>
into a single typeCheckABIEncodeCallFunctionOrError
|
docs/cheatsheet.rst
Outdated
@@ -26,6 +26,8 @@ ABI Encoding and Decoding Functions | |||
tuple. Performs a full type-check, ensuring the types match the function signature. Result equals ``abi.encodeWithSelector(functionPointer.selector, (...))`` | |||
- ``abi.encodeWithSignature(string memory signature, ...) returns (bytes memory)``: Equivalent | |||
to ``abi.encodeWithSelector(bytes4(keccak256(bytes(signature))), ...)`` | |||
- ``abi.encodeError(error errorPointer, (...)) returns (bytes memory)``: ABI-encodes the revert data for ``errorPointer`` with the arguments found in the | |||
tuple. Performs a full type-check, ensuring the types match the error definition. Results equals ``abi.encodeWithSelector(errorPointer.selector, (...))`` |
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.
tuple. Performs a full type-check, ensuring the types match the error definition. Results equals ``abi.encodeWithSelector(errorPointer.selector, (...))`` | |
tuple. Performs a full type-check, ensuring the types match the error definition. Results equals ``abi.encodeWithSelector(errorPointer.selector, ...)`` |
This a minor imprecision that was fixed recently in the previous entry for abi.encodeCall
:)
I will already commit this suggestion via github interface;
Actually, there were another instances which I already fixed via a commit.
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.
I just have one nitpick left, but overall looks good to me.
Also, I forgot to mention that we use rebase
rather than merge
and this needs the former.
m_errorReporter.typeError( | ||
5512_error, | ||
arguments.front()->location(), | ||
"Expected first argument to be a custom error, not \"" + |
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.
I was trying to think of some test cases and when I try something like:
error E(uint a, uint b);
contract C {
function g() public view returns (bytes memory) {
bytes memory b1 = abi.encodeError(E(1, 2), (1, 2));
return b1;
}
}
The following error message is generated:
Expected first argument to be a custom error, not "error".
Which is a bit weird. Maybe we should be more precise and change to [...] custom error name [...]
?
I think we should have a test like this anyway.
Pending the discussion in #14287 (comment), we decided to close this PR for now. But feel free to jump in there (or join one of our calls) and make the case for this approach and we can potentially revisit and revive this PR! |
Fixes #14287
TODO:
typeCheckABIEncodeCallFunction
andtypeCheckABIEncodeErrorFunction
?