aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-11-11 19:07:30 +0800
committerchriseth <c@ethdev.com>2016-11-16 21:37:18 +0800
commit22b4d1b29a17c6a6360d6d6e42860bd621a7bfd3 (patch)
treed1214fc92f986a2e973f126be4f2e88576631ef2 /libsolidity/ast
parentf3d0433ec3aca99f6d9212da944c6fc51cb9292a (diff)
downloaddexon-solidity-22b4d1b29a17c6a6360d6d6e42860bd621a7bfd3.tar.gz
dexon-solidity-22b4d1b29a17c6a6360d6d6e42860bd621a7bfd3.tar.zst
dexon-solidity-22b4d1b29a17c6a6360d6d6e42860bd621a7bfd3.zip
Check that no internals are used in any external function type.
Diffstat (limited to 'libsolidity/ast')
-rw-r--r--libsolidity/ast/Types.cpp24
-rw-r--r--libsolidity/ast/Types.h4
2 files changed, 28 insertions, 0 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index e18735d9..c1ae183e 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -1265,6 +1265,7 @@ TypePointer ArrayType::decodingType() const
TypePointer ArrayType::interfaceType(bool _inLibrary) const
{
+ // Note: This has to fulfill canBeUsedExternally(_inLibrary) == !!interfaceType(_inLibrary)
if (_inLibrary && location() == DataLocation::Storage)
return shared_from_this();
@@ -1282,6 +1283,21 @@ TypePointer ArrayType::interfaceType(bool _inLibrary) const
return make_shared<ArrayType>(DataLocation::Memory, baseExt, m_length);
}
+bool ArrayType::canBeUsedExternally(bool _inLibrary) const
+{
+ // Note: This has to fulfill canBeUsedExternally(_inLibrary) == !!interfaceType(_inLibrary)
+ if (_inLibrary && location() == DataLocation::Storage)
+ return true;
+ else if (m_arrayKind != ArrayKind::Ordinary)
+ return true;
+ else if (!m_baseType->canBeUsedExternally(_inLibrary))
+ return false;
+ else if (m_baseType->category() == Category::Array && m_baseType->isDynamicallySized())
+ return false;
+ else
+ return true;
+}
+
u256 ArrayType::memorySize() const
{
solAssert(!isDynamicallySized(), "");
@@ -1815,11 +1831,19 @@ FunctionType::FunctionType(FunctionTypeName const& _typeName):
for (auto const& t: _typeName.parameterTypes())
{
solAssert(t->annotation().type, "Type not set for parameter.");
+ solAssert(
+ m_location != Location::External || t->annotation().type->canBeUsedExternally(false),
+ "Internal type used as parameter for external function."
+ );
m_parameterTypes.push_back(t->annotation().type);
}
for (auto const& t: _typeName.returnParameterTypes())
{
solAssert(t->annotation().type, "Type not set for return parameter.");
+ solAssert(
+ m_location != Location::External || t->annotation().type->canBeUsedExternally(false),
+ "Internal type used as return parameter for external function."
+ );
m_returnParameterTypes.push_back(t->annotation().type);
}
}
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index 9831bc42..84e56663 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -254,6 +254,9 @@ public:
/// @param _inLibrary if set, returns types as used in a library, e.g. struct and contract types
/// are returned without modification.
virtual TypePointer interfaceType(bool /*_inLibrary*/) const { return TypePointer(); }
+ /// @returns true iff this type can be passed on via calls (to libraries if _inLibrary is true),
+ /// should be have identical to !!interfaceType(_inLibrary) but might do optimizations.
+ virtual bool canBeUsedExternally(bool _inLibrary) const { return !!interfaceType(_inLibrary); }
private:
/// @returns a member list containing all members added to this type by `using for` directives.
@@ -580,6 +583,7 @@ public:
virtual TypePointer encodingType() const override;
virtual TypePointer decodingType() const override;
virtual TypePointer interfaceType(bool _inLibrary) const override;
+ virtual bool canBeUsedExternally(bool _inLibrary) const override;
/// @returns true if this is a byte array or a string
bool isByteArray() const { return m_arrayKind != ArrayKind::Ordinary; }