From 1769356fdf3d6fbcef24646e518a0f368ceffb5f Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 2 May 2014 01:44:33 +0100 Subject: [PATCH] State fix. --- alethzero/MainWin.cpp | 3 --- libethereum/Executive.cpp | 2 +- libethereum/State.cpp | 15 +++++++++++++++ libethereum/VM.h | 4 ++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 007ad9676..4559646cf 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -975,12 +975,9 @@ void Main::initDebugger() dc->clear(); if (m_currentExecution) { - for (unsigned i = 0; i < m_currentExecution->ext().code.size(); ++i) - cnote << i << std::hex << (int)m_currentExecution->ext().code[i]; for (unsigned i = 0; i <= m_currentExecution->ext().code.size(); ++i) { byte b = i < m_currentExecution->ext().code.size() ? m_currentExecution->ext().code[i] : 0; - cnote << i << std::hex << (int)b; QString s = c_instructionInfo.at((Instruction)b).name; m_pcWarp[i] = dc->count(); ostringstream out; diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 1e6a873f6..31dd211d0 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -117,7 +117,7 @@ void Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _g // Execute _init. m_vm = new VM(_gas); - m_ext = new ExtVM(m_s, m_newAddress, _sender, _origin, _endowment, _gasPrice, _init, _init); + m_ext = new ExtVM(m_s, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init); } bool Executive::go(uint64_t _steps) diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 490825875..a0d1a0e0e 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -358,9 +358,17 @@ u256 State::playbackRaw(bytesConstRef _block, BlockInfo const& _grandParent, boo unsigned i = 0; for (auto const& tr: RLP(_block)[1]) { +// cnote << m_state.root() << m_state; +// cnote << *this; execute(tr[0].data()); if (tr[1].toInt() != m_state.root()) + { + // Invalid state root + cnote << m_state.root() << m_state; + cnote << *this; + cnote << "INVALID: " << tr[1].toInt(); throw InvalidTransactionStateRoot(); + } if (tr[2].toInt() != gasUsed()) throw InvalidTransactionGasUsed(); if (_fullCommit) @@ -657,6 +665,9 @@ bytes const& State::code(Address _contract) const u256 State::execute(bytesConstRef _rlp) { + cnote << m_state.root() << m_state; + cnote << *this; + Executive e(*this); e.setup(_rlp); @@ -669,6 +680,10 @@ u256 State::execute(bytesConstRef _rlp) commit(); + cnote << "Done TX"; + cnote << m_state.root() << m_state; + cnote << *this; + // Add to the user-originated transactions that we've executed. m_transactions.push_back(TransactionReceipt(e.t(), m_state.root(), startGasUSed + e.gasUsed())); m_transactionSet.insert(e.t().sha3()); diff --git a/libethereum/VM.h b/libethereum/VM.h index 2d3b8fffb..79e193b65 100644 --- a/libethereum/VM.h +++ b/libethereum/VM.h @@ -332,7 +332,7 @@ template eth::bytesConstRef eth::VM::go(Ext& _ext, uint64_t _steps) m_stack.pop_back(); unsigned l = (unsigned)m_stack.back(); m_stack.pop_back(); - unsigned el = cf + l > _ext.data.size() ? _ext.data.size() - cf : l; + unsigned el = cf + l > _ext.data.size() ? _ext.data.size() < cf ? 0 : _ext.data.size() - cf : l; memcpy(m_temp.data() + mf, _ext.data.data() + cf, el); memset(m_temp.data() + mf + el, 0, l - el); break; @@ -349,7 +349,7 @@ template eth::bytesConstRef eth::VM::go(Ext& _ext, uint64_t _steps) m_stack.pop_back(); unsigned l = (unsigned)m_stack.back(); m_stack.pop_back(); - unsigned el = cf + l > _ext.code.size() ? _ext.code.size() - cf : l; + unsigned el = cf + l > _ext.code.size() ? _ext.code.size() < cf ? 0 : _ext.code.size() - cf : l; memcpy(m_temp.data() + mf, _ext.code.data() + cf, el); memset(m_temp.data() + mf + el, 0, l - el); break;