From ee65ecfb3b80d9c027bade21df883e897b1234c5 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 26 Sep 2017 22:46:33 +0100 Subject: [PATCH] Ensure that address types are always declared as 160bit --- libsolidity/analysis/TypeChecker.cpp | 2 +- libsolidity/ast/Types.cpp | 14 +++++++------- libsolidity/codegen/ABIFunctions.cpp | 4 ++-- libsolidity/codegen/CompilerUtils.cpp | 2 +- libsolidity/codegen/ExpressionCompiler.cpp | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 4b2ec8d64..21d3dda6c 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1954,7 +1954,7 @@ void TypeChecker::endVisit(Literal const& _literal) if (_literal.looksLikeAddress()) { if (_literal.passesAddressChecksum()) - _literal.annotation().type = make_shared(0, IntegerType::Modifier::Address); + _literal.annotation().type = make_shared(160, IntegerType::Modifier::Address); else m_errorReporter.warning( _literal.location(), diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 83a5b465a..ebf2cd8b3 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -203,7 +203,7 @@ TypePointer Type::fromElementaryTypeName(ElementaryTypeNameToken const& _type) case Token::Byte: return make_shared(1); case Token::Address: - return make_shared(0, IntegerType::Modifier::Address); + return make_shared(160, IntegerType::Modifier::Address); case Token::Bool: return make_shared(); case Token::Bytes: @@ -327,11 +327,11 @@ IntegerType::IntegerType(int _bits, IntegerType::Modifier _modifier): m_bits(_bits), m_modifier(_modifier) { if (isAddress()) - m_bits = 160; + solAssert(m_bits == 160, ""); solAssert( m_bits > 0 && m_bits <= 256 && m_bits % 8 == 0, "Invalid bit number for integer type: " + dev::toString(_bits) - ); + ); } string IntegerType::identifier() const @@ -1619,7 +1619,7 @@ string ContractType::canonicalName() const MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) const { // All address members and all interface functions - MemberList::MemberMap members(IntegerType(120, IntegerType::Modifier::Address).nativeMembers(nullptr)); + MemberList::MemberMap members(IntegerType(160, IntegerType::Modifier::Address).nativeMembers(nullptr)); if (m_super) { // add the most derived of all functions which are visible in derived contracts @@ -2968,7 +2968,7 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const { case Kind::Block: return MemberList::MemberMap({ - {"coinbase", make_shared(0, IntegerType::Modifier::Address)}, + {"coinbase", make_shared(160, IntegerType::Modifier::Address)}, {"timestamp", make_shared(256)}, {"blockhash", make_shared(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)}, {"difficulty", make_shared(256)}, @@ -2977,7 +2977,7 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const }); case Kind::Message: return MemberList::MemberMap({ - {"sender", make_shared(0, IntegerType::Modifier::Address)}, + {"sender", make_shared(160, IntegerType::Modifier::Address)}, {"gas", make_shared(256)}, {"value", make_shared(256)}, {"data", make_shared(DataLocation::CallData)}, @@ -2985,7 +2985,7 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const }); case Kind::Transaction: return MemberList::MemberMap({ - {"origin", make_shared(0, IntegerType::Modifier::Address)}, + {"origin", make_shared(160, IntegerType::Modifier::Address)}, {"gasprice", make_shared(256)} }); default: diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index 9f6c55ba6..22b620e1a 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -162,7 +162,7 @@ string ABIFunctions::cleanupFunction(Type const& _type, bool _revertOnFailure) break; } case Type::Category::Contract: - templ("body", "cleaned := " + cleanupFunction(IntegerType(0, IntegerType::Modifier::Address)) + "(value)"); + templ("body", "cleaned := " + cleanupFunction(IntegerType(160, IntegerType::Modifier::Address)) + "(value)"); break; case Type::Category::Enum: { @@ -243,7 +243,7 @@ string ABIFunctions::conversionFunction(Type const& _from, Type const& _to) toCategory == Type::Category::Integer || toCategory == Type::Category::Contract, ""); - IntegerType const addressType(0, IntegerType::Modifier::Address); + IntegerType const addressType(160, IntegerType::Modifier::Address); IntegerType const& to = toCategory == Type::Category::Integer ? dynamic_cast(_to) : diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index c1171c1d2..ce97ed610 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -541,7 +541,7 @@ void CompilerUtils::convertType( else { solAssert(targetTypeCategory == Type::Category::Integer || targetTypeCategory == Type::Category::Contract, ""); - IntegerType addressType(0, IntegerType::Modifier::Address); + IntegerType addressType(160, IntegerType::Modifier::Address); IntegerType const& targetType = targetTypeCategory == Type::Category::Integer ? dynamic_cast(_targetType) : addressType; if (stackTypeCategory == Type::Category::RationalNumber) diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index b286594ab..58c64bce7 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -1040,7 +1040,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) identifier = FunctionType(*function).externalIdentifier(); else solAssert(false, "Contract member is neither variable nor function."); - utils().convertType(type, IntegerType(0, IntegerType::Modifier::Address), true); + utils().convertType(type, IntegerType(160, IntegerType::Modifier::Address), true); m_context << identifier; } else @@ -1057,7 +1057,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) { utils().convertType( *_memberAccess.expression().annotation().type, - IntegerType(0, IntegerType::Modifier::Address), + IntegerType(160, IntegerType::Modifier::Address), true ); m_context << Instruction::BALANCE; @@ -1065,7 +1065,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) else if ((set{"send", "transfer", "call", "callcode", "delegatecall"}).count(member)) utils().convertType( *_memberAccess.expression().annotation().type, - IntegerType(0, IntegerType::Modifier::Address), + IntegerType(160, IntegerType::Modifier::Address), true ); else