fix(sema): reject rational expressions in abi.encode* arguments#1892
Open
aryanbaranwal001 wants to merge 1 commit intohyperledger-solang:mainfrom
Open
fix(sema): reject rational expressions in abi.encode* arguments#1892aryanbaranwal001 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 rational (fractional/decimal) expression is passed as an argument to
abi.encode*.unreachable!("Type should not exist in codegen")when abi-encoding a rational expression #1864The 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::Rational, which is a sema level placeholder for expressions involving decimal literals,24.24,1 - 24.24,1.5 * 2that haven't been coerced to a concrete integer type, which only happens when a target type is available (e.g.uint256 x = 32). The rational expression is stored in AST asType::Rationalwithout any error which then passes into codegen.codegen/expression.rs:1048matchesast::Builtin::AbiEncodePackedand callsabi_encode_packed()atcodegen/expression.rs:1853.abi_encode_packedmapsexpression()over each arg and passes the result toabi_encode()atcodegen/expression.rs:1858.abi_encodecallscalculate_size_args()atcodegen/encoding/mod.rs:48, which callsget_expr_size()atcodegen/encoding/mod.rs:176.get_expr_sizematches on the expression's type.Type::Rationalhits the unreachable arm atcodegen/encoding/mod.rs:1454–1456:Fix
Add a
Type::Rationalguard in the arg resolution loop atsema/builtin.rs:1407, immediately after the existing mapping/recursive check:This makes sema reject unresolved rational expressions before they reach codegen. The fix covers all
abi.encode*variants ofabi.encode,abi.encodePacked,abi.encodeWithSelector, andabi.encodeWithSignature, since they all share the same loop atsema/builtin.rs:1403.Previously panicking inputs:
abi.encodePacked(1 - 24.24);abi.encode(1.7);Reproduces on
polkadot,solana, andevmtargets.