mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Prevent encoding of weird types and support packed encoding of external function types.
This commit is contained in:
committed by
Alex Beregszaszi
parent
c2ae33f806
commit
5c8a6aac69
@@ -1644,9 +1644,20 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
|
||||
auto const& argType = type(*arguments[i]);
|
||||
if (functionType->takesArbitraryParameters())
|
||||
{
|
||||
bool errored = false;
|
||||
if (auto t = dynamic_cast<RationalNumberType const*>(argType.get()))
|
||||
if (!t->mobileType())
|
||||
{
|
||||
m_errorReporter.typeError(arguments[i]->location(), "Invalid rational number (too large or division by zero).");
|
||||
errored = true;
|
||||
}
|
||||
if (!errored && !(
|
||||
argType->mobileType() &&
|
||||
argType->mobileType()->interfaceType(false) &&
|
||||
argType->mobileType()->interfaceType(false)->encodingType() &&
|
||||
!(dynamic_cast<StructType const*>(argType->mobileType()->interfaceType(false)->encodingType().get()))
|
||||
))
|
||||
m_errorReporter.typeError(arguments[i]->location(), "This type cannot be encoded.");
|
||||
}
|
||||
else if (!type(*arguments[i])->isImplicitlyConvertibleTo(*parameterTypes[i]))
|
||||
m_errorReporter.typeError(
|
||||
|
||||
@@ -1262,6 +1262,8 @@ bool ContractType::isPayable() const
|
||||
|
||||
TypePointer ContractType::unaryOperatorResult(Token::Value _operator) const
|
||||
{
|
||||
if (isSuper())
|
||||
return TypePointer{};
|
||||
return _operator == Token::Delete ? make_shared<TupleType>() : TypePointer();
|
||||
}
|
||||
|
||||
|
||||
@@ -692,22 +692,27 @@ public:
|
||||
virtual bool operator==(Type const& _other) const override;
|
||||
virtual unsigned calldataEncodedSize(bool _padded ) const override
|
||||
{
|
||||
solAssert(!isSuper(), "");
|
||||
return encodingType()->calldataEncodedSize(_padded);
|
||||
}
|
||||
virtual unsigned storageBytes() const override { return 20; }
|
||||
virtual bool canLiveOutsideStorage() const override { return true; }
|
||||
virtual unsigned storageBytes() const override { solAssert(!isSuper(), ""); return 20; }
|
||||
virtual bool canLiveOutsideStorage() const override { return !isSuper(); }
|
||||
virtual unsigned sizeOnStack() const override { return m_super ? 0 : 1; }
|
||||
virtual bool isValueType() const override { return true; }
|
||||
virtual bool isValueType() const override { return !isSuper(); }
|
||||
virtual std::string toString(bool _short) const override;
|
||||
virtual std::string canonicalName() const override;
|
||||
|
||||
virtual MemberList::MemberMap nativeMembers(ContractDefinition const* _currentScope) const override;
|
||||
virtual TypePointer encodingType() const override
|
||||
{
|
||||
if (isSuper())
|
||||
return TypePointer{};
|
||||
return std::make_shared<IntegerType>(160, IntegerType::Modifier::Address);
|
||||
}
|
||||
virtual TypePointer interfaceType(bool _inLibrary) const override
|
||||
{
|
||||
if (isSuper())
|
||||
return TypePointer{};
|
||||
return _inLibrary ? shared_from_this() : encodingType();
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,6 @@ void CompilerUtils::storeInMemoryDynamic(Type const& _type, bool _padToWordBound
|
||||
dynamic_cast<FunctionType const&>(_type).kind() == FunctionType::Kind::External
|
||||
)
|
||||
{
|
||||
solUnimplementedAssert(_padToWordBoundaries, "Non-padded store for function not implemented.");
|
||||
combineExternalFunctionType(true);
|
||||
m_context << Instruction::DUP2 << Instruction::MSTORE;
|
||||
m_context << u256(_padToWordBoundaries ? 32 : 24) << Instruction::ADD;
|
||||
|
||||
Reference in New Issue
Block a user