Browse Source

Merge branch 'develop' into develop-evmcc

cl-refactor
Paweł Bylica 10 years ago
parent
commit
f55a8e8b73
  1. 21
      libdevcrypto/EC.cpp
  2. 2
      libethcore/CommonEth.cpp
  3. 2
      libevm/ExtVMFace.h
  4. 3
      libevm/FeeStructure.cpp
  5. 3
      libevm/FeeStructure.h
  6. 3
      libevm/VM.h
  7. 3
      libserpent/compiler.cpp
  8. 3
      libweb3jsonrpc/WebThreeStubServer.cpp
  9. 4
      libwhisper/Common.cpp
  10. 12
      libwhisper/Common.h
  11. 2
      libwhisper/Message.h

21
libdevcrypto/EC.cpp

@ -37,6 +37,8 @@ using namespace dev::crypto;
using namespace CryptoPP;
using namespace pp;
static const int c_publicKeySize = 65; // Public key size for I/O is 65 bytes (there's an extra byte that we don't really need).
void crypto::toPublic(Secret const& _s, Public& o_public)
{
exponentToPublic(Integer(_s.data(), sizeof(_s)), o_public);
@ -143,7 +145,7 @@ bool crypto::verify(Public const& _p, Signature const& _sig, bytesConstRef _mess
byte dersig[c_derMaxEncodingLength];
size_t cssz = DSAConvertSignatureFormat(dersig, c_derMaxEncodingLength, DSA_DER, _sig.data(), 64, DSA_P1363);
assert(cssz <= c_derMaxEncodingLength);
return (1 == secp256k1_ecdsa_verify(_message.data(), _message.size(), dersig, cssz, encpub, 65));
return (1 == secp256k1_ecdsa_verify(_message.data(), _message.size(), dersig, cssz, encpub, c_publicKeySize));
}
ECDSA<ECP, SHA3_256>::Verifier verifier;
@ -155,9 +157,9 @@ Public crypto::recover(Signature _signature, bytesConstRef _message)
{
secp256k1_start();
int pubkeylen = 65;
byte pubkey[pubkeylen];
if (!secp256k1_ecdsa_recover_compact(_message.data(), 32, _signature.data(), pubkey, &pubkeylen, 0, (int)_signature[64]))
byte pubkey[c_publicKeySize];
int keySize;
if (!secp256k1_ecdsa_recover_compact(_message.data(), 32, _signature.data(), pubkey, &keySize, 0, (int)_signature[64]) || keySize != c_publicKeySize)
return Public();
#if ETH_CRYPTO_TRACE
@ -180,13 +182,14 @@ bool crypto::verifySecret(Secret const& _s, Public const& _p)
if (!ok)
return false;
int pubkeylen = 65;
byte pubkey[pubkeylen];
ok = secp256k1_ecdsa_pubkey_create(pubkey, &pubkeylen, _s.data(), 0);
if (!ok || pubkeylen != 65)
byte pubkey[c_publicKeySize];
int keySize;
ok = secp256k1_ecdsa_pubkey_create(pubkey, &keySize, _s.data(), 0);
if (!ok || keySize != c_publicKeySize)
return false;
ok = secp256k1_ecdsa_pubkey_verify(pubkey, 65);
ok = secp256k1_ecdsa_pubkey_verify(pubkey, c_publicKeySize);
if (!ok)
return false;

2
libethcore/CommonEth.cpp

@ -34,7 +34,7 @@ namespace dev
namespace eth
{
const unsigned c_protocolVersion = 40;
const unsigned c_protocolVersion = 41;
const unsigned c_databaseVersion = 4;
static const vector<pair<u256, string>> g_units =

2
libevm/ExtVMFace.h

@ -49,7 +49,7 @@ using LogBloom = h512;
struct LogEntry
{
LogEntry() {}
LogEntry(RLP const& _r) { address = (Address)_r[0]; topics = (h256Set)_r[1]; data = (bytes)_r[2]; }
LogEntry(RLP const& _r) { address = (Address)_r[0]; topics = (h256Set)_r[1]; data = _r[2].toBytes(); }
LogEntry(Address const& _address, h256s const& _ts, bytes&& _d): address(_address), topics(toSet(_ts)), data(std::move(_d)) {}
void streamRLP(RLPStream& _s) const { _s.appendList(3) << address << topics << data; }

3
libevm/FeeStructure.cpp

@ -37,3 +37,6 @@ u256 const dev::eth::c_callGas = 20;
u256 const dev::eth::c_memoryGas = 1;
u256 const dev::eth::c_txDataGas = 5;
u256 const dev::eth::c_txGas = 500;
u256 const dev::eth::c_logGas = 32;
u256 const dev::eth::c_logDataGas = 1;
u256 const dev::eth::c_logTopicGas = 32;

3
libevm/FeeStructure.h

@ -40,6 +40,9 @@ extern u256 const c_callGas; ///< Once per CALL operation & message call trans
extern u256 const c_memoryGas; ///< Times the address of the (highest referenced byte in memory + 1). NOTE: referencing happens on read, write and in instructions such as RETURN and CALL.
extern u256 const c_txDataGas; ///< Per byte of data attached to a transaction. NOTE: Not payable on data of calls between transactions.
extern u256 const c_txGas; ///< Per transaction. NOTE: Not payable on data of calls between transactions.
extern u256 const c_logGas; ///< Per LOG* operation.
extern u256 const c_logDataGas; ///< Per byte in a LOG* operation's data.
extern u256 const c_logTopicGas; ///< Multiplied by the * of the LOG*, per LOG transaction. e.g. LOG0 incurs 0 * c_txLogTopicGas, LOG4 incurs 4 * c_txLogTopicGas.
}
}

3
libevm/VM.h

@ -184,7 +184,8 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con
{
unsigned n = (unsigned)inst - (unsigned)Instruction::LOG0;
require(n + 2);
newTempSize = memNeed(m_stack[m_stack.size() - 1 ], m_stack[m_stack.size() - 2]);
runGas = c_logGas + c_logTopicGas * n + c_logDataGas * m_stack[m_stack.size() - 2];
newTempSize = memNeed(m_stack[m_stack.size() - 1], m_stack[m_stack.size() - 2]);
break;
}

3
libserpent/compiler.cpp

@ -131,8 +131,7 @@ programData opcodeify(Node node,
}
// Declare variable
else {
Node nodelist[] = { };
return pd(aux, multiToken(nodelist, 0, m), 0);
return pd(aux, multiToken(nullptr, 0, m), 0);
}
}
// Define functions (TODO: eventually move to rewriter.cpp, keep

3
libweb3jsonrpc/WebThreeStubServer.cpp

@ -271,14 +271,13 @@ static Json::Value toJson(h256 const& _h, shh::Envelope const& _e, shh::Message
res["ttl"] = (int)_e.ttl();
res["workProved"] = (int)_e.workProved();
for (auto const& t: _e.topics())
res["topics"].append(toJS((u256)t));
res["topics"].append(toJS(t));
res["payload"] = toJS(_m.payload());
res["from"] = toJS(_m.from());
res["to"] = toJS(_m.to());
return res;
}
WebThreeStubServer::WebThreeStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDirect& _web3, std::vector<dev::KeyPair> const& _accounts):
AbstractWebThreeStubServer(_conn),
m_web3(_web3)

