fix(sema): reject void typed arguments to abi.encode#1889
Open
aryanbaranwal001 wants to merge 1 commit intohyperledger-solang:mainfrom
Open
fix(sema): reject void typed arguments to abi.encode#1889aryanbaranwal001 wants to merge 1 commit intohyperledger-solang:mainfrom
aryanbaranwal001 wants to merge 1 commit intohyperledger-solang:mainfrom
Conversation
Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a compiler panic when a void returning expression is passed as an argument to
abi.encode*.Expression does not have a typewhenabi.encodePackedreceives a void-returning call #1878The root cause is that sema's
abi.encode*argument resolution loop atsema/builtin.rs:1403only guards against mapping and recursive types. It has no guard forType::Void. So when a void returning expression likerequire(true)or a user defined void functiong()is passed as an argument, sema accepts it without error and stores it in the AST asast::Expression::Builtin { kind: Require, tys: [Type::Void], ... }.codegen/expression.rs:1050, codegen'sexpression()matchesast::Builtin::AbiEncodePackedand callsabi_encode_packed()atcodegen/expression.rs:1853.abi_encode_packedthen mapsexpression()over each arg. ForBuiltin::Require, this callsrevert::require()atcodegen/revert.rs:235, which emits the branch IR and returnsExpression::Poison. ThatPoisonis put into the packed args list.abi_encode_packedpasses the list toabi_encode()atcodegen/expression.rs:1858.abi_encodecallscalculate_size_args()atcodegen/encoding/mod.rs:48.calculate_size_argscallsget_expr_size()atcodegen/encoding/mod.rs:176.get_expr_sizeimmediately callsexpr.ty()onExpression::Poison, which hitsExpression::Poison => unreachable!("Expression does not have a type")atcodegen/mod.rs:1003and panics.Fix
Add a
Type::Voidguard in the arg resolution loop atsema/builtin.rs:1404, after the arg is resolved and before theis_mappingcheck:This makes sema reject void arguments before they reach codegen. The fix covers all affected variants,
abi.encode,abi.encodePacked,abi.encodeWithSelectorandabi.encodeWithSignature, since they all share the same loop atsema/builtin.rs:1403.Previously panicking inputs:
abi.encodePacked(require(true));abi.encode(require(true));abi.encodePacked(g());wherefunction g() public {}Reproduces on
polkadot,solana, andevmtargets.