Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into poc-8
Browse files Browse the repository at this point in the history
  • Loading branch information
gavofyork committed Feb 24, 2015
2 parents be5c8b7 + f1996c6 commit 72f598f
Show file tree
Hide file tree
Showing 16 changed files with 291 additions and 73 deletions.
2 changes: 1 addition & 1 deletion alethzero/MainWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,7 @@ void Main::on_net_triggered()
{
web3()->setIdealPeerCount(ui->idealPeers->value());
web3()->setNetworkPreferences(netPrefs());
ethereum()->setNetworkId(m_privateChain.size() ? sha3(m_privateChain.toStdString()) : 0);
ethereum()->setNetworkId(m_privateChain.size() ? sha3(m_privateChain.toStdString()) : h256());
// TODO: p2p
// if (m_networkConfig.size()/* && ui->usePast->isChecked()*/)
// web3()->restoreNetwork(bytesConstRef((byte*)m_networkConfig.data(), m_networkConfig.size()));
Expand Down
2 changes: 1 addition & 1 deletion libdevcore/FixedHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class FixedHash
operator Arith() const { return fromBigEndian<Arith>(m_data); }

/// @returns true iff this is the empty hash.
operator bool() const { return ((Arith)*this) != 0; }
explicit operator bool() const { return ((Arith)*this) != 0; }

// The obvious comparison operators.
bool operator==(FixedHash const& _c) const { return m_data == _c.m_data; }
Expand Down
2 changes: 1 addition & 1 deletion libdevcrypto/CryptoPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bool Secp256k1::verify(Signature const& _signature, bytesConstRef _message)
bool Secp256k1::verify(Public const& _p, Signature const& _sig, bytesConstRef _message, bool _hashed)
{
// todo: verify w/o recovery (if faster)
return _p == _hashed ? recover(_sig, _message) : recover(_sig, sha3(_message).ref());
return (bool)_p == _hashed ? (bool)recover(_sig, _message) : (bool)recover(_sig, sha3(_message).ref());
}

Public Secp256k1::recover(Signature _signature, bytesConstRef _message)
Expand Down
2 changes: 1 addition & 1 deletion libethcore/ProofOfWork.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ template <class Evaluator>
std::pair<MineInfo, h256> ProofOfWorkEngine<Evaluator>::mine(h256 const& _root, u256 const& _difficulty, unsigned _msTimeout, bool _continue, bool _turbo)
{
std::pair<MineInfo, h256> ret;
static std::mt19937_64 s_eng((time(0) + (unsigned)m_last));
static std::mt19937_64 s_eng((time(0) + *reinterpret_cast<unsigned*>(m_last.data())));
u256 s = (m_last = h256::random(s_eng));

bigint d = (bigint(1) << 256) / _difficulty;
Expand Down
2 changes: 1 addition & 1 deletion libethereum/EthereumHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class EthereumHost: public p2p::HostCapability<EthereumPeer>, Worker
h256Set neededBlocks(h256Set const& _exclude);

/// Check to see if the network peer-state initialisation has happened.
bool isInitialised() const { return m_latestBlockSent; }
bool isInitialised() const { return (bool)m_latestBlockSent; }

/// Initialises the network peer-state, doing the stuff that needs to be once-only. @returns true if it really was first.
bool ensureInitialised();
Expand Down
2 changes: 1 addition & 1 deletion libethereum/Transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Transaction
Address safeSender() const noexcept;

/// @returns true if transaction is non-null.
operator bool() const { return m_type != NullTransaction; }
explicit operator bool() const { return m_type != NullTransaction; }

/// @returns true if transaction is contract-creation.
bool isCreation() const { return m_type == ContractCreation; }
Expand Down
12 changes: 11 additions & 1 deletion libsolidity/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,17 @@ void MemberAccess::checkTypeRequirements()
if (!m_type)
BOOST_THROW_EXCEPTION(createTypeError("Member \"" + *m_memberName + "\" not found or not "
"visible in " + type.toString()));
m_isLValue = (type.getCategory() == Type::Category::Struct);
// This should probably move somewhere else.
if (type.getCategory() == Type::Category::Struct)
m_isLValue = true;
else if (type.getCategory() == Type::Category::Array)
{
auto const& arrayType(dynamic_cast<ArrayType const&>(type));
m_isLValue = (*m_memberName == "length" &&
arrayType.getLocation() != ArrayType::Location::CallData && arrayType.isDynamicallySized());
}
else
m_isLValue = false;
}

void IndexAccess::checkTypeRequirements()
Expand Down
7 changes: 6 additions & 1 deletion libsolidity/CompilerContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ void CompilerContext::addMagicGlobal(MagicVariableDeclaration const& _declaratio
void CompilerContext::addStateVariable(VariableDeclaration const& _declaration)
{
m_stateVariables[&_declaration] = m_stateVariablesSize;
m_stateVariablesSize += _declaration.getType()->getStorageSize();
bigint newSize = bigint(m_stateVariablesSize) + _declaration.getType()->getStorageSize();
if (newSize >= bigint(1) << 256)
BOOST_THROW_EXCEPTION(TypeError()
<< errinfo_comment("State variable does not fit in storage.")
<< errinfo_sourceLocation(_declaration.getLocation()));
m_stateVariablesSize = u256(newSize);
}

void CompilerContext::startFunction(Declaration const& _function)
Expand Down
96 changes: 69 additions & 27 deletions libsolidity/ExpressionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,19 +534,25 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
{
solAssert(member == "length", "Illegal array member.");
auto const& type = dynamic_cast<ArrayType const&>(*_memberAccess.getExpression().getType());
solAssert(type.isByteArray(), "Non byte arrays not yet implemented here.");
switch (type.getLocation())
if (!type.isDynamicallySized())
{
case ArrayType::Location::CallData:
m_context << eth::Instruction::SWAP1 << eth::Instruction::POP;
break;
case ArrayType::Location::Storage:
m_context << eth::Instruction::SLOAD;
break;
default:
solAssert(false, "Unsupported array location.");
break;
CompilerUtils(m_context).popStackElement(type);
m_context << type.getLength();
}
else
switch (type.getLocation())
{
case ArrayType::Location::CallData:
m_context << eth::Instruction::SWAP1 << eth::Instruction::POP;
break;
case ArrayType::Location::Storage:
m_currentLValue = LValue(m_context, LValue::LValueType::Storage, _memberAccess.getType());
m_currentLValue.retrieveValueIfLValueNotRequested(_memberAccess);
break;
default:
solAssert(false, "Unsupported array location.");
break;
}
break;
}
default:
Expand All @@ -559,19 +565,55 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
_indexAccess.getBaseExpression().accept(*this);

Type const& baseType = *_indexAccess.getBaseExpression().getType();
solAssert(baseType.getCategory() == Type::Category::Mapping, "");
Type const& keyType = *dynamic_cast<MappingType const&>(baseType).getKeyType();
m_context << u256(0);
solAssert(_indexAccess.getIndexExpression(), "Index expression expected.");
appendExpressionCopyToMemory(keyType, *_indexAccess.getIndexExpression());
solAssert(baseType.getSizeOnStack() == 1,
"Unexpected: Not exactly one stack slot taken by subscriptable expression.");
m_context << eth::Instruction::SWAP1;
appendTypeMoveToMemory(IntegerType(256));
m_context << u256(0) << eth::Instruction::SHA3;

m_currentLValue = LValue(m_context, LValue::LValueType::Storage, _indexAccess.getType());
m_currentLValue.retrieveValueIfLValueNotRequested(_indexAccess);
if (baseType.getCategory() == Type::Category::Mapping)
{
Type const& keyType = *dynamic_cast<MappingType const&>(baseType).getKeyType();
m_context << u256(0);
solAssert(_indexAccess.getIndexExpression(), "Index expression expected.");
appendExpressionCopyToMemory(keyType, *_indexAccess.getIndexExpression());
solAssert(baseType.getSizeOnStack() == 1,
"Unexpected: Not exactly one stack slot taken by subscriptable expression.");
m_context << eth::Instruction::SWAP1;
appendTypeMoveToMemory(IntegerType(256));
m_context << u256(0) << eth::Instruction::SHA3;
m_currentLValue = LValue(m_context, LValue::LValueType::Storage, _indexAccess.getType());
m_currentLValue.retrieveValueIfLValueNotRequested(_indexAccess);
}
else if (baseType.getCategory() == Type::Category::Array)
{
ArrayType const& arrayType = dynamic_cast<ArrayType const&>(baseType);
solAssert(arrayType.getLocation() == ArrayType::Location::Storage,
"TODO: Index acces only implemented for storage arrays.");
solAssert(!arrayType.isByteArray(), "TODO: Index acces not implemented for byte arrays.");
solAssert(_indexAccess.getIndexExpression(), "Index expression expected.");

_indexAccess.getIndexExpression()->accept(*this);
// retrieve length
if (arrayType.isDynamicallySized())
m_context << eth::Instruction::DUP2 << eth::Instruction::SLOAD;
else
m_context << arrayType.getLength();
// stack: <base_ref> <index> <length>
// check out-of-bounds access
m_context << eth::Instruction::DUP2 << eth::Instruction::LT;
eth::AssemblyItem legalAccess = m_context.appendConditionalJump();
// out-of-bounds access throws exception (just STOP for now)
m_context << eth::Instruction::STOP;

m_context << legalAccess;
// stack: <base_ref> <index>
m_context << arrayType.getBaseType()->getStorageSize() << eth::Instruction::MUL;
if (arrayType.isDynamicallySized())
{
m_context << eth::Instruction::SWAP1;
CompilerUtils(m_context).computeHashStatic();
}
m_context << eth::Instruction::ADD;
m_currentLValue = LValue(m_context, LValue::LValueType::Storage, _indexAccess.getType());
m_currentLValue.retrieveValueIfLValueNotRequested(_indexAccess);
}
else
solAssert(false, "Index access only allowed for mappings or arrays.");

return false;
}
Expand Down Expand Up @@ -1049,7 +1091,7 @@ void ExpressionCompiler::LValue::retrieveValue(Location const& _location, bool _
{
case LValueType::Stack:
{
unsigned stackPos = m_context->baseToCurrentStackOffset(unsigned(m_baseStackOffset));
unsigned stackPos = m_context->baseToCurrentStackOffset(m_baseStackOffset);
if (stackPos >= 15) //@todo correct this by fetching earlier or moving to memory
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Stack too deep."));
Expand Down Expand Up @@ -1098,7 +1140,7 @@ void ExpressionCompiler::LValue::storeValue(Type const& _sourceType, Location co
{
case LValueType::Stack:
{
unsigned stackDiff = m_context->baseToCurrentStackOffset(unsigned(m_baseStackOffset)) - m_size + 1;
unsigned stackDiff = m_context->baseToCurrentStackOffset(m_baseStackOffset) - m_size + 1;
if (stackDiff > 16)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Stack too deep."));
Expand Down Expand Up @@ -1201,7 +1243,7 @@ void ExpressionCompiler::LValue::setToZero(Location const& _location) const
{
case LValueType::Stack:
{
unsigned stackDiff = m_context->baseToCurrentStackOffset(unsigned(m_baseStackOffset));
unsigned stackDiff = m_context->baseToCurrentStackOffset(m_baseStackOffset);
if (stackDiff > 16)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Stack too deep."));
Expand Down
19 changes: 17 additions & 2 deletions libsolidity/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,19 @@ bool ArrayType::operator==(Type const& _other) const
return other.m_location == m_location;
}

u256 ArrayType::getStorageSize() const
{
if (isDynamicallySized())
return 1;
else
{
bigint size = bigint(getLength()) * getBaseType()->getStorageSize();
if (size >= bigint(1) << 256)
BOOST_THROW_EXCEPTION(TypeError() << errinfo_comment("Array too large for storage."));
return max<u256>(1, u256(size));
}
}

unsigned ArrayType::getSizeOnStack() const
{
if (m_location == Location::CallData)
Expand Down Expand Up @@ -665,10 +678,12 @@ bool StructType::operator==(Type const& _other) const

u256 StructType::getStorageSize() const
{
u256 size = 0;
bigint size = 0;
for (pair<string, TypePointer> const& member: getMembers())
size += member.second->getStorageSize();
return max<u256>(1, size);
if (size >= bigint(1) << 256)
BOOST_THROW_EXCEPTION(TypeError() << errinfo_comment("Struct too large for storage."));
return max<u256>(1, u256(size));
}

bool StructType::canLiveOutsideStorage() const
Expand Down
1 change: 1 addition & 0 deletions libsolidity/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ class ArrayType: public Type
virtual TypePointer unaryOperatorResult(Token::Value _operator) const override;
virtual bool operator==(const Type& _other) const override;
virtual bool isDynamicallySized() const { return m_hasDynamicLength; }
virtual u256 getStorageSize() const override;
virtual unsigned getSizeOnStack() const override;
virtual std::string toString() const override;
virtual MemberList const& getMembers() const override { return s_arrayTypeMemberList; }
Expand Down
4 changes: 2 additions & 2 deletions libweb3jsonrpc/WebThreeStubServerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,10 +701,10 @@ std::string WebThreeStubServerBase::eth_transact(Json::Value const& _json)
{
std::string ret;
TransactionSkeleton t = toTransaction(_json);
if (t.creation)
ret = right160(sha3(rlpList(t.from, client()->countAt(t.from))));;
if (!t.from)
t.from = m_accounts->getDefaultTransactAccount();
if (t.creation)
ret = toJS(right160(sha3(rlpList(t.from, client()->countAt(t.from)))));;
if (!t.gasPrice)
t.gasPrice = 10 * dev::eth::szabo;
if (!t.gas)
Expand Down
2 changes: 1 addition & 1 deletion libwhisper/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool TopicFilter::matches(Envelope const& _e) const
for (unsigned i = 0; i < t.size(); ++i)
{
for (auto et: _e.topic())
if (((t[i].first ^ et) & t[i].second) == 0)
if (((t[i].first ^ et) & t[i].second) == CollapsedTopicPart())
goto NEXT_TOPICPART;
// failed to match topicmask against any topics: move on to next mask
goto NEXT_TOPICMASK;
Expand Down
4 changes: 2 additions & 2 deletions mix/ClientModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void ClientModel::onNewTransaction()
QString function;
QString returned;

bool creation = tr.contractAddress != 0;
bool creation = (bool)tr.contractAddress;

//TODO: handle value transfer
FixedHash<4> functionHash;
Expand Down Expand Up @@ -403,7 +403,7 @@ void ClientModel::onNewTransaction()
if (creation)
returned = QString::fromStdString(toJS(tr.contractAddress));

Address contractAddress = tr.address != 0 ? tr.address : tr.contractAddress;
Address contractAddress = (bool)tr.address ? tr.address : tr.contractAddress;
auto contractAddressIter = m_contractNames.find(contractAddress);
if (contractAddressIter != m_contractNames.end())
{
Expand Down

0 comments on commit 72f598f

Please sign in to comment.