4
libwhisper/Common.cpp

@ -33,7 +33,7 @@ Topic BuildTopic::toTopic() const
Topic ret;
ret.reserve(m_parts.size());
for (auto const& h: m_parts)
ret.push_back((TopicPart)u256(h));
ret.push_back(TopicPart(h));
return ret;
}
@ -69,7 +69,7 @@ TopicMask BuildTopicMask::toTopicMask() const
TopicMask ret;
ret.reserve(m_parts.size());
for (auto const& h: m_parts)
ret.push_back(make_pair((TopicPart)u256(h), h ? ~(uint32_t)0 : 0));
ret.push_back(make_pair(TopicPart(h), h ? ~TopicPart() : TopicPart()));
return ret;
}

12
libwhisper/Common.h

@ -59,7 +59,7 @@ enum WhisperPacket
PacketCount
};
using TopicPart = uint32_t;
using TopicPart = FixedHash<4>;
using Topic = std::vector<TopicPart>;
@ -92,7 +92,15 @@ public:
TopicFilter() {}
TopicFilter(TopicMask const& _m): m_topicMasks(1, _m) {}
TopicFilter(TopicMasks const& _m): m_topicMasks(_m) {}
TopicFilter(RLP const& _r): m_topicMasks(_r.toVector<std::vector<std::pair<uint32_t, uint32_t>>>()) {}
TopicFilter(RLP const& _r)//: m_topicMasks(_r.toVector<std::vector<>>())
{
for (RLP i: _r)
{
m_topicMasks.push_back(TopicMask());
for (RLP j: i)
m_topicMasks.back().push_back(j.toPair<FixedHash<4>, FixedHash<4>>());
}
}
void streamRLP(RLPStream& _s) const { _s << m_topicMasks; }
h256 sha3() const;

2
libwhisper/Message.h

@ -55,7 +55,7 @@ public:
{
m_expiry = _m[0].toInt<unsigned>();
m_ttl = _m[1].toInt<unsigned>();
m_topic = _m[2].toVector<uint32_t>();
m_topic = _m[2].toVector<FixedHash<4>>();
m_data = _m[3].toBytes();
m_nonce = _m[4].toInt<u256>();
}

Loading…
Cancel
Save