30 auto offset =
static_cast<size_t>(*_sp--);
31 s512 bigIndex = *_sp--;
32 auto index =
static_cast<size_t>(bigIndex);
33 auto size =
static_cast<size_t>(*_sp--);
35 size_t sizeToBeCopied = bigIndex +
size > _data.
size() ? _data.
size() < bigIndex ? 0 : _data.
size() - index :
size;
37 if (sizeToBeCopied > 0)
38 std::memcpy(m_mem.data() + offset, _data.
data() + index, sizeToBeCopied);
39 if (
size > sizeToBeCopied)
40 std::memset(m_mem.data() + offset + sizeToBeCopied, 0,
size - sizeToBeCopied);
46 void VM::throwOutOfGas()
48 BOOST_THROW_EXCEPTION(OutOfGas());
51 void VM::throwBadInstruction()
56 void VM::throwBadJumpDestination()
61 void VM::throwBadStack(
unsigned _size,
unsigned _removed,
unsigned _added)
69 if (_size - _removed + _added > 1024)
77 int64_t VM::verifyJumpDest(
u256 const& _dest,
bool _throw)
81 if (_dest <= 0x7FFFFFFFFFFFFFFF) {
85 uint64_t pc = uint64_t(_dest);
86 if (std::binary_search(m_jumpDests.begin(), m_jumpDests.end(), pc))
90 throwBadJumpDestination();
101 m_bounce = &VM::interpretCases;
102 m_newMemSize = memNeed(*(m_SP - 1), *(m_SP - 2));
103 m_runGas = toInt63(m_schedule->createGas);
108 auto const& endowment = *m_SP--;
109 uint64_t initOff = (uint64_t)*m_SP--;
110 uint64_t initSize = (uint64_t)*m_SP--;
114 if (m_ext->balance(m_ext->myAddress) >= endowment && m_ext->depth < 1024)
117 u256 createGas = *io_gas;
118 if (!m_schedule->staticCallDepthLimit())
119 createGas -= createGas / 64;
120 u256 gas = createGas;
121 *++m_SP = (
u160)m_ext->create(endowment, gas,
bytesConstRef(m_mem.data() + initOff, initSize), m_onOp);
122 *io_gas -= (createGas - gas);
123 m_io_gas = uint64_t(*io_gas);
132 m_bounce = &VM::interpretCases;
135 if (caseCallSetup(callParams.get(), output))
137 if (boost::optional<owning_bytes_ref> r = m_ext->call(*callParams))
147 m_io_gas += uint64_t(callParams->gas);
153 m_runGas = toInt63(m_schedule->callGas);
155 if (m_OP == Instruction::CALL && !m_ext->exists(
asAddress(*(m_SP - 1))))
156 if (*(m_SP - 2) > 0 || m_schedule->zeroValueTransferChargesNewAccountGas())
157 m_runGas += toInt63(m_schedule->callNewAccountGas);
159 if (m_OP != Instruction::DELEGATECALL && *(m_SP - 2) > 0)
160 m_runGas += toInt63(m_schedule->callValueTransferGas);
162 size_t sizesOffset = m_OP == Instruction::DELEGATECALL ? 3 : 4;
163 u256 inputOffset = m_stack[(1 + m_SP - m_stack) - sizesOffset];
164 u256 inputSize = m_stack[(1 + m_SP - m_stack) - sizesOffset - 1];
165 u256 outputOffset = m_stack[(1 + m_SP - m_stack) - sizesOffset - 2];
166 u256 outputSize = m_stack[(1 + m_SP - m_stack) - sizesOffset - 3];
167 uint64_t inputMemNeed = memNeed(inputOffset, inputSize);
168 uint64_t outputMemNeed = memNeed(outputOffset, outputSize);
170 m_newMemSize =
std::max(inputMemNeed, outputMemNeed);
175 if (m_schedule->staticCallDepthLimit())
177 callParams->
gas = *m_SP;
181 u256 maxAllowedCallGas = m_io_gas - m_io_gas / 64;
182 callParams->
gas =
std::min(*m_SP, maxAllowedCallGas);
185 m_runGas = toInt63(callParams->gas);
189 if (m_OP != Instruction::DELEGATECALL && *(m_SP - 2) > 0)
190 callParams->gas += m_schedule->callStipend;
193 callParams->codeAddress =
asAddress(*m_SP);
196 if (m_OP == Instruction::DELEGATECALL)
198 callParams->apparentValue = m_ext->value;
199 callParams->valueTransfer = 0;
203 callParams->apparentValue = callParams->valueTransfer = *m_SP;
207 uint64_t inOff = (uint64_t)*m_SP--;
208 uint64_t inSize = (uint64_t)*m_SP--;
209 uint64_t outOff = (uint64_t)*m_SP--;
210 uint64_t outSize = (uint64_t)*m_SP--;
212 if (m_ext->balance(m_ext->myAddress) >= callParams->valueTransfer && m_ext->depth < 1024)
214 callParams->onOp = m_onOp;
215 callParams->senderAddress = m_OP == Instruction::DELEGATECALL ? m_ext->caller : m_ext->myAddress;
216 callParams->receiveAddress = m_OP == Instruction::CALL ? callParams->codeAddress : m_ext->myAddress;
217 callParams->data =
bytesConstRef(m_mem.data() + inOff, inSize);
218 o_output =
bytesRef(m_mem.data() + outOff, outSize);
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>> bigint
std::hash for asio::adress
Ran out of stack executing code of the transaction.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 160, 160, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u160
vector_ref< byte > bytesRef
vector_ref< byte const > bytesConstRef
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
uint8_t const size_t const size
void * memcpy(void *a, const void *b, size_t c)
Address asAddress(u256 _item)
void copyTo(vector_ref< typename std::remove_const< _T >::type > _t) const
Copies the contents of this vector_ref to the contents of _t, up to the max size of _t...
dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b)
boost::tuple< errinfo_required, errinfo_got > RequirementError
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 512, 512, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void >> s512