From c1bc090104c1d2ca3bbaecb8dd145565d3c8db16 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 13 Nov 2014 15:50:32 +0100 Subject: [PATCH 1/5] Log pricing update. --- libevm/FeeStructure.cpp | 3 +++ libevm/FeeStructure.h | 3 +++ libevm/VM.h | 3 ++- libweb3jsonrpc/WebThreeStubServer.cpp | 3 +-- libwhisper/Common.cpp | 4 ++-- libwhisper/Common.h | 4 ++-- libwhisper/Message.h | 2 +- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libevm/FeeStructure.cpp b/libevm/FeeStructure.cpp index 47236b506..6d868cac5 100644 --- a/libevm/FeeStructure.cpp +++ b/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; diff --git a/libevm/FeeStructure.h b/libevm/FeeStructure.h index 84a2551d9..e57f7ccf8 100644 --- a/libevm/FeeStructure.h +++ b/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. } } diff --git a/libevm/VM.h b/libevm/VM.h index b3a4c2828..d495b6289 100644 --- a/libevm/VM.h +++ b/libevm/VM.h @@ -206,7 +206,8 @@ template 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; } diff --git a/libweb3jsonrpc/WebThreeStubServer.cpp b/libweb3jsonrpc/WebThreeStubServer.cpp index 3849fb4a8..092faae09 100644 --- a/libweb3jsonrpc/WebThreeStubServer.cpp +++ b/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 const& _accounts): AbstractWebThreeStubServer(_conn), m_web3(_web3) diff --git a/libwhisper/Common.cpp b/libwhisper/Common.cpp index 8f58ae994..83f289875 100644 --- a/libwhisper/Common.cpp +++ b/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; } diff --git a/libwhisper/Common.h b/libwhisper/Common.h index 436af8d11..c445ac506 100644 --- a/libwhisper/Common.h +++ b/libwhisper/Common.h @@ -59,7 +59,7 @@ enum WhisperPacket PacketCount }; -using TopicPart = uint32_t; +using TopicPart = FixedHash<4>; using Topic = std::vector; @@ -92,7 +92,7 @@ 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>>()) {} + TopicFilter(RLP const& _r): m_topicMasks(_r.toVector, FixedHash<4>>>>()) {} void streamRLP(RLPStream& _s) const { _s << m_topicMasks; } h256 sha3() const; diff --git a/libwhisper/Message.h b/libwhisper/Message.h index ed26cf145..954aed4a0 100644 --- a/libwhisper/Message.h +++ b/libwhisper/Message.h @@ -55,7 +55,7 @@ public: { m_expiry = _m[0].toInt(); m_ttl = _m[1].toInt(); - m_topic = _m[2].toVector(); + m_topic = _m[2].toVector>(); m_data = _m[3].toBytes(); m_nonce = _m[4].toInt(); } From 26a9bf4ebef500d3ba26f834f264e759a899fa69 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 13 Nov 2014 16:22:52 +0100 Subject: [PATCH 2/5] Version bump. --- libethcore/CommonEth.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethcore/CommonEth.cpp b/libethcore/CommonEth.cpp index 0ebf79669..250761e12 100644 --- a/libethcore/CommonEth.cpp +++ b/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> g_units = From 5f8a974a17233843331e3ba2558514a9322578bd Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 13 Nov 2014 17:35:23 +0100 Subject: [PATCH 3/5] Don't cast to bytes for fear of MSVC's brokenness. --- libevm/ExtVMFace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libevm/ExtVMFace.h b/libevm/ExtVMFace.h index 8a6b2edc9..65761e410 100644 --- a/libevm/ExtVMFace.h +++ b/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; } From b74250c6b40f2eb44bbd918f33c53f84340d51d6 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 13 Nov 2014 17:56:09 +0100 Subject: [PATCH 4/5] Windows fixes(?) --- libdevcrypto/EC.cpp | 21 ++++++++++++--------- libserpent/compiler.cpp | 3 +-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libdevcrypto/EC.cpp b/libdevcrypto/EC.cpp index c35eb17f2..e6e6d2329 100644 --- a/libdevcrypto/EC.cpp +++ b/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::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; diff --git a/libserpent/compiler.cpp b/libserpent/compiler.cpp index 623ab3950..30628fbc9 100644 --- a/libserpent/compiler.cpp +++ b/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 From 50c11a2151e4d76a1d4420f11c77659cae7f87c0 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 13 Nov 2014 18:01:20 +0100 Subject: [PATCH 5/5] Stupid MSVC fixes. --- libwhisper/Common.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libwhisper/Common.h b/libwhisper/Common.h index c445ac506..312cbf6d3 100644 --- a/libwhisper/Common.h +++ b/libwhisper/Common.h @@ -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, FixedHash<4>>>>()) {} + TopicFilter(RLP const& _r)//: m_topicMasks(_r.toVector>()) + { + for (RLP i: _r) + { + m_topicMasks.push_back(TopicMask()); + for (RLP j: i) + m_topicMasks.back().push_back(j.toPair, FixedHash<4>>()); + } + } void streamRLP(RLPStream& _s) const { _s << m_topicMasks; } h256 sha3() const;