Browse Source

Dynamic gas requirements for premined crypto contracts.

cl-refactor
Gav Wood 10 years ago
parent
commit
774abf0d54
  1. 7
      alethzero/MainWin.cpp
  2. 2
      libethcore/CommonEth.cpp
  3. 14
      libethereum/Executive.cpp
  4. 11
      libethereum/State.cpp
  5. 5
      libethereum/State.h
  6. 4
      libevm/FeeStructure.cpp

7
alethzero/MainWin.cpp

@ -1263,7 +1263,10 @@ void Main::on_blocks_currentItemChanged()
s << "<br/>Nonce: <b>" << info.nonce << "</b>";
s << "<br/>Hash w/o nonce: <b>" << info.headerHashWithoutNonce() << "</b>";
s << "<br/>Difficulty: <b>" << info.difficulty << "</b>";
s << "<br/>Proof-of-Work: <b>" << ProofOfWork::eval(info.headerHashWithoutNonce(), info.nonce) << " &lt;= " << (h256)u256((bigint(1) << 256) / info.difficulty) << "</b>";
if (info.number)
s << "<br/>Proof-of-Work: <b>" << ProofOfWork::eval(info.headerHashWithoutNonce(), info.nonce) << " &lt;= " << (h256)u256((bigint(1) << 256) / info.difficulty) << "</b>";
else
s << "<br/>Proof-of-Work: <i>Phil need prove nothing</i>";
s << "<br/>Parent: <b>" << info.parentHash << "</b>";
// s << "<br/>Bloom: <b>" << details.bloom << "</b>";
s << "<br/>Log Bloom: <b>" << info.logBloom << "</b>";
@ -1280,7 +1283,7 @@ void Main::on_blocks_currentItemChanged()
if (info.parentHash)
s << "<br/>Pre: <b>" << BlockInfo(ethereum()->blockChain().block(info.parentHash)).stateRoot << "</b>";
else
s << "<br/>Pre: <i>Nothing is before the Gensesis</i>";
s << "<br/>Pre: <i>Nothing is before Phil</i>";
for (auto const& i: block[1])
s << "<br/>" << sha3(i.data()).abridged();// << ": <b>" << i[1].toHash<h256>() << "</b> [<b>" << i[2].toInt<u256>() << "</b> used]";
s << "<br/>Post: <b>" << info.stateRoot << "</b>";

2
libethcore/CommonEth.cpp

@ -33,7 +33,7 @@ namespace dev
namespace eth
{
const unsigned c_protocolVersion = 48;
const unsigned c_protocolVersion = 49;
const unsigned c_databaseVersion = 5;
static const vector<pair<u256, string>> g_units =

14
libethereum/Executive.cpp

@ -110,7 +110,19 @@ bool Executive::call(Address _receiveAddress, Address _senderAddress, u256 _valu
// cnote << "Transferring" << formatBalance(_value) << "to receiver.";
m_s.addBalance(_receiveAddress, _value);
if (m_s.addressHasCode(_receiveAddress))
auto it = !(_receiveAddress & ~h160(0xffffffff)) ? State::precompiled().find((unsigned)(u160)_receiveAddress) : State::precompiled().end();
if (it != State::precompiled().end())
{
if (_gas < it->second.gas(_data))
{
m_endGas = 0;
return false;
}
m_endGas = (u256)(_gas - it->second.gas(_data));
it->second.exec(_data, bytesRef());
return true;
}
else if (m_s.addressHasCode(_receiveAddress))
{
m_vm = new VM(_gas);
bytes const& c = m_s.code(_receiveAddress);

11
libethereum/State.cpp

@ -89,9 +89,9 @@ void ripemd160Code(bytesConstRef _in, bytesRef _out)
const std::map<unsigned, PrecompiledAddress> State::c_precompiled =
{
{ 1, { 500, ecrecoverCode }},
{ 2, { 100, sha256Code }},
{ 3, { 100, ripemd160Code }}
{ 1, { [](bytesConstRef){ return (bigint)500; }, ecrecoverCode }},
{ 2, { [](bytesConstRef i){ return (bigint)50 + (i.size() + 31) / 32 * 50; }, sha256Code }},
{ 3, { [](bytesConstRef i){ return (bigint)50 + (i.size() + 31) / 32 * 50; }, ripemd160Code }}
};
OverlayDB State::openDB(std::string _path, bool _killExisting)
@ -1202,13 +1202,13 @@ bool State::call(Address _receiveAddress, Address _codeAddress, Address _senderA
auto it = !(_codeAddress & ~h160(0xffffffff)) ? c_precompiled.find((unsigned)(u160)_codeAddress) : c_precompiled.end();
if (it != c_precompiled.end())
{
if (*_gas < it->second.gas)
if (*_gas < it->second.gas(_data))
{
*_gas = 0;
return false;
}
*_gas -= it->second.gas;
*_gas -= (u256)it->second.gas(_data);
it->second.exec(_data, _out);
}
else if (addressHasCode(_codeAddress))
@ -1274,7 +1274,6 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
// Execute init code.
VM vm(*_gas);
ExtVM evm(*this, newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _code, o_ms, _level);
bool revert = false;
bytesConstRef out;
try

5
libethereum/State.h

@ -55,7 +55,7 @@ struct StateDetail: public LogChannel { static const char* name() { return "/S/"
struct PrecompiledAddress
{
unsigned gas;
std::function<bigint(bytesConstRef)> gas;
std::function<void(bytesConstRef, bytesRef)> exec;
};
@ -259,6 +259,9 @@ public:
/// the block since all state changes are ultimately reversed.
void cleanup(bool _fullCommit);
/// Info on precompiled contract accounts baked into the protocol.
static std::map<unsigned, PrecompiledAddress> const& precompiled() { return c_precompiled; }
private:
/// Undo the changes to the state for committing to mine.
void uncommitToMine();

4
libevm/FeeStructure.cpp

@ -27,8 +27,8 @@ 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_sha3Gas = 10;
u256 const dev::eth::c_sha3WordGas = 10;
u256 const dev::eth::c_sloadGas = 20;
u256 const dev::eth::c_sstoreSetGas = 300;
u256 const dev::eth::c_sstoreResetGas = 100;

Loading…
Cancel
Save