[libsolidity] TypeProvider: adds explicit uint256() accessor and removes default params in integerType(...).

This commit is contained in:
Christian Parpart 2019-04-15 18:10:43 +02:00 committed by chriseth
parent 59d4f54729
commit 58a45f2cb6
13 changed files with 57 additions and 54 deletions

View File

@ -57,7 +57,7 @@ inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariable
magicVarDecl("log4", TypeProvider::functionType(strings{"bytes32", "bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log4)), magicVarDecl("log4", TypeProvider::functionType(strings{"bytes32", "bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log4)),
magicVarDecl("msg", TypeProvider::magicType(MagicType::Kind::Message)), magicVarDecl("msg", TypeProvider::magicType(MagicType::Kind::Message)),
magicVarDecl("mulmod", TypeProvider::functionType(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::MulMod, false, StateMutability::Pure)), magicVarDecl("mulmod", TypeProvider::functionType(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::MulMod, false, StateMutability::Pure)),
magicVarDecl("now", TypeProvider::integerType(256)), magicVarDecl("now", TypeProvider::uint256()),
magicVarDecl("require", TypeProvider::functionType(strings{"bool"}, strings{}, FunctionType::Kind::Require, false, StateMutability::Pure)), magicVarDecl("require", TypeProvider::functionType(strings{"bool"}, strings{}, FunctionType::Kind::Require, false, StateMutability::Pure)),
magicVarDecl("require", TypeProvider::functionType(strings{"bool", "string memory"}, strings{}, FunctionType::Kind::Require, false, StateMutability::Pure)), magicVarDecl("require", TypeProvider::functionType(strings{"bool", "string memory"}, strings{}, FunctionType::Kind::Require, false, StateMutability::Pure)),
magicVarDecl("revert", TypeProvider::functionType(strings(), strings(), FunctionType::Kind::Revert, false, StateMutability::Pure)), magicVarDecl("revert", TypeProvider::functionType(strings(), strings(), FunctionType::Kind::Revert, false, StateMutability::Pure)),

View File

@ -1999,7 +1999,7 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
); );
type = ReferenceType::copyForLocationIfReference(DataLocation::Memory, type); type = ReferenceType::copyForLocationIfReference(DataLocation::Memory, type);
_newExpression.annotation().type = TypeProvider::functionType( _newExpression.annotation().type = TypeProvider::functionType(
TypePointers{TypeProvider::integerType(256)}, TypePointers{TypeProvider::uint256()},
TypePointers{type}, TypePointers{type},
strings(1, ""), strings(1, ""),
strings(1, ""), strings(1, ""),
@ -2195,7 +2195,7 @@ bool TypeChecker::visit(IndexAccess const& _access)
} }
else else
{ {
expectType(*index, *TypeProvider::integerType()); expectType(*index, *TypeProvider::uint256());
if (!m_errorReporter.hasErrors()) if (!m_errorReporter.hasErrors())
if (auto numberType = dynamic_cast<RationalNumberType const*>(type(*index))) if (auto numberType = dynamic_cast<RationalNumberType const*>(type(*index)))
{ {
@ -2229,7 +2229,7 @@ bool TypeChecker::visit(IndexAccess const& _access)
else else
{ {
u256 length = 1; u256 length = 1;
if (expectType(*index, *TypeProvider::integerType())) if (expectType(*index, *TypeProvider::uint256()))
{ {
if (auto indexValue = dynamic_cast<RationalNumberType const*>(type(*index))) if (auto indexValue = dynamic_cast<RationalNumberType const*>(type(*index)))
length = indexValue->literalValue(nullptr); length = indexValue->literalValue(nullptr);
@ -2254,7 +2254,7 @@ bool TypeChecker::visit(IndexAccess const& _access)
m_errorReporter.typeError(_access.location(), "Index expression cannot be omitted."); m_errorReporter.typeError(_access.location(), "Index expression cannot be omitted.");
else else
{ {
if (!expectType(*index, *TypeProvider::integerType())) if (!expectType(*index, *TypeProvider::uint256()))
m_errorReporter.fatalTypeError(_access.location(), "Index expression cannot be represented as an unsigned integer."); m_errorReporter.fatalTypeError(_access.location(), "Index expression cannot be represented as an unsigned integer.");
if (auto integerType = dynamic_cast<RationalNumberType const*>(type(*index))) if (auto integerType = dynamic_cast<RationalNumberType const*>(type(*index)))
if (bytesType.numBytes() <= integerType->literalValue(nullptr)) if (bytesType.numBytes() <= integerType->literalValue(nullptr))

View File

@ -83,7 +83,7 @@ public:
static AddressType const* payableAddressType() noexcept { return &m_payableAddressType; } static AddressType const* payableAddressType() noexcept { return &m_payableAddressType; }
static AddressType const* addressType() noexcept { return &m_addressType; } static AddressType const* addressType() noexcept { return &m_addressType; }
static IntegerType const* integerType(unsigned _bits = 256, IntegerType::Modifier _modifier = IntegerType::Modifier::Unsigned) static IntegerType const* integerType(unsigned _bits, IntegerType::Modifier _modifier)
{ {
solAssert((_bits % 8) == 0, ""); solAssert((_bits % 8) == 0, "");
if (_modifier == IntegerType::Modifier::Unsigned) if (_modifier == IntegerType::Modifier::Unsigned)
@ -91,6 +91,9 @@ public:
else else
return &m_intM.at(_bits / 8 - 1); return &m_intM.at(_bits / 8 - 1);
} }
static IntegerType const* uint(unsigned _bits) { return integerType(_bits, IntegerType::Modifier::Unsigned); }
static IntegerType const* uint256() { return uint(256); }
static FixedPointType const* fixedPointType(unsigned m, unsigned n, FixedPointType::Modifier _modifier); static FixedPointType const* fixedPointType(unsigned m, unsigned n, FixedPointType::Modifier _modifier);

View File

@ -449,7 +449,7 @@ bool AddressType::operator==(Type const& _other) const
MemberList::MemberMap AddressType::nativeMembers(ContractDefinition const*) const MemberList::MemberMap AddressType::nativeMembers(ContractDefinition const*) const
{ {
MemberList::MemberMap members = { MemberList::MemberMap members = {
{"balance", TypeProvider::integerType(256)}, {"balance", TypeProvider::uint256()},
{"call", TypeProvider::functionType(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareCall, false, StateMutability::Payable)}, {"call", TypeProvider::functionType(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareCall, false, StateMutability::Payable)},
{"callcode", TypeProvider::functionType(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareCallCode, false, StateMutability::Payable)}, {"callcode", TypeProvider::functionType(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareCallCode, false, StateMutability::Payable)},
{"delegatecall", TypeProvider::functionType(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareDelegateCall, false, StateMutability::NonPayable)}, {"delegatecall", TypeProvider::functionType(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareDelegateCall, false, StateMutability::NonPayable)},
@ -1358,7 +1358,7 @@ TypeResult FixedBytesType::binaryOperatorResult(Token _operator, Type const* _ot
MemberList::MemberMap FixedBytesType::nativeMembers(ContractDefinition const*) const MemberList::MemberMap FixedBytesType::nativeMembers(ContractDefinition const*) const
{ {
return MemberList::MemberMap{MemberList::Member{"length", TypeProvider::integerType(8)}}; return MemberList::MemberMap{MemberList::Member{"length", TypeProvider::uint(8)}};
} }
string FixedBytesType::richIdentifier() const string FixedBytesType::richIdentifier() const
@ -1753,12 +1753,12 @@ MemberList::MemberMap ArrayType::nativeMembers(ContractDefinition const*) const
MemberList::MemberMap members; MemberList::MemberMap members;
if (!isString()) if (!isString())
{ {
members.emplace_back("length", TypeProvider::integerType(256)); members.emplace_back("length", TypeProvider::uint256());
if (isDynamicallySized() && location() == DataLocation::Storage) if (isDynamicallySized() && location() == DataLocation::Storage)
{ {
members.emplace_back("push", TypeProvider::functionType( members.emplace_back("push", TypeProvider::functionType(
TypePointers{baseType()}, TypePointers{baseType()},
TypePointers{TypeProvider::integerType(256)}, TypePointers{TypeProvider::uint256()},
strings{string()}, strings{string()},
strings{string()}, strings{string()},
isByteArray() ? FunctionType::Kind::ByteArrayPush : FunctionType::Kind::ArrayPush isByteArray() ? FunctionType::Kind::ByteArrayPush : FunctionType::Kind::ArrayPush
@ -1778,7 +1778,7 @@ MemberList::MemberMap ArrayType::nativeMembers(ContractDefinition const*) const
TypePointer ArrayType::encodingType() const TypePointer ArrayType::encodingType() const
{ {
if (location() == DataLocation::Storage) if (location() == DataLocation::Storage)
return TypeProvider::integerType(256); return TypeProvider::uint256();
else else
return TypeProvider::withLocation(this, DataLocation::Memory, true); return TypeProvider::withLocation(this, DataLocation::Memory, true);
} }
@ -1786,7 +1786,7 @@ TypePointer ArrayType::encodingType() const
TypePointer ArrayType::decodingType() const TypePointer ArrayType::decodingType() const
{ {
if (location() == DataLocation::Storage) if (location() == DataLocation::Storage)
return TypeProvider::integerType(256); return TypeProvider::uint256();
else else
return this; return this;
} }
@ -1955,7 +1955,7 @@ Type const* StructType::encodingType() const
if (location() != DataLocation::Storage) if (location() != DataLocation::Storage)
return this; return this;
return TypeProvider::integerType(256); return TypeProvider::uint256();
} }
BoolResult StructType::isImplicitlyConvertibleTo(Type const& _convertTo) const BoolResult StructType::isImplicitlyConvertibleTo(Type const& _convertTo) const
@ -2252,7 +2252,7 @@ set<string> StructType::membersMissingInMemory() const
TypePointer EnumType::encodingType() const TypePointer EnumType::encodingType() const
{ {
return TypeProvider::integerType(8 * static_cast<int>(storageBytes())); return TypeProvider::uint(8 * storageBytes());
} }
TypeResult EnumType::unaryOperatorResult(Token _operator) const TypeResult EnumType::unaryOperatorResult(Token _operator) const
@ -2458,7 +2458,7 @@ FunctionType::FunctionType(VariableDeclaration const& _varDecl):
break; break;
returnType = arrayType->baseType(); returnType = arrayType->baseType();
m_parameterNames.emplace_back(""); m_parameterNames.emplace_back("");
m_parameterTypes.push_back(TypeProvider::integerType(256)); m_parameterTypes.push_back(TypeProvider::uint256());
} }
else else
break; break;
@ -3454,24 +3454,24 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const
case Kind::Block: case Kind::Block:
return MemberList::MemberMap({ return MemberList::MemberMap({
{"coinbase", TypeProvider::payableAddressType()}, {"coinbase", TypeProvider::payableAddressType()},
{"timestamp", TypeProvider::integerType(256)}, {"timestamp", TypeProvider::uint256()},
{"blockhash", TypeProvider::functionType(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)}, {"blockhash", TypeProvider::functionType(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)},
{"difficulty", TypeProvider::integerType(256)}, {"difficulty", TypeProvider::uint256()},
{"number", TypeProvider::integerType(256)}, {"number", TypeProvider::uint256()},
{"gaslimit", TypeProvider::integerType(256)} {"gaslimit", TypeProvider::uint256()}
}); });
case Kind::Message: case Kind::Message:
return MemberList::MemberMap({ return MemberList::MemberMap({
{"sender", TypeProvider::payableAddressType()}, {"sender", TypeProvider::payableAddressType()},
{"gas", TypeProvider::integerType(256)}, {"gas", TypeProvider::uint256()},
{"value", TypeProvider::integerType(256)}, {"value", TypeProvider::uint256()},
{"data", TypeProvider::arrayType(DataLocation::CallData)}, {"data", TypeProvider::arrayType(DataLocation::CallData)},
{"sig", TypeProvider::fixedBytesType(4)} {"sig", TypeProvider::fixedBytesType(4)}
}); });
case Kind::Transaction: case Kind::Transaction:
return MemberList::MemberMap({ return MemberList::MemberMap({
{"origin", TypeProvider::payableAddressType()}, {"origin", TypeProvider::payableAddressType()},
{"gasprice", TypeProvider::integerType(256)} {"gasprice", TypeProvider::uint256()}
}); });
case Kind::ABI: case Kind::ABI:
return MemberList::MemberMap({ return MemberList::MemberMap({

View File

@ -311,7 +311,7 @@ string ABIFunctions::abiEncodingFunction(
case DataLocation::CallData: case DataLocation::CallData:
if ( if (
fromArray.isByteArray() || fromArray.isByteArray() ||
*fromArray.baseType() == *TypeProvider::integerType() || *fromArray.baseType() == *TypeProvider::uint256() ||
*fromArray.baseType() == FixedBytesType(32) *fromArray.baseType() == FixedBytesType(32)
) )
return abiEncodingFunctionCalldataArrayWithoutCleanup(fromArray, *toArray, _options); return abiEncodingFunctionCalldataArrayWithoutCleanup(fromArray, *toArray, _options);
@ -369,7 +369,7 @@ string ABIFunctions::abiEncodingFunction(
// possible for library calls where we just forward the storage reference // possible for library calls where we just forward the storage reference
solAssert(_options.encodeAsLibraryTypes, ""); solAssert(_options.encodeAsLibraryTypes, "");
solAssert(_options.padded && !_options.dynamicInplace, "Non-padded / inplace encoding for library call requested."); solAssert(_options.padded && !_options.dynamicInplace, "Non-padded / inplace encoding for library call requested.");
solAssert(to == *TypeProvider::integerType(), ""); solAssert(to == *TypeProvider::uint256(), "");
templ("cleanupConvert", "value"); templ("cleanupConvert", "value");
} }
else else
@ -445,7 +445,7 @@ string ABIFunctions::abiEncodingFunctionCalldataArrayWithoutCleanup(
solAssert(fromArrayType.location() == DataLocation::CallData, ""); solAssert(fromArrayType.location() == DataLocation::CallData, "");
solAssert( solAssert(
fromArrayType.isByteArray() || fromArrayType.isByteArray() ||
*fromArrayType.baseType() == *TypeProvider::integerType() || *fromArrayType.baseType() == *TypeProvider::uint256() ||
*fromArrayType.baseType() == FixedBytesType(32), *fromArrayType.baseType() == FixedBytesType(32),
""); "");
solAssert(fromArrayType.calldataStride() == toArrayType.memoryStride(), ""); solAssert(fromArrayType.calldataStride() == toArrayType.memoryStride(), "");

View File

@ -45,7 +45,7 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons
// stack layout: [source_ref] [source length] target_ref (top) // stack layout: [source_ref] [source length] target_ref (top)
solAssert(_targetType.location() == DataLocation::Storage, ""); solAssert(_targetType.location() == DataLocation::Storage, "");
TypePointer uint256 = TypeProvider::integerType(256); TypePointer uint256 = TypeProvider::uint256();
TypePointer targetBaseType = _targetType.isByteArray() ? uint256 : _targetType.baseType(); TypePointer targetBaseType = _targetType.isByteArray() ? uint256 : _targetType.baseType();
TypePointer sourceBaseType = _sourceType.isByteArray() ? uint256 : _sourceType.baseType(); TypePointer sourceBaseType = _sourceType.isByteArray() ? uint256 : _sourceType.baseType();
@ -585,7 +585,7 @@ void ArrayUtils::clearArray(ArrayType const& _typeIn) const
ArrayUtils(_context).convertLengthToSize(_type); ArrayUtils(_context).convertLengthToSize(_type);
_context << Instruction::ADD << Instruction::SWAP1; _context << Instruction::ADD << Instruction::SWAP1;
if (_type.baseType()->storageBytes() < 32) if (_type.baseType()->storageBytes() < 32)
ArrayUtils(_context).clearStorageLoop(TypeProvider::integerType(256)); ArrayUtils(_context).clearStorageLoop(TypeProvider::uint256());
else else
ArrayUtils(_context).clearStorageLoop(_type.baseType()); ArrayUtils(_context).clearStorageLoop(_type.baseType());
_context << Instruction::POP; _context << Instruction::POP;
@ -626,7 +626,7 @@ void ArrayUtils::clearDynamicArray(ArrayType const& _type) const
<< Instruction::SWAP1; << Instruction::SWAP1;
// stack: data_pos_end data_pos // stack: data_pos_end data_pos
if (_type.storageStride() < 32) if (_type.storageStride() < 32)
clearStorageLoop(TypeProvider::integerType(256)); clearStorageLoop(TypeProvider::uint256());
else else
clearStorageLoop(_type.baseType()); clearStorageLoop(_type.baseType());
// cleanup // cleanup
@ -733,7 +733,7 @@ void ArrayUtils::resizeDynamicArray(ArrayType const& _typeIn) const
ArrayUtils(_context).convertLengthToSize(_type); ArrayUtils(_context).convertLengthToSize(_type);
_context << Instruction::DUP2 << Instruction::ADD << Instruction::SWAP1; _context << Instruction::DUP2 << Instruction::ADD << Instruction::SWAP1;
// stack: ref new_length current_length first_word data_location_end data_location // stack: ref new_length current_length first_word data_location_end data_location
ArrayUtils(_context).clearStorageLoop(TypeProvider::integerType(256)); ArrayUtils(_context).clearStorageLoop(TypeProvider::uint256());
_context << Instruction::POP; _context << Instruction::POP;
// stack: ref new_length current_length first_word // stack: ref new_length current_length first_word
solAssert(_context.stackHeight() - stackHeightStart == 4 - 2, "3"); solAssert(_context.stackHeight() - stackHeightStart == 4 - 2, "3");
@ -772,7 +772,7 @@ void ArrayUtils::resizeDynamicArray(ArrayType const& _typeIn) const
_context << Instruction::SWAP2 << Instruction::ADD; _context << Instruction::SWAP2 << Instruction::ADD;
// stack: ref new_length delete_end delete_start // stack: ref new_length delete_end delete_start
if (_type.storageStride() < 32) if (_type.storageStride() < 32)
ArrayUtils(_context).clearStorageLoop(TypeProvider::integerType(256)); ArrayUtils(_context).clearStorageLoop(TypeProvider::uint256());
else else
ArrayUtils(_context).clearStorageLoop(_type.baseType()); ArrayUtils(_context).clearStorageLoop(_type.baseType());

View File

@ -186,7 +186,7 @@ void CompilerUtils::loadFromMemoryDynamic(
void CompilerUtils::storeInMemory(unsigned _offset) void CompilerUtils::storeInMemory(unsigned _offset)
{ {
unsigned numBytes = prepareMemoryStore(*TypeProvider::integerType(), true); unsigned numBytes = prepareMemoryStore(*TypeProvider::uint256(), true);
if (numBytes > 0) if (numBytes > 0)
m_context << u256(_offset) << Instruction::MSTORE; m_context << u256(_offset) << Instruction::MSTORE;
} }
@ -200,7 +200,7 @@ void CompilerUtils::storeInMemoryDynamic(Type const& _type, bool _padToWordBound
ref->location() == DataLocation::Memory, ref->location() == DataLocation::Memory,
"Only in-memory reference type can be stored." "Only in-memory reference type can be stored."
); );
storeInMemoryDynamic(*TypeProvider::integerType(), _padToWordBoundaries); storeInMemoryDynamic(*TypeProvider::uint256(), _padToWordBoundaries);
} }
else if (auto str = dynamic_cast<StringLiteralType const*>(&_type)) else if (auto str = dynamic_cast<StringLiteralType const*>(&_type))
{ {
@ -316,7 +316,7 @@ void CompilerUtils::abiDecode(TypePointers const& _typeParameters, bool _fromMem
if (calldataType->isDynamicallySized()) if (calldataType->isDynamicallySized())
{ {
// put on stack: data_pointer length // put on stack: data_pointer length
loadFromMemoryDynamic(*TypeProvider::integerType(), !_fromMemory); loadFromMemoryDynamic(*TypeProvider::uint256(), !_fromMemory);
m_context << Instruction::SWAP1; m_context << Instruction::SWAP1;
// stack: input_end base_offset next_pointer data_offset // stack: input_end base_offset next_pointer data_offset
m_context.appendInlineAssembly("{ if gt(data_offset, 0x100000000) { revert(0, 0) } }", {"data_offset"}); m_context.appendInlineAssembly("{ if gt(data_offset, 0x100000000) { revert(0, 0) } }", {"data_offset"});
@ -327,7 +327,7 @@ void CompilerUtils::abiDecode(TypePointers const& _typeParameters, bool _fromMem
{"input_end", "base_offset", "next_ptr", "array_head_ptr"} {"input_end", "base_offset", "next_ptr", "array_head_ptr"}
); );
// retrieve length // retrieve length
loadFromMemoryDynamic(*TypeProvider::integerType(), !_fromMemory, true); loadFromMemoryDynamic(*TypeProvider::uint256(), !_fromMemory, true);
// stack: input_end base_offset next_pointer array_length data_pointer // stack: input_end base_offset next_pointer array_length data_pointer
m_context << Instruction::SWAP2; m_context << Instruction::SWAP2;
// stack: input_end base_offset data_pointer array_length next_pointer // stack: input_end base_offset data_pointer array_length next_pointer
@ -483,7 +483,7 @@ void CompilerUtils::encodeToMemory(
{ {
auto const& strType = dynamic_cast<StringLiteralType const&>(*_givenTypes[i]); auto const& strType = dynamic_cast<StringLiteralType const&>(*_givenTypes[i]);
m_context << u256(strType.value().size()); m_context << u256(strType.value().size());
storeInMemoryDynamic(*TypeProvider::integerType(), true); storeInMemoryDynamic(*TypeProvider::uint256(), true);
// stack: ... <end_of_mem'> // stack: ... <end_of_mem'>
storeInMemoryDynamic(strType, _padToWordBoundaries); storeInMemoryDynamic(strType, _padToWordBoundaries);
} }
@ -498,7 +498,7 @@ void CompilerUtils::encodeToMemory(
m_context << dupInstruction(1 + arrayType.sizeOnStack()); m_context << dupInstruction(1 + arrayType.sizeOnStack());
ArrayUtils(m_context).retrieveLength(arrayType, 1); ArrayUtils(m_context).retrieveLength(arrayType, 1);
// stack: ... <end_of_mem> <value...> <end_of_mem'> <length> // stack: ... <end_of_mem> <value...> <end_of_mem'> <length>
storeInMemoryDynamic(*TypeProvider::integerType(), true); storeInMemoryDynamic(*TypeProvider::uint256(), true);
// stack: ... <end_of_mem> <value...> <end_of_mem''> // stack: ... <end_of_mem> <value...> <end_of_mem''>
// copy the new memory pointer // copy the new memory pointer
m_context << swapInstruction(arrayType.sizeOnStack() + 1) << Instruction::POP; m_context << swapInstruction(arrayType.sizeOnStack() + 1) << Instruction::POP;
@ -869,7 +869,7 @@ void CompilerUtils::convertType(
allocateMemory(storageSize); allocateMemory(storageSize);
// stack: mempos // stack: mempos
m_context << Instruction::DUP1 << u256(data.size()); m_context << Instruction::DUP1 << u256(data.size());
storeInMemoryDynamic(*TypeProvider::integerType()); storeInMemoryDynamic(*TypeProvider::uint256());
// stack: mempos datapos // stack: mempos datapos
storeStringData(data); storeStringData(data);
} }
@ -918,7 +918,7 @@ void CompilerUtils::convertType(
if (targetType.isDynamicallySized()) if (targetType.isDynamicallySized())
{ {
m_context << Instruction::DUP2; m_context << Instruction::DUP2;
storeInMemoryDynamic(*TypeProvider::integerType()); storeInMemoryDynamic(*TypeProvider::uint256());
} }
// stack: <mem start> <source ref> (variably sized) <length> <mem data pos> // stack: <mem start> <source ref> (variably sized) <length> <mem data pos>
if (targetType.baseType()->isValueType()) if (targetType.baseType()->isValueType())
@ -1321,7 +1321,7 @@ void CompilerUtils::storeStringData(bytesConstRef _data)
for (unsigned i = 0; i < _data.size(); i += 32) for (unsigned i = 0; i < _data.size(); i += 32)
{ {
m_context << h256::Arith(h256(_data.cropped(i), h256::AlignLeft)); m_context << h256::Arith(h256(_data.cropped(i), h256::AlignLeft));
storeInMemoryDynamic(*TypeProvider::integerType()); storeInMemoryDynamic(*TypeProvider::uint256());
} }
m_context << Instruction::POP; m_context << Instruction::POP;
} }

View File

@ -82,7 +82,7 @@ public:
/// @returns the number of bytes consumed in memory. /// @returns the number of bytes consumed in memory.
unsigned loadFromMemory( unsigned loadFromMemory(
unsigned _offset, unsigned _offset,
Type const& _type = *TypeProvider::integerType(), Type const& _type = *TypeProvider::uint256(),
bool _fromCalldata = false, bool _fromCalldata = false,
bool _padToWords = false bool _padToWords = false
); );

View File

@ -648,7 +648,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
_functionCall.expression().accept(*this); _functionCall.expression().accept(*this);
arguments.front()->accept(*this); arguments.front()->accept(*this);
utils().convertType(*arguments.front()->annotation().type, *TypeProvider::integerType(), true); utils().convertType(*arguments.front()->annotation().type, *TypeProvider::uint256(), true);
// Note that function is not the original function, but the ".gas" function. // Note that function is not the original function, but the ".gas" function.
// Its values of gasSet and valueSet is equal to the original function's though. // Its values of gasSet and valueSet is equal to the original function's though.
unsigned stackDepth = (function.gasSet() ? 1 : 0) + (function.valueSet() ? 1 : 0); unsigned stackDepth = (function.gasSet() ? 1 : 0) + (function.valueSet() ? 1 : 0);
@ -836,13 +836,13 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
case FunctionType::Kind::MulMod: case FunctionType::Kind::MulMod:
{ {
arguments[2]->accept(*this); arguments[2]->accept(*this);
utils().convertType(*arguments[2]->annotation().type, *TypeProvider::integerType()); utils().convertType(*arguments[2]->annotation().type, *TypeProvider::uint256());
m_context << Instruction::DUP1 << Instruction::ISZERO; m_context << Instruction::DUP1 << Instruction::ISZERO;
m_context.appendConditionalInvalid(); m_context.appendConditionalInvalid();
for (unsigned i = 1; i < 3; i ++) for (unsigned i = 1; i < 3; i ++)
{ {
arguments[2 - i]->accept(*this); arguments[2 - i]->accept(*this);
utils().convertType(*arguments[2 - i]->annotation().type, *TypeProvider::integerType()); utils().convertType(*arguments[2 - i]->annotation().type, *TypeProvider::uint256());
} }
if (function.kind() == FunctionType::Kind::AddMod) if (function.kind() == FunctionType::Kind::AddMod)
m_context << Instruction::ADDMOD; m_context << Instruction::ADDMOD;
@ -928,7 +928,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
// Fetch requested length. // Fetch requested length.
arguments[0]->accept(*this); arguments[0]->accept(*this);
utils().convertType(*arguments[0]->annotation().type, *TypeProvider::integerType()); utils().convertType(*arguments[0]->annotation().type, *TypeProvider::uint256());
// Stack: requested_length // Stack: requested_length
utils().fetchFreeMemoryPointer(); utils().fetchFreeMemoryPointer();
@ -1543,7 +1543,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
TypePointers{keyType} TypePointers{keyType}
); );
m_context << Instruction::SWAP1; m_context << Instruction::SWAP1;
utils().storeInMemoryDynamic(*TypeProvider::integerType()); utils().storeInMemoryDynamic(*TypeProvider::uint256());
utils().toSizeAfterFreeMemoryPointer(); utils().toSizeAfterFreeMemoryPointer();
} }
else else
@ -1552,7 +1552,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
appendExpressionCopyToMemory(*keyType, *_indexAccess.indexExpression()); appendExpressionCopyToMemory(*keyType, *_indexAccess.indexExpression());
m_context << Instruction::SWAP1; m_context << Instruction::SWAP1;
solAssert(CompilerUtils::freeMemoryPointer >= 0x40, ""); solAssert(CompilerUtils::freeMemoryPointer >= 0x40, "");
utils().storeInMemoryDynamic(*TypeProvider::integerType()); utils().storeInMemoryDynamic(*TypeProvider::uint256());
m_context << u256(0); m_context << u256(0);
} }
m_context << Instruction::KECCAK256; m_context << Instruction::KECCAK256;
@ -1565,7 +1565,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
solAssert(_indexAccess.indexExpression(), "Index expression expected."); solAssert(_indexAccess.indexExpression(), "Index expression expected.");
_indexAccess.indexExpression()->accept(*this); _indexAccess.indexExpression()->accept(*this);
utils().convertType(*_indexAccess.indexExpression()->annotation().type, *TypeProvider::integerType(), true); utils().convertType(*_indexAccess.indexExpression()->annotation().type, *TypeProvider::uint256(), true);
// stack layout: <base_ref> [<length>] <index> // stack layout: <base_ref> [<length>] <index>
switch (arrayType.location()) switch (arrayType.location())
{ {
@ -1632,7 +1632,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
solAssert(_indexAccess.indexExpression(), "Index expression expected."); solAssert(_indexAccess.indexExpression(), "Index expression expected.");
_indexAccess.indexExpression()->accept(*this); _indexAccess.indexExpression()->accept(*this);
utils().convertType(*_indexAccess.indexExpression()->annotation().type, *TypeProvider::integerType(), true); utils().convertType(*_indexAccess.indexExpression()->annotation().type, *TypeProvider::uint256(), true);
// stack layout: <value> <index> // stack layout: <value> <index>
// check out-of-bounds access // check out-of-bounds access
m_context << u256(fixedBytesType.numBytes()); m_context << u256(fixedBytesType.numBytes());

View File

@ -1206,7 +1206,7 @@ void SMTChecker::assignment(VariableDeclaration const& _variable, smt::Expressio
if (type->category() == Type::Category::Integer) if (type->category() == Type::Category::Integer)
addOverflowTarget(OverflowTarget::Type::All, type, _value, _location); addOverflowTarget(OverflowTarget::Type::All, type, _value, _location);
else if (type->category() == Type::Category::Address) else if (type->category() == Type::Category::Address)
addOverflowTarget(OverflowTarget::Type::All, TypeProvider::integerType(160), _value, _location); addOverflowTarget(OverflowTarget::Type::All, TypeProvider::uint(160), _value, _location);
else if (type->category() == Type::Category::Mapping) else if (type->category() == Type::Category::Mapping)
arrayAssignment(); arrayAssignment();
m_interface->addAssertion(newValue(_variable) == _value); m_interface->addAssertion(newValue(_variable) == _value);

View File

@ -120,7 +120,7 @@ pair<bool, shared_ptr<SymbolicVariable>> dev::solidity::newSymbolicVariable(
if (!isSupportedTypeDeclaration(_type)) if (!isSupportedTypeDeclaration(_type))
{ {
abstract = true; abstract = true;
var = make_shared<SymbolicIntVariable>(TypeProvider::integerType(256), _uniqueName, _solver); var = make_shared<SymbolicIntVariable>(TypeProvider::uint256(), _uniqueName, _solver);
} }
else if (isBool(_type.category())) else if (isBool(_type.category()))
var = make_shared<SymbolicBoolVariable>(type, _uniqueName, _solver); var = make_shared<SymbolicBoolVariable>(type, _uniqueName, _solver);
@ -143,7 +143,7 @@ pair<bool, shared_ptr<SymbolicVariable>> dev::solidity::newSymbolicVariable(
auto rational = dynamic_cast<RationalNumberType const*>(&_type); auto rational = dynamic_cast<RationalNumberType const*>(&_type);
solAssert(rational, ""); solAssert(rational, "");
if (rational->isFractional()) if (rational->isFractional())
var = make_shared<SymbolicIntVariable>(TypeProvider::integerType(256), _uniqueName, _solver); var = make_shared<SymbolicIntVariable>(TypeProvider::uint256(), _uniqueName, _solver);
else else
var = make_shared<SymbolicIntVariable>(type, _uniqueName, _solver); var = make_shared<SymbolicIntVariable>(type, _uniqueName, _solver);
} }

View File

@ -103,7 +103,7 @@ SymbolicAddressVariable::SymbolicAddressVariable(
string _uniqueName, string _uniqueName,
smt::SolverInterface& _interface smt::SolverInterface& _interface
): ):
SymbolicIntVariable(TypeProvider::integerType(160), move(_uniqueName), _interface) SymbolicIntVariable(TypeProvider::uint(160), move(_uniqueName), _interface)
{ {
} }
@ -112,7 +112,7 @@ SymbolicFixedBytesVariable::SymbolicFixedBytesVariable(
string _uniqueName, string _uniqueName,
smt::SolverInterface& _interface smt::SolverInterface& _interface
): ):
SymbolicIntVariable(TypeProvider::integerType(_numBytes * 8), move(_uniqueName), _interface) SymbolicIntVariable(TypeProvider::uint(_numBytes * 8), move(_uniqueName), _interface)
{ {
} }

View File

@ -233,7 +233,7 @@ BOOST_AUTO_TEST_CASE(encoded_sizes)
ArrayType const* uint24Array = TypeProvider::arrayType( ArrayType const* uint24Array = TypeProvider::arrayType(
DataLocation::Memory, DataLocation::Memory,
TypeProvider::integerType(24), TypeProvider::uint(24),
9 9
); );
BOOST_CHECK_EQUAL(uint24Array->calldataEncodedSize(true), 9 * 32); BOOST_CHECK_EQUAL(uint24Array->calldataEncodedSize(true), 9 * 32);