Ensure that address types are always declared as 160bit

This commit is contained in:
Alex Beregszaszi 2017-09-26 22:46:33 +01:00
parent eb5a6aacd9
commit ee65ecfb3b
5 changed files with 14 additions and 14 deletions

View File

@ -1954,7 +1954,7 @@ void TypeChecker::endVisit(Literal const& _literal)
if (_literal.looksLikeAddress()) if (_literal.looksLikeAddress())
{ {
if (_literal.passesAddressChecksum()) if (_literal.passesAddressChecksum())
_literal.annotation().type = make_shared<IntegerType>(0, IntegerType::Modifier::Address); _literal.annotation().type = make_shared<IntegerType>(160, IntegerType::Modifier::Address);
else else
m_errorReporter.warning( m_errorReporter.warning(
_literal.location(), _literal.location(),

View File

@ -203,7 +203,7 @@ TypePointer Type::fromElementaryTypeName(ElementaryTypeNameToken const& _type)
case Token::Byte: case Token::Byte:
return make_shared<FixedBytesType>(1); return make_shared<FixedBytesType>(1);
case Token::Address: case Token::Address:
return make_shared<IntegerType>(0, IntegerType::Modifier::Address); return make_shared<IntegerType>(160, IntegerType::Modifier::Address);
case Token::Bool: case Token::Bool:
return make_shared<BoolType>(); return make_shared<BoolType>();
case Token::Bytes: case Token::Bytes:
@ -327,11 +327,11 @@ IntegerType::IntegerType(int _bits, IntegerType::Modifier _modifier):
m_bits(_bits), m_modifier(_modifier) m_bits(_bits), m_modifier(_modifier)
{ {
if (isAddress()) if (isAddress())
m_bits = 160; solAssert(m_bits == 160, "");
solAssert( solAssert(
m_bits > 0 && m_bits <= 256 && m_bits % 8 == 0, m_bits > 0 && m_bits <= 256 && m_bits % 8 == 0,
"Invalid bit number for integer type: " + dev::toString(_bits) "Invalid bit number for integer type: " + dev::toString(_bits)
); );
} }
string IntegerType::identifier() const string IntegerType::identifier() const
@ -1619,7 +1619,7 @@ string ContractType::canonicalName() const
MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) const MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) const
{ {
// All address members and all interface functions // 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) if (m_super)
{ {
// add the most derived of all functions which are visible in derived contracts // 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: case Kind::Block:
return MemberList::MemberMap({ return MemberList::MemberMap({
{"coinbase", make_shared<IntegerType>(0, IntegerType::Modifier::Address)}, {"coinbase", make_shared<IntegerType>(160, IntegerType::Modifier::Address)},
{"timestamp", make_shared<IntegerType>(256)}, {"timestamp", make_shared<IntegerType>(256)},
{"blockhash", make_shared<FunctionType>(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)}, {"blockhash", make_shared<FunctionType>(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)},
{"difficulty", make_shared<IntegerType>(256)}, {"difficulty", make_shared<IntegerType>(256)},
@ -2977,7 +2977,7 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const
}); });
case Kind::Message: case Kind::Message:
return MemberList::MemberMap({ return MemberList::MemberMap({
{"sender", make_shared<IntegerType>(0, IntegerType::Modifier::Address)}, {"sender", make_shared<IntegerType>(160, IntegerType::Modifier::Address)},
{"gas", make_shared<IntegerType>(256)}, {"gas", make_shared<IntegerType>(256)},
{"value", make_shared<IntegerType>(256)}, {"value", make_shared<IntegerType>(256)},
{"data", make_shared<ArrayType>(DataLocation::CallData)}, {"data", make_shared<ArrayType>(DataLocation::CallData)},
@ -2985,7 +2985,7 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const
}); });
case Kind::Transaction: case Kind::Transaction:
return MemberList::MemberMap({ return MemberList::MemberMap({
{"origin", make_shared<IntegerType>(0, IntegerType::Modifier::Address)}, {"origin", make_shared<IntegerType>(160, IntegerType::Modifier::Address)},
{"gasprice", make_shared<IntegerType>(256)} {"gasprice", make_shared<IntegerType>(256)}
}); });
default: default:

View File

@ -162,7 +162,7 @@ string ABIFunctions::cleanupFunction(Type const& _type, bool _revertOnFailure)
break; break;
} }
case Type::Category::Contract: 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; break;
case Type::Category::Enum: case Type::Category::Enum:
{ {
@ -243,7 +243,7 @@ string ABIFunctions::conversionFunction(Type const& _from, Type const& _to)
toCategory == Type::Category::Integer || toCategory == Type::Category::Integer ||
toCategory == Type::Category::Contract, toCategory == Type::Category::Contract,
""); "");
IntegerType const addressType(0, IntegerType::Modifier::Address); IntegerType const addressType(160, IntegerType::Modifier::Address);
IntegerType const& to = IntegerType const& to =
toCategory == Type::Category::Integer ? toCategory == Type::Category::Integer ?
dynamic_cast<IntegerType const&>(_to) : dynamic_cast<IntegerType const&>(_to) :

View File

@ -541,7 +541,7 @@ void CompilerUtils::convertType(
else else
{ {
solAssert(targetTypeCategory == Type::Category::Integer || targetTypeCategory == Type::Category::Contract, ""); 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 IntegerType const& targetType = targetTypeCategory == Type::Category::Integer
? dynamic_cast<IntegerType const&>(_targetType) : addressType; ? dynamic_cast<IntegerType const&>(_targetType) : addressType;
if (stackTypeCategory == Type::Category::RationalNumber) if (stackTypeCategory == Type::Category::RationalNumber)

View File

@ -1040,7 +1040,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
identifier = FunctionType(*function).externalIdentifier(); identifier = FunctionType(*function).externalIdentifier();
else else
solAssert(false, "Contract member is neither variable nor function."); 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; m_context << identifier;
} }
else else
@ -1057,7 +1057,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
{ {
utils().convertType( utils().convertType(
*_memberAccess.expression().annotation().type, *_memberAccess.expression().annotation().type,
IntegerType(0, IntegerType::Modifier::Address), IntegerType(160, IntegerType::Modifier::Address),
true true
); );
m_context << Instruction::BALANCE; m_context << Instruction::BALANCE;
@ -1065,7 +1065,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
else if ((set<string>{"send", "transfer", "call", "callcode", "delegatecall"}).count(member)) else if ((set<string>{"send", "transfer", "call", "callcode", "delegatecall"}).count(member))
utils().convertType( utils().convertType(
*_memberAccess.expression().annotation().type, *_memberAccess.expression().annotation().type,
IntegerType(0, IntegerType::Modifier::Address), IntegerType(160, IntegerType::Modifier::Address),
true true
); );
else else