mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[SMTChecker] Fixing conversion from StringLiteral to FixedBytes
This commit is contained in:
@@ -959,16 +959,21 @@ void SMTEncoder::visitTypeConversion(FunctionCall const& _funCall)
|
||||
solAssert(_funCall.arguments().size() == 1, "");
|
||||
|
||||
auto argument = _funCall.arguments().front();
|
||||
auto const& argType = argument->annotation().type;
|
||||
auto const argType = argument->annotation().type;
|
||||
auto const funCallType = _funCall.annotation().type;
|
||||
|
||||
unsigned argSize = argument->annotation().type->storageBytes();
|
||||
unsigned castSize = _funCall.annotation().type->storageBytes();
|
||||
auto symbArg = expr(*argument, funCallType);
|
||||
|
||||
auto const& funCallType = _funCall.annotation().type;
|
||||
if (smt::isStringLiteral(*argType) && smt::isFixedBytes(*funCallType))
|
||||
{
|
||||
defineExpr(_funCall, symbArg);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO Simplify this whole thing for 0.8.0 where weird casts are disallowed.
|
||||
|
||||
auto symbArg = expr(*argument, funCallType);
|
||||
unsigned argSize = argType->storageBytes();
|
||||
unsigned castSize = funCallType->storageBytes();
|
||||
bool castIsSigned = smt::isNumber(*funCallType) && smt::isSigned(funCallType);
|
||||
bool argIsSigned = smt::isNumber(*argType) && smt::isSigned(argType);
|
||||
optional<smtutil::Expression> symbMin;
|
||||
@@ -1112,7 +1117,7 @@ void SMTEncoder::endVisit(Literal const& _literal)
|
||||
|
||||
addArrayLiteralAssertions(
|
||||
*symbArray,
|
||||
applyMap(_literal.value(), [&](auto const& c) { return smtutil::Expression{size_t(c)}; })
|
||||
applyMap(_literal.value(), [](unsigned char c) { return smtutil::Expression{size_t(c)}; })
|
||||
);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -566,11 +566,13 @@ optional<smtutil::Expression> symbolicTypeConversion(TypePointer _from, TypePoin
|
||||
// but they can also be compared/assigned to fixed bytes, in which
|
||||
// case they'd need to be encoded as numbers.
|
||||
if (auto strType = dynamic_cast<StringLiteralType const*>(_from))
|
||||
if (_to->category() == frontend::Type::Category::FixedBytes)
|
||||
if (auto fixedBytesType = dynamic_cast<FixedBytesType const*>(_to))
|
||||
{
|
||||
if (strType->value().empty())
|
||||
return smtutil::Expression(size_t(0));
|
||||
return smtutil::Expression(u256(toHex(util::asBytes(strType->value()), util::HexPrefix::Add)));
|
||||
auto bytesVec = util::asBytes(strType->value());
|
||||
bytesVec.resize(fixedBytesType->numBytes(), 0);
|
||||
return smtutil::Expression(u256(toHex(bytesVec, util::HexPrefix::Add)));
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
|
||||
Reference in New Issue
Block a user