mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #11590 from ethereum/disallow-non-hex-zero-and-fix-bytes32-literals-in-bytes-concat
Disallow non-hex zero literals and fix 32-byte hex literals in `bytes.concat()`
This commit is contained in:
@@ -2033,11 +2033,14 @@ void TypeChecker::typeCheckBytesConcatFunction(
|
||||
typeCheckFunctionGeneralChecks(_functionCall, _functionType);
|
||||
|
||||
for (shared_ptr<Expression const> const& argument: _functionCall.arguments())
|
||||
if (
|
||||
Type const* argumentType = type(*argument);
|
||||
{
|
||||
Type const* argumentType = type(*argument);
|
||||
bool notConvertibleToBytes =
|
||||
!argumentType->isImplicitlyConvertibleTo(*TypeProvider::fixedBytes(32)) &&
|
||||
!argumentType->isImplicitlyConvertibleTo(*TypeProvider::bytesMemory())
|
||||
)
|
||||
!argumentType->isImplicitlyConvertibleTo(*TypeProvider::bytesMemory());
|
||||
bool numberLiteral = (dynamic_cast<RationalNumberType const*>(argumentType) != nullptr);
|
||||
|
||||
if (notConvertibleToBytes || numberLiteral)
|
||||
m_errorReporter.typeError(
|
||||
8015_error,
|
||||
argument->location(),
|
||||
@@ -2045,6 +2048,7 @@ void TypeChecker::typeCheckBytesConcatFunction(
|
||||
"bytes or fixed bytes type is required, but " +
|
||||
argumentType->toString(true) + " provided."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void TypeChecker::typeCheckFunctionGeneralChecks(
|
||||
|
||||
@@ -593,7 +593,7 @@ public:
|
||||
private:
|
||||
rational m_value;
|
||||
|
||||
/// Bytes type to which the rational can be explicitly converted.
|
||||
/// Bytes type to which the rational can be implicitly converted.
|
||||
/// Empty for all rationals that are not directly parsed from hex literals.
|
||||
Type const* m_compatibleBytesType;
|
||||
|
||||
|
||||
@@ -1086,13 +1086,9 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
literalType && !literalType->value().empty() && literalType->value().size() <= 32
|
||||
)
|
||||
targetTypes.emplace_back(TypeProvider::fixedBytes(static_cast<unsigned>(literalType->value().size())));
|
||||
else if (auto const* literalType = dynamic_cast<RationalNumberType const*>(argument->annotation().type))
|
||||
{
|
||||
solAssert(literalType->value() == 0, "");
|
||||
targetTypes.emplace_back(TypeProvider::fixedBytes(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
solAssert(!dynamic_cast<RationalNumberType const*>(argument->annotation().type), "");
|
||||
solAssert(argument->annotation().type->isImplicitlyConvertibleTo(*TypeProvider::bytesMemory()), "");
|
||||
targetTypes.emplace_back(TypeProvider::bytesMemory());
|
||||
}
|
||||
|
||||
@@ -2476,13 +2476,9 @@ string YulUtilFunctions::bytesConcatFunction(vector<Type const*> const& _argumen
|
||||
literalType && !literalType->value().empty() && literalType->value().size() <= 32
|
||||
)
|
||||
targetTypes.emplace_back(TypeProvider::fixedBytes(static_cast<unsigned>(literalType->value().size())));
|
||||
else if (auto const* literalType = dynamic_cast<RationalNumberType const*>(argumentType))
|
||||
{
|
||||
solAssert(literalType->value() == 0, "");
|
||||
targetTypes.emplace_back(TypeProvider::fixedBytes(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
solAssert(!dynamic_cast<RationalNumberType const*>(argumentType), "");
|
||||
solAssert(argumentType->isImplicitlyConvertibleTo(*TypeProvider::bytesMemory()), "");
|
||||
targetTypes.emplace_back(TypeProvider::bytesMemory());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user