Browse Source

PV49 alterations for creation.

cl-refactor
Gav Wood 10 years ago
parent
commit
49b1039bd7
  1. 35
      libethereum/Executive.cpp
  2. 25
      libethereum/State.cpp
  3. 2
      libevm/FeeStructure.cpp
  4. 2
      libevm/FeeStructure.h
  5. 2
      libevm/VM.h

35
libethereum/Executive.cpp

@ -162,7 +162,6 @@ bool Executive::go(OnOpFunc const& _onOp)
{
boost::timer t;
auto sgas = m_vm->gas();
bool revert = false;
try
{
m_out = m_vm->go(*m_ext, _onOp);
@ -171,7 +170,10 @@ bool Executive::go(OnOpFunc const& _onOp)
m_endGas += min((m_t.gas() - m_endGas) / 2, m_ext->sub.refunds);
m_logs = m_ext->sub.logs;
}
m_endGas = m_vm->gas();
if (m_out.size() * c_createDataGas <= m_endGas)
m_endGas -= m_out.size() * c_createDataGas;
else
m_out.reset();
}
catch (StepsDone const&)
{
@ -181,7 +183,16 @@ bool Executive::go(OnOpFunc const& _onOp)
{
clog(StateChat) << "Safe VM Exception: " << diagnostic_information(_e);
m_endGas = 0;//m_vm->gas();
revert = true;
// Write state out only in the case of a non-excepted transaction.
m_ext->revert();
// Explicitly delete a newly created address - this will still be in the reverted state.
/* if (m_newAddress)
{
m_s.m_cache.erase(m_newAddress);
m_newAddress = Address();
}*/
}
catch (Exception const& _e)
{
@ -194,18 +205,6 @@ bool Executive::go(OnOpFunc const& _onOp)
cwarn << "Unexpected std::exception in VM. This is probably unrecoverable. " << _e.what();
}
cnote << "VM took:" << t.elapsed() << "; gas used: " << (sgas - m_endGas);
// Write state out only in the case of a non-excepted transaction.
if (revert)
{
m_ext->revert();
// Explicitly delete a newly created address - this will still be in the reverted state.
if (m_newAddress)
{
m_s.m_cache.erase(m_newAddress);
m_newAddress = Address();
}
}
}
return true;
}
@ -217,9 +216,11 @@ u256 Executive::gas() const
void Executive::finalize(OnOpFunc const&)
{
if (m_t.isCreation() && m_newAddress && m_out.size())
// non-reverted creation - put code in place.
if (m_t.isCreation() && !m_ext->sub.suicides.count(m_newAddress))
{
// creation - put code in place.
m_s.m_cache[m_newAddress].setCode(m_out);
}
// cnote << "Refunding" << formatBalance(m_endGas * m_ext->gasPrice) << "to origin (=" << m_endGas << "*" << formatBalance(m_ext->gasPrice) << ")";
m_s.addBalance(m_sender, m_endGas * m_t.gasPrice());

25
libethereum/State.cpp

@ -1285,11 +1285,20 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
if (o_sub)
*o_sub += evm.sub;
*_gas = vm.gas();
if (out.size() * c_createDataGas <= *_gas)
*_gas -= out.size() * c_createDataGas;
else
out.reset();
// Set code.
if (!evm.sub.suicides.count(newAddress))
m_cache[newAddress].setCode(out);
}
catch (VMException const& _e)
{
clog(StateChat) << "Safe VM Exception: " << diagnostic_information(_e);
revert = true;
evm.revert();
*_gas = 0;
}
catch (Exception const& _e)
@ -1303,20 +1312,6 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
cwarn << "Unexpected std::exception in VM. This is probably unrecoverable. " << _e.what();
}
// TODO: CHECK: AUDIT: IS THIS CORRECT?! (esp. given account created prior to revertion init.)
// Write state out only in the case of a non-out-of-gas transaction.
if (revert)
{
evm.revert();
m_cache.erase(newAddress);
newAddress = Address();
}
else
// Set code.
if (addressInUse(newAddress))
m_cache[newAddress].setCode(out);
return newAddress;
}

2
libevm/FeeStructure.cpp

@ -28,11 +28,13 @@ using namespace dev::eth;
u256 const dev::eth::c_stepGas = 1;
u256 const dev::eth::c_balanceGas = 20;
u256 const dev::eth::c_sha3Gas = 20;
u256 const dev::eth::c_sha3WordGas = 1;
u256 const dev::eth::c_sloadGas = 20;
u256 const dev::eth::c_sstoreSetGas = 300;
u256 const dev::eth::c_sstoreResetGas = 100;
u256 const dev::eth::c_sstoreRefundGas = 100;
u256 const dev::eth::c_createGas = 100;
u256 const dev::eth::c_createDataGas = 5;
u256 const dev::eth::c_callGas = 20;
u256 const dev::eth::c_expGas = 1;
u256 const dev::eth::c_expByteGas = 1;

2
libevm/FeeStructure.h

@ -31,11 +31,13 @@ namespace eth
extern u256 const c_stepGas; ///< Once per operation, except for SSTORE, SLOAD, BALANCE, SHA3, CREATE, CALL.
extern u256 const c_balanceGas; ///< Once per BALANCE operation.
extern u256 const c_sha3Gas; ///< Once per SHA3 operation.
extern u256 const c_sha3WordGas;
extern u256 const c_sloadGas; ///< Once per SLOAD operation.
extern u256 const c_sstoreSetGas; ///< Once per SSTORE operation if the zeroness changes from zero.
extern u256 const c_sstoreResetGas; ///< Once per SSTORE operation if the zeroness doesn't change.
extern u256 const c_sstoreRefundGas; ///< Refunded gas, once per SSTORE operation if the zeroness changes to zero.
extern u256 const c_createGas; ///< Once per CREATE operation & contract-creation transaction.
extern u256 const c_createDataGas;
extern u256 const c_callGas; ///< Once per CALL operation & message call transaction.
extern u256 const c_expGas; ///< Once per EXP instuction.
extern u256 const c_expByteGas; ///< Times ceil(log256(exponent)) for the EXP instruction.

2
libevm/VM.h

@ -186,7 +186,7 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con
break;
case Instruction::SHA3:
require(2);
runGas = c_sha3Gas;
runGas = c_sha3Gas + (m_stack[m_stack.size() - 2] + 31) / 32 * c_sha3WordGas;
newTempSize = memNeed(m_stack.back(), m_stack[m_stack.size() - 2]);
break;
case Instruction::CALLDATACOPY:

Loading…
Cancel
Save