From 19c272c32d86ea237e4f579f5babcb5f05f56e08 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 11 Dec 2014 18:25:21 +0100 Subject: [PATCH] Fix for crazy compiler lambda behaviour. --- alethzero/MainWin.cpp | 2 +- libethereum/State.cpp | 11 ++++++----- liblll/CompilerState.cpp | 5 +++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 270147c64..8da2a823b 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -1266,7 +1266,7 @@ void Main::on_blocks_currentItemChanged() if (info.number) s << "
Proof-of-Work: " << ProofOfWork::eval(info.headerHashWithoutNonce(), info.nonce) << " <= " << (h256)u256((bigint(1) << 256) / info.difficulty) << ""; else - s << "
Proof-of-Work: Phil need prove nothing"; + s << "
Proof-of-Work: Phil has nothing to prove"; s << "
Parent: " << info.parentHash << ""; // s << "
Bloom: " << details.bloom << ""; s << "
Log Bloom: " << info.logBloom << ""; diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 093f6fcb4..8664c0c52 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -89,9 +89,9 @@ void ripemd160Code(bytesConstRef _in, bytesRef _out) const std::map State::c_precompiled = { - { 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 }} + { 1, { [](bytesConstRef) -> bigint { return (bigint)500; }, ecrecoverCode }}, + { 2, { [](bytesConstRef i) -> bigint { return (bigint)50 + (i.size() + 31) / 32 * 50; }, sha256Code }}, + { 3, { [](bytesConstRef i) -> bigint { return (bigint)50 + (i.size() + 31) / 32 * 50; }, ripemd160Code }} }; OverlayDB State::openDB(std::string _path, bool _killExisting) @@ -1202,13 +1202,14 @@ 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(_data)) + bigint g = it->second.gas(_data); + if (*_gas < g) { *_gas = 0; return false; } - *_gas -= (u256)it->second.gas(_data); + *_gas -= (u256)g; it->second.exec(_data, _out); } else if (addressHasCode(_codeAddress)) diff --git a/liblll/CompilerState.cpp b/liblll/CompilerState.cpp index c3dc2dda3..63351bc4c 100644 --- a/liblll/CompilerState.cpp +++ b/liblll/CompilerState.cpp @@ -72,6 +72,11 @@ void CompilerState::populateStandard() "(def 'regname (name) { [32]'register [64]name (call allgas namereg 0 32 64 0 0) })" "(def 'regcoin (name) { [32]name (call allgas coinreg 0 32 32 0 0) })" "(def 'regcoin (name denom) { [32]name [64]denom (call allgas coinreg 0 32 64 0 0) })" + "(def 'ecrecover (r s v hash) { [0] r [32] s [64] v [96] hash (msg allgas 1 0 0 128) })" + "(def 'sha256 (data datasize) (msg allgas 2 0 data datasize))" + "(def 'ripemd160 (data datasize) (msg allgas 3 0 data datasize))" + "(def 'sha256 (val) { [0]:val (sha256 0 32) })" + "(def 'ripemd160 (val) { [0]:val (ripemd160 0 32) })" "}"; CodeFragment::compile(s, *this); }