Packed Encoding: Disallow types in v2 that aren't allowed in v1

This commit is contained in:
Mathias Baumann
2019-02-11 11:37:48 +01:00
committed by chriseth
parent 227addfcef
commit fe2429de9f
8 changed files with 52 additions and 31 deletions
+15 -6
View File
@@ -48,9 +48,9 @@ using namespace dev::solidity;
namespace
{
bool typeSupportedByOldABIEncoder(Type const& _type)
bool typeSupportedByOldABIEncoder(Type const& _type, bool _isLibraryCall)
{
if (_type.dataStoredIn(DataLocation::Storage))
if (_isLibraryCall && _type.dataStoredIn(DataLocation::Storage))
return true;
if (_type.category() == Type::Category::Struct)
return false;
@@ -58,7 +58,7 @@ bool typeSupportedByOldABIEncoder(Type const& _type)
{
auto const& arrayType = dynamic_cast<ArrayType const&>(_type);
auto base = arrayType.baseType();
if (!typeSupportedByOldABIEncoder(*base) || (base->category() == Type::Category::Array && base->isDynamicallySized()))
if (!typeSupportedByOldABIEncoder(*base, _isLibraryCall) || (base->category() == Type::Category::Array && base->isDynamicallySized()))
return false;
}
return true;
@@ -355,7 +355,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
if (
_function.isPublic() &&
!_function.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::ABIEncoderV2) &&
!typeSupportedByOldABIEncoder(*type(var))
!typeSupportedByOldABIEncoder(*type(var), isLibraryFunction)
)
m_errorReporter.typeError(
var.location(),
@@ -475,7 +475,7 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
{
vector<string> unsupportedTypes;
for (auto const& param: getter.parameterTypes() + getter.returnParameterTypes())
if (!typeSupportedByOldABIEncoder(*param))
if (!typeSupportedByOldABIEncoder(*param, false /* isLibrary */))
unsupportedTypes.emplace_back(param->toString());
if (!unsupportedTypes.empty())
m_errorReporter.typeError(_variable.location(),
@@ -585,7 +585,7 @@ bool TypeChecker::visit(EventDefinition const& _eventDef)
m_errorReporter.typeError(var->location(), "Internal or recursive type is not allowed as event parameter type.");
if (
!_eventDef.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::ABIEncoderV2) &&
!typeSupportedByOldABIEncoder(*type(*var))
!typeSupportedByOldABIEncoder(*type(*var), false /* isLibrary */)
)
m_errorReporter.typeError(
var->location(),
@@ -1550,6 +1550,15 @@ void TypeChecker::typeCheckABIEncodeFunctions(
}
}
if (isPacked && !typeSupportedByOldABIEncoder(*argType, false /* isLibrary */))
{
m_errorReporter.typeError(
arguments[i]->location(),
"Type not supported in packed mode."
);
continue;
}
if (!argType->fullEncodingType(false, abiEncoderV2, !_functionType->padArguments()))
m_errorReporter.typeError(
arguments[i]->location(),