Clean up and modernize code:

This commit removes obsolete comments, dead or no longer useful
code, and workarounds for several issues that were present in older
compilers that we no longer support.

Specifically:

- It improves the transaction metadata handling class, simplifying
  its use and making it less error-prone.
- It reduces the footprint of the Serializer class by consolidating
  code and leveraging templates.
- It cleanups the ST* class hierarchy, removing dead code, improving
  and consolidating code to reduce complexity and code duplication.
- It shores up the handling of currency codes and the conversation
  between 160-bit currency codes and their string representation.
- It migrates beast::secure_erase to the ripple namespace and uses
  a call to OpenSSL_cleanse instead of the custom implementation.
This commit is contained in:
Nik Bougalis
2020-03-27 14:26:46 -07:00
parent 6c72d5cf7e
commit dbee3f01b7
45 changed files with 244 additions and 703 deletions

View File

@@ -114,7 +114,8 @@ target_sources (xrpl_core PRIVATE
src/ripple/crypto/impl/RFC1751.cpp
src/ripple/crypto/impl/csprng.cpp
src/ripple/crypto/impl/ec_key.cpp
src/ripple/crypto/impl/openssl.cpp)
src/ripple/crypto/impl/openssl.cpp
src/ripple/crypto/impl/secure_erase.cpp)
add_library (Ripple::xrpl_core ALIAS xrpl_core)
target_include_directories (xrpl_core
@@ -168,6 +169,7 @@ install (
src/ripple/crypto/GenerateDeterministicKey.h
src/ripple/crypto/RFC1751.h
src/ripple/crypto/csprng.h
src/ripple/crypto/secure_erase.h
DESTINATION include/ripple/crypto)
install (
FILES
@@ -267,7 +269,6 @@ install (
src/ripple/beast/crypto/detail/ripemd_context.h
src/ripple/beast/crypto/detail/sha2_context.h
src/ripple/beast/crypto/ripemd.h
src/ripple/beast/crypto/secure_erase.h
src/ripple/beast/crypto/sha2.h
DESTINATION include/ripple/beast/crypto)
install (

View File

@@ -78,8 +78,8 @@ proposalUniqueId(
Slice const& signature)
{
Serializer s(512);
s.add256(proposeHash);
s.add256(previousLedger);
s.addBitString(proposeHash);
s.addBitString(previousLedger);
s.add32(proposeSeq);
s.add32(closeTime.time_since_epoch().count());
s.addVL(publicKey);

View File

@@ -179,7 +179,7 @@ handleNewValidation(
s << (val->isTrusted() ? "trusted" : "untrusted") << " "
<< (val->isFull() ? "full" : "partial") << " validation: " << hash
<< " from " << id << " via " << source << ": " << msg << "\n"
<< " [" << val->getSerializer().getHex() << "]";
<< " [" << val->getSerializer().slice() << "]";
};
if (!val->isFieldPresent(sfLedgerSequence))

View File

@@ -51,10 +51,6 @@ class Transaction;
// Tracks the current ledger and any ledgers in the process of closing
// Tracks ledger history
// Tracks held transactions
// VFALCO TODO Rename to Ledgers
// It sounds like this holds all the ledgers...
//
class LedgerMaster : public Stoppable, public AbstractFetchPackContainer
{
public:

View File

@@ -779,14 +779,11 @@ main(int argc, char** argv)
_ftime(&t);
#endif
}
ripple::sha512_deprecatedMSVCWorkaround();
#endif
atexit(&google::protobuf::ShutdownProtobufLibrary);
auto const result(ripple::run(argc, argv));
beast::basic_seconds_clock_main_hook();
return result;
}

View File

@@ -29,12 +29,11 @@
namespace ripple {
// VFALCO NOTE Are these the flags?? Why aren't we using a packed struct?
// VFALCO TODO convert these macros to int constants
// VFALCO NOTE How can both bad and good be set on a hash?
// TODO convert these macros to int constants or an enum
#define SF_BAD 0x02 // Temporarily bad
#define SF_SAVED 0x04
#define SF_TRUSTED 0x10 // comes from trusted source
// Private flags, used internally in apply.cpp.
// Do not attempt to read, set, or reuse.
#define SF_PRIVATE1 0x0100

View File

@@ -253,7 +253,8 @@ public:
};
// client information retrieval functions
using AccountTx = std::pair<std::shared_ptr<Transaction>, TxMeta::pointer>;
using AccountTx =
std::pair<std::shared_ptr<Transaction>, std::shared_ptr<TxMeta>>;
using AccountTxs = std::vector<AccountTx>;
virtual AccountTxs

View File

@@ -105,10 +105,6 @@ private:
first.
@return `true` if the file was opened.
*/
// VFALCO NOTE The parameter is unfortunately a boost type because it
// can be either wchar or char based depending on platform.
// TODO Replace with beast::File
//
bool
open(boost::filesystem::path const& path);

View File

@@ -43,13 +43,11 @@ namespace ripple {
@note Callers must not modify data objects that are stored in the cache
unless they hold their own lock over all cache operations.
*/
// VFALCO TODO Figure out how to pass through the allocator
template <
class Key,
class T,
class Hash = hardened_hash<>,
class KeyEqual = std::equal_to<Key>,
// class Allocator = std::allocator <std::pair <Key const, Entry>>,
class Mutex = std::recursive_mutex>
class TaggedCache
{
@@ -57,9 +55,6 @@ public:
using mutex_type = Mutex;
using key_type = Key;
using mapped_type = T;
// VFALCO TODO Use std::shared_ptr, std::weak_ptr
using weak_mapped_ptr = std::weak_ptr<mapped_type>;
using mapped_ptr = std::shared_ptr<mapped_type>;
using clock_type = beast::abstract_clock<std::chrono::steady_clock>;
public:
@@ -180,7 +175,7 @@ public:
// Keep references to all the stuff we sweep
// so that we can destroy them outside the lock.
//
std::vector<mapped_ptr> stuffToSweep;
std::vector<std::shared_ptr<mapped_type>> stuffToSweep;
{
clock_type::time_point const now(m_clock.now());
@@ -211,7 +206,7 @@ public:
stuffToSweep.reserve(m_cache.size());
cache_iterator cit = m_cache.begin();
auto cit = m_cache.begin();
while (cit != m_cache.end())
{
@@ -273,7 +268,7 @@ public:
// removed from cache
std::lock_guard lock(m_mutex);
cache_iterator cit = m_cache.find(key);
auto cit = m_cache.find(key);
if (cit == m_cache.end())
return false;
@@ -322,7 +317,7 @@ private:
// Return values: true=we had the data already
std::lock_guard lock(m_mutex);
cache_iterator cit = m_cache.find(key);
auto cit = m_cache.find(key);
if (cit == m_cache.end())
{
@@ -352,7 +347,7 @@ private:
return true;
}
mapped_ptr cachedData = entry.lock();
auto cachedData = entry.lock();
if (cachedData)
{
@@ -399,12 +394,12 @@ public:
// fetch us a shared pointer to the stored data object
std::lock_guard lock(m_mutex);
cache_iterator cit = m_cache.find(key);
auto cit = m_cache.find(key);
if (cit == m_cache.end())
{
++m_misses;
return mapped_ptr();
return {};
}
Entry& entry = cit->second;
@@ -427,7 +422,7 @@ public:
m_cache.erase(cit);
++m_misses;
return mapped_ptr();
return {};
}
/** Insert the element into the container.
@@ -437,7 +432,7 @@ public:
bool
insert(key_type const& key, T const& value)
{
mapped_ptr p(std::make_shared<T>(std::cref(value)));
auto p = std::make_shared<T>(std::cref(value));
return canonicalize_replace_client(key, p);
}
@@ -450,7 +445,7 @@ public:
retrieve(const key_type& key, T& data)
{
// retrieve the value of the stored data
mapped_ptr entry = fetch(key);
auto entry = fetch(key);
if (!entry)
return false;
@@ -472,9 +467,7 @@ public:
// If present, make current in cache
std::lock_guard lock(m_mutex);
cache_iterator cit = m_cache.find(key);
if (cit != m_cache.end())
if (auto cit = m_cache.find(key); cit != m_cache.end())
{
Entry& entry = cit->second;
@@ -504,10 +497,6 @@ public:
found = true;
}
}
else
{
// not present
}
return found;
}
@@ -573,13 +562,13 @@ private:
class Entry
{
public:
mapped_ptr ptr;
weak_mapped_ptr weak_ptr;
std::shared_ptr<mapped_type> ptr;
std::weak_ptr<mapped_type> weak_ptr;
clock_type::time_point last_access;
Entry(
clock_type::time_point const& last_access_,
mapped_ptr const& ptr_)
std::shared_ptr<mapped_type> const& ptr_)
: ptr(ptr_), weak_ptr(ptr_), last_access(last_access_)
{
}
@@ -599,7 +588,7 @@ private:
{
return weak_ptr.expired();
}
mapped_ptr
std::shared_ptr<mapped_type>
lock()
{
return weak_ptr.lock();
@@ -612,7 +601,6 @@ private:
};
using cache_type = hardened_hash_map<key_type, Entry, Hash, KeyEqual>;
using cache_iterator = typename cache_type::iterator;
beast::Journal m_journal;
clock_type& m_clock;

View File

@@ -134,21 +134,6 @@ public:
} // namespace detail
//------------------------------------------------------------------------------
/** Called before main exits to terminate the utility thread.
This is a workaround for Visual Studio 2013:
http://connect.microsoft.com/VisualStudio/feedback/details/786016/creating-a-global-c-object-that-used-thread-join-in-its-destructor-causes-a-lockup
http://stackoverflow.com/questions/10915233/stdthreadjoin-hangs-if-called-after-main-exits-when-using-vs2012-rc
*/
inline void
basic_seconds_clock_main_hook()
{
#ifdef _MSC_VER
detail::seconds_clock_thread::instance().stop();
#endif
}
/** A clock whose minimum resolution is one second.
The purpose of this class is to optimize the performance of the now()

View File

@@ -20,8 +20,8 @@
#ifndef BEAST_CRYPTO_MAC_FACADE_H_INCLUDED
#define BEAST_CRYPTO_MAC_FACADE_H_INCLUDED
#include <ripple/beast/crypto/secure_erase.h>
#include <ripple/beast/hash/endian.h>
#include <ripple/crypto/secure_erase.h>
#include <array>
#include <type_traits>

View File

@@ -1,89 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_CRYPTO_SECURE_ERASE_H_INCLUDED
#define BEAST_CRYPTO_SECURE_ERASE_H_INCLUDED
#include <cstddef>
#include <cstdint>
#include <new>
namespace beast {
namespace detail {
class secure_erase_impl
{
private:
struct base
{
virtual void
operator()(void* dest, std::size_t bytes) const = 0;
virtual ~base() = default;
base() = default;
base(base const&) = delete;
base&
operator=(base const&) = delete;
};
struct impl : base
{
void
operator()(void* dest, std::size_t bytes) const override
{
char volatile* volatile p =
const_cast<volatile char*>(reinterpret_cast<char*>(dest));
if (bytes == 0)
return;
do
{
*p = 0;
} while (*p++ == 0 && --bytes);
}
};
char buf_[sizeof(impl)];
base& erase_;
public:
secure_erase_impl() : erase_(*new (buf_) impl)
{
}
void
operator()(void* dest, std::size_t bytes) const
{
return erase_(dest, bytes);
}
};
} // namespace detail
/** Guaranteed to fill memory with zeroes */
template <class = void>
void
secure_erase(void* dest, std::size_t bytes)
{
static detail::secure_erase_impl const erase;
erase(dest, bytes);
}
} // namespace beast
#endif

View File

@@ -78,7 +78,6 @@ LoadMonitor::update()
mLatencyMSAvg = 0ms;
mLatencyMSPeak = 0ms;
mLastUpdate = now;
// VFALCO TODO don't return from the middle...
return;
}

View File

@@ -18,14 +18,13 @@
//==============================================================================
#include <ripple/basics/contract.h>
#include <ripple/beast/crypto/secure_erase.h>
#include <ripple/crypto/GenerateDeterministicKey.h>
#include <ripple/crypto/impl/ec_key.h>
#include <ripple/crypto/impl/openssl.h>
#include <ripple/crypto/secure_erase.h>
#include <ripple/protocol/digest.h>
#include <array>
#include <openssl/pem.h>
#include <openssl/sha.h>
#include <string>
namespace ripple {
@@ -101,11 +100,11 @@ generateRootDeterministicKey(uint128 const& seed)
std::copy(seed.begin(), seed.end(), buf.begin());
copy_uint32(buf.begin() + 16, seq++);
auto root = sha512Half(buf);
beast::secure_erase(buf.data(), buf.size());
secure_erase(buf.data(), buf.size());
privKey.assign(root.data(), root.size());
beast::secure_erase(root.data(), root.size());
secure_erase(root.data(), root.size());
} while (privKey.is_zero() || privKey >= secp256k1curve().order);
beast::secure_erase(&seq, sizeof(seq));
secure_erase(&seq, sizeof(seq));
return privKey;
}
@@ -163,9 +162,9 @@ makeHash(Blob const& pubGen, int seq, bignum const& order)
copy_uint32(buf.begin() + 33, seq);
copy_uint32(buf.begin() + 37, subSeq++);
auto root = sha512Half_s(buf);
beast::secure_erase(buf.data(), buf.size());
secure_erase(buf.data(), buf.size());
result.assign(root.data(), root.size());
beast::secure_erase(root.data(), root.size());
secure_erase(root.data(), root.size());
} while (result.is_zero() || result >= order);
return result;

View File

@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Copyright (c) 2020 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -17,24 +17,15 @@
*/
//==============================================================================
#ifndef RIPPLE_NODESTORE_VISITCALLBACK_H_INCLUDED
#define RIPPLE_NODESTORE_VISITCALLBACK_H_INCLUDED
#include <ripple/crypto/secure_erase.h>
#include <openssl/crypto.h>
namespace ripple {
namespace NodeStore {
/** Callback for iterating through objects.
@see visitAll
*/
// VFALCO DEPRECATED Use std::function instead
struct VisitCallback
void
secure_erase(void* dest, std::size_t bytes)
{
virtual void
visitObject(NodeObject::Ptr const& object) = 0;
};
OPENSSL_cleanse(dest, bytes);
}
} // namespace NodeStore
} // namespace ripple
#endif

View File

@@ -0,0 +1,46 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2020 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_CRYPTO_SECURE_ERASE_H_INCLUDED
#define RIPPLE_CRYPTO_SECURE_ERASE_H_INCLUDED
#include <cstddef>
namespace ripple {
/** Attempts to fill memory with zeroes.
The underlying implementation of this function takes pains to
attempt to outsmart compilers from optimizing the zeroization
away. Please note that, despite that, remnants of content may
remain floating around in memory as well as registers, caches
and more.
For a comprehensive treatise on the subject of secure
memory clearing, see:
http://www.daemonology.net/blog/2014-09-04-how-to-zero-a-buffer.html
http://www.daemonology.net/blog/2014-09-06-zeroing-buffers-is-insufficient.html
*/
void
secure_erase(void* dest, std::size_t bytes);
} // namespace ripple
#endif

View File

@@ -29,13 +29,8 @@
namespace ripple {
// VFALCO Move to ripple/app/ledger/detail, rename to TxMeta
class TxMeta
{
public:
using pointer = std::shared_ptr<TxMeta>;
using ref = const pointer&;
private:
struct CtorHelper
{
@@ -49,32 +44,11 @@ private:
CtorHelper);
public:
TxMeta() : mLedger(0), mIndex(static_cast<std::uint32_t>(-1)), mResult(255)
{
}
TxMeta(uint256 const& txID, std::uint32_t ledger, std::uint32_t index)
: mTransactionID(txID)
, mLedger(ledger)
, mIndex(static_cast<std::uint32_t>(-1))
, mResult(255)
{
}
TxMeta(uint256 const& transactionID, std::uint32_t ledger);
TxMeta(uint256 const& txID, std::uint32_t ledger, Blob const&);
TxMeta(uint256 const& txID, std::uint32_t ledger, std::string const&);
TxMeta(uint256 const& txID, std::uint32_t ledger, STObject const&);
void
init(uint256 const& transactionID, std::uint32_t ledger);
void
clear()
{
mNodes.clear();
}
void
swap(TxMeta&) noexcept;
uint256 const&
getTxID()
{
@@ -101,16 +75,12 @@ public:
return mIndex;
}
bool
isNodeAffected(uint256 const&) const;
void
setAffectedNode(uint256 const&, SField const& type, std::uint16_t nodeType);
STObject&
getAffectedNode(SLE::ref node, SField const& type); // create if needed
STObject&
getAffectedNode(uint256 const&);
const STObject&
peekAffectedNode(uint256 const&) const;
/** Return a list of accounts affected by this transaction */
boost::container::flat_set<AccountID>
@@ -151,9 +121,6 @@ public:
return static_cast<bool>(mDelivered);
}
static bool
thread(STObject& node, uint256 const& prevTxID, std::uint32_t prevLgrID);
private:
uint256 mTransactionID;
std::uint32_t mLedger;

View File

@@ -123,9 +123,7 @@ ApplyStateTable::apply(
std::shared_ptr<Serializer> sMeta;
if (!to.open())
{
TxMeta meta;
// VFALCO Shouldn't TxMeta ctor do this?
meta.init(tx.getTransactionID(), to.seq());
TxMeta meta(tx.getTransactionID(), to.seq());
if (deliver)
meta.setDeliveredAmount(*deliver);
Mods newMod;
@@ -526,12 +524,24 @@ ApplyStateTable::threadItem(TxMeta& meta, std::shared_ptr<SLE> const& sle)
{
key_type prevTxID;
LedgerIndex prevLgrID;
if (!sle->thread(meta.getTxID(), meta.getLgrSeq(), prevTxID, prevLgrID))
return;
if (prevTxID.isZero())
return;
TxMeta::thread(
meta.getAffectedNode(sle, sfModifiedNode), prevTxID, prevLgrID);
if (!prevTxID.isZero())
{
auto& node = meta.getAffectedNode(sle, sfModifiedNode);
if (node.getFieldIndex(sfPreviousTxnID) == -1)
{
assert(node.getFieldIndex(sfPreviousTxnLgrSeq) == -1);
node.setFieldH256(sfPreviousTxnID, prevTxID);
node.setFieldU32(sfPreviousTxnLgrSeq, prevLgrID);
}
assert(node.getFieldH256(sfPreviousTxnID) == prevTxID);
assert(node.getFieldU32(sfPreviousTxnLgrSeq) == prevLgrID);
}
}
std::shared_ptr<SLE>

View File

@@ -26,8 +26,6 @@
namespace ripple {
// VFALCO TODO rename class to TransactionMeta
template <class T>
TxMeta::TxMeta(
uint256 const& txid,
@@ -78,16 +76,14 @@ TxMeta::TxMeta(
{
}
bool
TxMeta::isNodeAffected(uint256 const& node) const
TxMeta::TxMeta(uint256 const& transactionID, std::uint32_t ledger)
: mTransactionID(transactionID)
, mLedger(ledger)
, mIndex(static_cast<std::uint32_t>(-1))
, mResult(255)
, mNodes(sfAffectedNodes)
{
for (auto const& n : mNodes)
{
if (n.getFieldH256(sfLedgerIndex) == node)
return true;
}
return false;
mNodes.reserve(32);
}
void
@@ -205,57 +201,6 @@ TxMeta::getAffectedNode(uint256 const& node)
return *(mNodes.begin()); // Silence compiler warning.
}
const STObject&
TxMeta::peekAffectedNode(uint256 const& node) const
{
for (auto const& n : mNodes)
{
if (n.getFieldH256(sfLedgerIndex) == node)
return n;
}
Throw<std::runtime_error>("Affected node not found");
return *(mNodes.begin()); // Silence compiler warning.
}
void
TxMeta::init(uint256 const& id, std::uint32_t ledger)
{
mTransactionID = id;
mLedger = ledger;
mNodes = STArray(sfAffectedNodes, 32);
mDelivered = boost::optional<STAmount>();
}
void
TxMeta::swap(TxMeta& s) noexcept
{
assert((mTransactionID == s.mTransactionID) && (mLedger == s.mLedger));
mNodes.swap(s.mNodes);
}
bool
TxMeta::thread(STObject& node, uint256 const& prevTxID, std::uint32_t prevLgrID)
{
if (node.getFieldIndex(sfPreviousTxnID) == -1)
{
assert(node.getFieldIndex(sfPreviousTxnLgrSeq) == -1);
node.setFieldH256(sfPreviousTxnID, prevTxID);
node.setFieldU32(sfPreviousTxnLgrSeq, prevLgrID);
return true;
}
assert(node.getFieldH256(sfPreviousTxnID) == prevTxID);
assert(node.getFieldU32(sfPreviousTxnLgrSeq) == prevLgrID);
return false;
}
static bool
compare(const STObject& o1, const STObject& o2)
{
return o1.getFieldH256(sfLedgerIndex) < o2.getFieldH256(sfLedgerIndex);
}
STObject
TxMeta::getAsObject() const
{
@@ -276,7 +221,9 @@ TxMeta::addRaw(Serializer& s, TER result, std::uint32_t index)
mIndex = index;
assert((mResult == 0) || ((mResult > 100) && (mResult <= 255)));
mNodes.sort(compare);
mNodes.sort([](STObject const& o1, STObject const& o2) {
return o1.getFieldH256(sfLedgerIndex) < o2.getFieldH256(sfLedgerIndex);
});
getAsObject().add(s);
}

View File

@@ -44,9 +44,9 @@ addRaw(LedgerInfo const& info, Serializer& s)
{
s.add32(info.seq);
s.add64(info.drops.drops());
s.add256(info.parentHash);
s.add256(info.txHash);
s.add256(info.accountHash);
s.addBitString(info.parentHash);
s.addBitString(info.txHash);
s.addBitString(info.accountHash);
s.add32(info.parentCloseTime.time_since_epoch().count());
s.add32(info.closeTime.time_since_epoch().count());
s.add8(info.closeTimeResolution.count());

View File

@@ -778,7 +778,7 @@ DatabaseShardImp::import(Database& source)
s.add32(Shard::version);
s.add32(firstLedgerSeq(shardIndex));
s.add32(lastLedgerSeq(shardIndex));
s.add256(*lastLedgerHash);
s.addBitString(*lastLedgerHash);
auto nObj{NodeObject::createObject(
hotUNKNOWN, std::move(s.modData()), Shard::finalKey)};

View File

@@ -594,7 +594,7 @@ Shard::finalize(const bool writeSQLite)
s.add32(version);
s.add32(firstSeq_);
s.add32(lastSeq_);
s.add256(lastLedgerHash);
s.addBitString(lastLedgerHash);
auto nObj{
NodeObject::createObject(hotUNKNOWN, std::move(s.modData()), finalKey)};
try

View File

@@ -63,9 +63,7 @@ Cluster::update(
{
std::lock_guard lock(mutex_);
// We can't use auto here yet due to the libstdc++ issue
// described at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68190
std::set<ClusterNode, Comparator>::iterator iter = nodes_.find(identity);
auto iter = nodes_.find(identity);
if (iter != nodes_.end())
{

View File

@@ -237,7 +237,7 @@ OverlayImpl::onHandoff(
return handoff;
}
// TODO Validate HTTP request
// Validate HTTP request
{
auto const types = beast::rfc2616::split_commas(request["Connect-As"]);
@@ -1083,14 +1083,13 @@ OverlayImpl::processValidatorList(
{
// If the target is in the form "/vl/<validator_list_public_key>",
// return the most recent validator list for that key.
if (!req.target().starts_with("/vl/") || !setup_.vlEnabled)
constexpr std::string_view prefix("/vl/");
if (!req.target().starts_with(prefix.data()) || !setup_.vlEnabled)
return false;
auto key = req.target();
if (key.starts_with("/vl/"))
key.remove_prefix(strlen("/vl/"));
else
key.remove_prefix(strlen("/unl/"));
auto key = req.target().substr(prefix.size());
if (key.empty())
return false;

View File

@@ -32,7 +32,16 @@ namespace ripple {
@note The list must be sorted in strictly ascending order (and so
it may not contain any duplicates!)
*/
constexpr ProtocolVersion const supportedProtocolList[]{{1, 2}, {2, 0}, {2, 1}};
// clang-format off
constexpr ProtocolVersion const supportedProtocolList[]
{
{1, 2},
{2, 0},
{2, 1}
};
// clang-format on
// This ugly construct ensures that supportedProtocolList is sorted in strictly
// ascending order and doesn't contain any duplicates.

View File

@@ -34,7 +34,7 @@ serializePayChanAuthorization(
XRPAmount const& amt)
{
msg.add32(HashPrefix::paymentChannelClaim);
msg.add256(key);
msg.addBitString(key);
msg.add64(amt.drops());
}

View File

@@ -30,14 +30,9 @@ class STArray final : public STBase, public CountedObject<STArray>
private:
using list_type = std::vector<STObject>;
enum { reserveSize = 8 };
list_type v_;
public:
// Read-only iteration
class Items;
static char const*
getCountedObjectName()
{
@@ -48,7 +43,7 @@ public:
using iterator = list_type::iterator;
using const_iterator = list_type::const_iterator;
STArray();
STArray() = default;
STArray(STArray&&);
STArray(STArray const&) = default;
STArray(SField const& f, int n);

View File

@@ -239,8 +239,6 @@ private:
}
};
enum { reserveSize = 20 };
using list_type = std::vector<detail::STVar>;
list_type v_;
@@ -281,7 +279,7 @@ public:
explicit STObject(SField const& name);
virtual ~STObject();
virtual ~STObject() = default;
STBase*
copy(std::size_t n, void* buf) const override

View File

@@ -26,20 +26,16 @@
#include <ripple/basics/base_uint.h>
#include <ripple/basics/contract.h>
#include <ripple/basics/safe_cast.h>
#include <ripple/beast/crypto/secure_erase.h>
#include <ripple/protocol/HashPrefix.h>
#include <ripple/protocol/SField.h>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <type_traits>
namespace ripple {
class CKey; // forward declaration
class Serializer
{
private:
@@ -83,34 +79,24 @@ public:
// assemble functions
int
add8(unsigned char byte);
int add16(std::uint16_t);
int add32(std::uint32_t); // ledger indexes, account sequence, timestamps
int add32(HashPrefix);
int add64(std::uint64_t); // native currency amounts
add8(unsigned char i);
int
add128(const uint128&); // private key generators
add16(std::uint16_t i);
int
add256(uint256 const&); // transaction and ledger hashes
add32(std::uint32_t i); // ledger indexes, account sequence, timestamps
int
add32(HashPrefix p);
int
add64(std::uint64_t i); // native currency amounts
template <typename Integer>
int addInteger(Integer);
template <int Bits, class Tag>
template <std::size_t Bits, class Tag>
int
addBitString(base_uint<Bits, Tag> const& v)
{
int ret = mData.size();
mData.insert(mData.end(), v.begin(), v.end());
return ret;
}
// TODO(tom): merge with add128 and add256.
template <class Tag>
int
add160(base_uint<160, Tag> const& i)
{
return addBitString<160, Tag>(i);
return addRaw(v.data(), v.size());
}
int
@@ -119,8 +105,6 @@ public:
addRaw(const void* ptr, int len);
int
addRaw(const Serializer& s);
int
addZeros(size_t uBytes);
int
addVL(Blob const& vector);
@@ -135,8 +119,6 @@ public:
// disassemble functions
bool
get8(int&, int offset) const;
bool
get256(uint256&, int offset) const;
template <typename Integer>
bool
@@ -157,7 +139,7 @@ public:
return true;
}
template <int Bits, typename Tag = void>
template <std::size_t Bits, typename Tag = void>
bool
getBitString(base_uint<Bits, Tag>& data, int offset) const
{
@@ -167,24 +149,6 @@ public:
return success;
}
// TODO(tom): merge with get128 and get256.
template <class Tag>
bool
get160(base_uint<160, Tag>& o, int offset) const
{
return getBitString<160, Tag>(o, offset);
}
bool
getRaw(Blob&, int offset, int length) const;
Blob
getRaw(int offset, int length) const;
bool
getVL(Blob& objectVL, int offset, int& length) const;
bool
getVLLength(int& length, int offset) const;
int
addFieldID(int type, int name);
int
@@ -240,12 +204,6 @@ public:
return std::string(static_cast<const char*>(getDataPtr()), size());
}
void
secureErase()
{
beast::secure_erase(mData.data(), mData.size());
mData.clear();
}
void
erase()
{
mData.clear();
@@ -311,19 +269,6 @@ public:
return v.mData != mData;
}
std::string
getHex() const
{
std::stringstream h;
for (unsigned char const& element : mData)
{
h << std::setw(2) << std::hex << std::setfill('0')
<< safe_cast<unsigned int>(element);
}
return h.str();
}
static int
decodeLengthLength(int b1);
static int
@@ -334,11 +279,6 @@ public:
decodeVLLength(int b1, int b2, int b3);
private:
static int
lengthVL(int length)
{
return length + encodeLengthLength(length);
}
static int
encodeLengthLength(int length); // length to encode length
int
@@ -414,7 +354,7 @@ public:
std::uint64_t
get64();
template <int Bits, class Tag = void>
template <std::size_t Bits, class Tag = void>
base_uint<Bits, Tag>
getBitString();
@@ -467,7 +407,7 @@ public:
getRawHelper(int size);
};
template <int Bits, class Tag>
template <std::size_t Bits, class Tag>
base_uint<Bits, Tag>
SerialIter::getBitString()
{

View File

@@ -84,7 +84,7 @@ startMultiSigningData(STObject const& obj);
inline void
finishMultiSigningData(AccountID const& signingID, Serializer& s)
{
s.add160(signingID);
s.addBitString(signingID);
}
} // namespace ripple

View File

@@ -81,11 +81,22 @@ isXRP(Currency const& c)
std::string
to_string(Currency const& c);
/** Tries to convert a string to a Currency, returns true on success. */
/** Tries to convert a string to a Currency, returns true on success.
@note This function will return success if the resulting currency is
badCurrency(). This legacy behavior is unfortunate; changing this
will require very careful checking everywhere and may mean having
to rewrite some unit test code.
*/
bool
to_currency(Currency&, std::string const&);
/** Tries to convert a string to a Currency, returns noCurrency() on failure. */
/** Tries to convert a string to a Currency, returns noCurrency() on failure.
@note This function can return badCurrency(). This legacy behavior is
unfortunate; changing this will require very careful checking
everywhere and may mean having to rewrite some unit test code.
*/
Currency
to_currency(std::string const&);

View File

@@ -208,7 +208,7 @@ private:
inline void erase(std::true_type)
{
beast::secure_erase(&h_, sizeof(h_));
secure_erase(&h_, sizeof(h_));
}
};
@@ -221,16 +221,6 @@ using sha512_half_hasher_s = detail::basic_sha512_half_hasher<true>;
//------------------------------------------------------------------------------
#ifdef _MSC_VER
// Call from main to fix magic statics pre-VS2015
inline void
sha512_deprecatedMSVCWorkaround()
{
beast::sha512_hasher h;
auto const digest = static_cast<beast::sha512_hasher::result_type>(h);
}
#endif
/** Returns the SHA512-Half of a series of objects. */
template <class... Args>
sha512_half_hasher::result_type

View File

@@ -624,8 +624,8 @@ STAmount::add(Serializer& s) const
(static_cast<std::uint64_t>(mOffset + 512 + 256 + 97)
<< (64 - 10)));
s.add160(mIssue.currency);
s.add160(mIssue.account);
s.addBitString(mIssue.currency);
s.addBitString(mIssue.account);
}
}

View File

@@ -24,14 +24,6 @@
namespace ripple {
STArray::STArray()
{
// VFALCO NOTE We need to determine if this is
// the right thing to do, and consider
// making it optional.
// v_.reserve(reserveSize);
}
STArray::STArray(STArray&& other)
: STBase(other.getFName()), v_(std::move(other.v_))
{
@@ -52,7 +44,6 @@ STArray::STArray(int n)
STArray::STArray(SField const& f) : STBase(f)
{
v_.reserve(reserveSize);
}
STArray::STArray(SField const& f, int n) : STBase(f)

View File

@@ -26,15 +26,6 @@
namespace ripple {
STObject::~STObject()
{
#if 0
// Turn this on to get a histogram on exit
static Log log;
log(v_.size());
#endif
}
STObject::STObject(STObject&& other)
: STBase(other.getFName()), v_(std::move(other.v_)), mType(other.mType)
{
@@ -42,8 +33,6 @@ STObject::STObject(STObject&& other)
STObject::STObject(SField const& name) : STBase(name), mType(nullptr)
{
// VFALCO TODO See if this is the right thing to do
// v_.reserve(reserveSize);
}
STObject::STObject(SOTemplate const& type, SField const& name) : STBase(name)

View File

@@ -202,13 +202,13 @@ STPathSet::add(Serializer& s) const
s.add8(iType);
if (iType & STPathElement::typeAccount)
s.add160(speElement.getAccountID());
s.addBitString(speElement.getAccountID());
if (iType & STPathElement::typeCurrency)
s.add160(speElement.getCurrency());
s.addBitString(speElement.getCurrency());
if (iType & STPathElement::typeIssuer)
s.add160(speElement.getIssuerID());
s.addBitString(speElement.getIssuerID());
}
first = false;

View File

@@ -19,10 +19,10 @@
#include <ripple/basics/contract.h>
#include <ripple/basics/strHex.h>
#include <ripple/beast/crypto/secure_erase.h>
#include <ripple/beast/utility/rngfill.h>
#include <ripple/crypto/GenerateDeterministicKey.h>
#include <ripple/crypto/csprng.h>
#include <ripple/crypto/secure_erase.h>
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/digest.h>
#include <ripple/protocol/impl/secp256k1.h>
@@ -33,7 +33,7 @@ namespace ripple {
SecretKey::~SecretKey()
{
beast::secure_erase(buf_, sizeof(buf_));
secure_erase(buf_, sizeof(buf_));
}
SecretKey::SecretKey(std::array<std::uint8_t, 32> const& key)
@@ -86,8 +86,8 @@ public:
auto gpk = generatePublicDeterministicKey(gen_, ordinal);
SecretKey const sk(Slice{gsk.data(), gsk.size()});
PublicKey const pk(Slice{gpk.data(), gpk.size()});
beast::secure_erase(ui.data(), ui.size());
beast::secure_erase(gsk.data(), gsk.size());
secure_erase(ui.data(), ui.size());
secure_erase(gsk.data(), gsk.size());
return {pk, sk};
}
};
@@ -169,7 +169,7 @@ randomSecretKey()
std::uint8_t buf[32];
beast::rngfill(buf, sizeof(buf), crypto_prng());
SecretKey sk(Slice{buf, sizeof(buf)});
beast::secure_erase(buf, sizeof(buf));
secure_erase(buf, sizeof(buf));
return sk;
}
@@ -182,7 +182,7 @@ generateSecretKey(KeyType type, Seed const& seed)
{
auto key = sha512Half_s(Slice(seed.data(), seed.size()));
SecretKey sk = Slice{key.data(), key.size()};
beast::secure_erase(key.data(), key.size());
secure_erase(key.data(), key.size());
return sk;
}
@@ -194,7 +194,7 @@ generateSecretKey(KeyType type, Seed const& seed)
std::memcpy(ps.data(), seed.data(), seed.size());
auto const upk = generateRootDeterministicPrivateKey(ps);
SecretKey sk = Slice{upk.data(), upk.size()};
beast::secure_erase(ps.data(), ps.size());
secure_erase(ps.data(), ps.size());
return sk;
}

View File

@@ -19,10 +19,10 @@
#include <ripple/basics/Buffer.h>
#include <ripple/basics/contract.h>
#include <ripple/beast/crypto/secure_erase.h>
#include <ripple/beast/utility/rngfill.h>
#include <ripple/crypto/RFC1751.h>
#include <ripple/crypto/csprng.h>
#include <ripple/crypto/secure_erase.h>
#include <ripple/protocol/AccountID.h>
#include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/SecretKey.h>
@@ -36,7 +36,7 @@ namespace ripple {
Seed::~Seed()
{
beast::secure_erase(buf_.data(), buf_.size());
secure_erase(buf_.data(), buf_.size());
}
Seed::Seed(Slice const& slice)
@@ -61,7 +61,7 @@ randomSeed()
std::array<std::uint8_t, 16> buffer;
beast::rngfill(buffer.data(), buffer.size(), crypto_prng());
Seed seed(makeSlice(buffer));
beast::secure_erase(buffer.data(), buffer.size());
secure_erase(buffer.data(), buffer.size());
return seed;
}

View File

@@ -25,17 +25,6 @@
namespace ripple {
int
Serializer::addZeros(size_t uBytes)
{
int ret = mData.size();
while (uBytes--)
mData.push_back(0);
return ret;
}
int
Serializer::add16(std::uint16_t i)
{
@@ -107,22 +96,6 @@ Serializer::addInteger(std::uint64_t i)
return add64(i);
}
int
Serializer::add128(const uint128& i)
{
int ret = mData.size();
mData.insert(mData.end(), i.begin(), i.end());
return ret;
}
int
Serializer::add256(uint256 const& i)
{
int ret = mData.size();
mData.insert(mData.end(), i.begin(), i.end());
return ret;
}
int
Serializer::addRaw(Blob const& vector)
{
@@ -147,16 +120,6 @@ Serializer::addRaw(const void* ptr, int len)
return ret;
}
bool
Serializer::get256(uint256& o, int offset) const
{
if ((offset + (256 / 8)) > mData.size())
return false;
memcpy(o.begin(), &(mData.front()) + offset, (256 / 8));
return true;
}
int
Serializer::addFieldID(int type, int name)
{
@@ -219,28 +182,6 @@ Serializer::chop(int bytes)
return true;
}
bool
Serializer::getRaw(Blob& o, int offset, int length) const
{
if ((offset + length) > mData.size())
return false;
o.assign(mData.begin() + offset, mData.begin() + offset + length);
return true;
}
Blob
Serializer::getRaw(int offset, int length) const
{
Blob o;
if ((offset + length) > mData.size())
return o;
o.assign(mData.begin() + offset, mData.begin() + offset + length);
return o;
}
uint256
Serializer::getSHA512Half() const
{
@@ -278,99 +219,6 @@ Serializer::addVL(const void* ptr, int len)
return ret;
}
bool
Serializer::getVL(Blob& objectVL, int offset, int& length) const
{
int b1;
if (!get8(b1, offset++))
return false;
int datLen, lenLen = decodeLengthLength(b1);
try
{
if (lenLen == 1)
datLen = decodeVLLength(b1);
else if (lenLen == 2)
{
int b2;
if (!get8(b2, offset++))
return false;
datLen = decodeVLLength(b1, b2);
}
else if (lenLen == 3)
{
int b2, b3;
if (!get8(b2, offset++))
return false;
if (!get8(b3, offset++))
return false;
datLen = decodeVLLength(b1, b2, b3);
}
else
return false;
}
catch (std::exception const&)
{
return false;
}
length = lenLen + datLen;
return getRaw(objectVL, offset, datLen);
}
bool
Serializer::getVLLength(int& length, int offset) const
{
int b1;
if (!get8(b1, offset++))
return false;
int lenLen = decodeLengthLength(b1);
try
{
if (lenLen == 1)
length = decodeVLLength(b1);
else if (lenLen == 2)
{
int b2;
if (!get8(b2, offset++))
return false;
length = decodeVLLength(b1, b2);
}
else if (lenLen == 3)
{
int b2, b3;
if (!get8(b2, offset++))
return false;
if (!get8(b3, offset++))
return false;
length = decodeVLLength(b1, b2, b3);
}
else
return false;
}
catch (std::exception const&)
{
return false;
}
return true;
}
int
Serializer::addEncoded(int length)
{

View File

@@ -21,20 +21,34 @@
#include <ripple/protocol/Serializer.h>
#include <ripple/protocol/SystemParameters.h>
#include <ripple/protocol/UintTypes.h>
#include <string_view>
namespace ripple {
// For details on the protocol-level serialization please visit
// https://xrpl.org/serialization.html#currency-codes
namespace detail {
// Characters we are willing to allow in the ASCII representation of a
// three-letter currency code.
constexpr std::string_view isoCharSet =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789"
"<>(){}[]|?!@#$%^&*";
// The location (in bytes) of the 3 digit currency inside a 160-bit value
constexpr std::size_t isoCodeOffset = 12;
// The length of an ISO-4217 like code
constexpr std::size_t isoCodeLength = 3;
} // namespace detail
std::string
to_string(Currency const& currency)
{
// Characters we are willing to allow in the ASCII representation of a
// three-letter currency code.
static std::string const allowed_characters =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789"
"<>(){}[]|?!@#$%^&*";
if (currency == beast::zero)
return systemCurrencyCode();
@@ -46,16 +60,14 @@ to_string(Currency const& currency)
if ((currency & sIsoBits).isZero())
{
// The offset of the 3 character ISO code in the currency descriptor
int const isoOffset = 12;
std::string const iso(
currency.data() + isoOffset, currency.data() + isoOffset + 3);
currency.data() + detail::isoCodeOffset,
currency.data() + detail::isoCodeOffset + detail::isoCodeLength);
// Specifying the system currency code using ISO-style representation
// is not allowed.
if ((iso != systemCurrencyCode()) &&
(iso.find_first_not_of(allowed_characters) == std::string::npos))
(iso.find_first_not_of(detail::isoCharSet) == std::string::npos))
{
return iso;
}
@@ -73,30 +85,27 @@ to_currency(Currency& currency, std::string const& code)
return true;
}
static const int CURRENCY_CODE_LENGTH = 3;
if (code.size() == CURRENCY_CODE_LENGTH)
// Handle ISO-4217-like 3-digit character codes.
if (code.size() == detail::isoCodeLength)
{
Blob codeBlob(CURRENCY_CODE_LENGTH);
if (code.find_first_not_of(detail::isoCharSet) != std::string::npos)
return false;
std::transform(code.begin(), code.end(), codeBlob.begin(), [](auto c) {
return ::toupper(static_cast<unsigned char>(c));
});
currency = beast::zero;
Serializer s;
std::transform(
code.begin(),
code.end(),
currency.begin() + detail::isoCodeOffset,
[](auto c) {
return static_cast<unsigned char>(
::toupper(static_cast<unsigned char>(c)));
});
s.addZeros(96 / 8);
s.addRaw(codeBlob);
s.addZeros(16 / 8);
s.addZeros(24 / 8);
s.get160(currency, 0);
return true;
}
if (40 == code.size())
return currency.SetHex(code);
return false;
return currency.SetHexExact(code);
}
Currency

View File

@@ -84,7 +84,7 @@ SHAMapNodeID::getString() const
void
SHAMapNodeID::addIDRaw(Serializer& s) const
{
s.add256(mNodeID);
s.addBitString(mNodeID);
s.add8(mDepth);
}

View File

@@ -116,7 +116,7 @@ SHAMapAbstractNode::make(
Throw<std::runtime_error>("short AS node");
uint256 u;
s.get256(u, len - (256 / 8));
s.getBitString(u, len - (256 / 8));
s.chop(256 / 8);
if (u.isZero())
@@ -137,7 +137,7 @@ SHAMapAbstractNode::make(
auto ret = std::make_shared<SHAMapInnerNode>(seq);
for (int i = 0; i < 16; ++i)
{
s.get256(ret->mHashes[i].as_uint256(), i * 32);
s.getBitString(ret->mHashes[i].as_uint256(), i * 32);
if (ret->mHashes[i].isNonZero())
ret->mIsBranch |= (1 << i);
@@ -159,7 +159,7 @@ SHAMapAbstractNode::make(
Throw<std::runtime_error>("short CI node");
if ((pos < 0) || (pos >= 16))
Throw<std::runtime_error>("invalid CI node");
s.get256(ret->mHashes[pos].as_uint256(), i * 33);
s.getBitString(ret->mHashes[pos].as_uint256(), i * 33);
if (ret->mHashes[pos].isNonZero())
ret->mIsBranch |= (1 << pos);
}
@@ -176,7 +176,7 @@ SHAMapAbstractNode::make(
Throw<std::runtime_error>("short TM node");
uint256 u;
s.get256(u, len - (256 / 8));
s.getBitString(u, len - (256 / 8));
s.chop(256 / 8);
if (u.isZero())
@@ -224,7 +224,7 @@ SHAMapAbstractNode::make(
Throw<std::runtime_error>("short PLN node");
uint256 u;
s.get256(u, s.getLength() - 32);
s.getBitString(u, s.getLength() - 32);
s.chop(32);
if (u.isZero())
@@ -250,7 +250,7 @@ SHAMapAbstractNode::make(
for (int i = 0; i < 16; ++i)
{
s.get256(ret->mHashes[i].as_uint256(), i * 32);
s.getBitString(ret->mHashes[i].as_uint256(), i * 32);
if (ret->mHashes[i].isNonZero())
ret->mIsBranch |= (1 << i);
@@ -269,7 +269,7 @@ SHAMapAbstractNode::make(
Throw<std::runtime_error>("short TXN node");
uint256 txID;
s.get256(txID, s.getLength() - 32);
s.getBitString(txID, s.getLength() - 32);
s.chop(32);
auto item = std::make_shared<SHAMapItem const>(txID, s.peekData());
if (hashValid)
@@ -359,7 +359,7 @@ SHAMapInnerNode::addRaw(Serializer& s, SHANodeFormat format) const
if (format == snfHASH)
{
s.add256(mHash.as_uint256());
s.addBitString(mHash.as_uint256());
}
else if (mType == tnINNER)
{
@@ -370,7 +370,7 @@ SHAMapInnerNode::addRaw(Serializer& s, SHANodeFormat format) const
s.add32(HashPrefix::innerNode);
for (auto const& hh : mHashes)
s.add256(hh.as_uint256());
s.addBitString(hh.as_uint256());
}
else // format == snfWIRE
{
@@ -380,7 +380,7 @@ SHAMapInnerNode::addRaw(Serializer& s, SHANodeFormat format) const
for (int i = 0; i < mHashes.size(); ++i)
if (!isEmptyBranch(i))
{
s.add256(mHashes[i].as_uint256());
s.addBitString(mHashes[i].as_uint256());
s.add8(i);
}
@@ -389,7 +389,7 @@ SHAMapInnerNode::addRaw(Serializer& s, SHANodeFormat format) const
else
{
for (auto const& hh : mHashes)
s.add256(hh.as_uint256());
s.addBitString(hh.as_uint256());
s.add8(2);
}
@@ -409,7 +409,7 @@ SHAMapTreeNode::addRaw(Serializer& s, SHANodeFormat format) const
if (format == snfHASH)
{
s.add256(mHash.as_uint256());
s.addBitString(mHash.as_uint256());
}
else if (mType == tnACCOUNT_STATE)
{
@@ -417,12 +417,12 @@ SHAMapTreeNode::addRaw(Serializer& s, SHANodeFormat format) const
{
s.add32(HashPrefix::leafNode);
s.addRaw(mItem->peekData());
s.add256(mItem->key());
s.addBitString(mItem->key());
}
else
{
s.addRaw(mItem->peekData());
s.add256(mItem->key());
s.addBitString(mItem->key());
s.add8(1);
}
}
@@ -445,12 +445,12 @@ SHAMapTreeNode::addRaw(Serializer& s, SHANodeFormat format) const
{
s.add32(HashPrefix::txNode);
s.addRaw(mItem->peekData());
s.add256(mItem->key());
s.addBitString(mItem->key());
}
else
{
s.addRaw(mItem->peekData());
s.add256(mItem->key());
s.addBitString(mItem->key());
s.add8(4);
}
}

View File

@@ -82,7 +82,7 @@ public:
BEAST_EXPECT(c.getTrackSize() == 1);
{
Cache::mapped_ptr p(c.fetch(2));
auto p = c.fetch(2);
BEAST_EXPECT(p != nullptr);
++clock;
c.sweep();
@@ -102,8 +102,8 @@ public:
BEAST_EXPECT(!c.insert(3, "three"));
{
Cache::mapped_ptr const p1(c.fetch(3));
Cache::mapped_ptr p2(std::make_shared<Value>("three"));
auto const p1 = c.fetch(3);
auto p2 = std::make_shared<Value>("three");
c.canonicalize_replace_client(3, p2);
BEAST_EXPECT(p1.get() == p2.get());
}
@@ -124,7 +124,7 @@ public:
{
// Keep a strong pointer to it
Cache::mapped_ptr p1(c.fetch(4));
auto const p1 = c.fetch(4);
BEAST_EXPECT(p1 != nullptr);
BEAST_EXPECT(c.getCacheSize() == 1);
BEAST_EXPECT(c.getTrackSize() == 1);
@@ -134,7 +134,7 @@ public:
BEAST_EXPECT(c.getCacheSize() == 0);
BEAST_EXPECT(c.getTrackSize() == 1);
// Canonicalize a new object with the same key
Cache::mapped_ptr p2(std::make_shared<std::string>("four"));
auto p2 = std::make_shared<std::string>("four");
BEAST_EXPECT(c.canonicalize_replace_client(4, p2));
BEAST_EXPECT(c.getCacheSize() == 1);
BEAST_EXPECT(c.getTrackSize() == 1);

View File

@@ -39,7 +39,7 @@ struct STAccount_test : public beast::unit_test::suite
Serializer s;
defaultAcct.add(s); // Asserts in debug build
BEAST_EXPECT(s.size() == 1);
BEAST_EXPECT(s.getHex() == "00");
BEAST_EXPECT(strHex(s) == "00");
SerialIter sit(s.slice());
STAccount const deserializedDefault(sit, sfAccount);
BEAST_EXPECT(deserializedDefault.isEquivalent(defaultAcct));
@@ -65,7 +65,7 @@ struct STAccount_test : public beast::unit_test::suite
Serializer s;
sfAcct.add(s);
BEAST_EXPECT(s.size() == 1);
BEAST_EXPECT(s.getHex() == "00");
BEAST_EXPECT(strHex(s) == "00");
SerialIter sit(s.slice());
STAccount const deserializedSf(sit, sfAccount);
BEAST_EXPECT(deserializedSf.isEquivalent(sfAcct));
@@ -83,7 +83,7 @@ struct STAccount_test : public beast::unit_test::suite
zeroAcct.add(s);
BEAST_EXPECT(s.size() == 21);
BEAST_EXPECT(
s.getHex() == "140000000000000000000000000000000000000000");
strHex(s) == "140000000000000000000000000000000000000000");
SerialIter sit(s.slice());
STAccount const deserializedZero(sit, sfAccount);
BEAST_EXPECT(deserializedZero.isEquivalent(zeroAcct));

View File

@@ -103,75 +103,6 @@ public:
return Buffer{Slice{b.data(), b.size()}};
}
// VFALCO We can remove this commented out code
// later, when we have confidence in the vectors.
/*
Buffer
makeNonCanonical(Buffer const& sig)
{
secp256k1_ecdsa_signature sigin;
BEAST_EXPECT(secp256k1_ecdsa_signature_parse_der(
secp256k1Context(),
&sigin,
reinterpret_cast<unsigned char const*>(
sig.data()),
sig.size()) == 1);
secp256k1_ecdsa_signature sigout;
BEAST_EXPECT(secp256k1_ecdsa_signature_denormalize(
secp256k1Context(),
&sigout,
&sigin) == 1);
unsigned char buf[72];
size_t len = sizeof(buf);
BEAST_EXPECT(secp256k1_ecdsa_signature_serialize_der(
secp256k1Context(),
buf,
&len,
&sigout) == 1);
return Buffer{buf, len};
}
void
makeCanonicalityTestVectors()
{
uint256 digest;
beast::rngfill (
digest.data(),
digest.size(),
crypto_prng());
log << "digest " << strHex(digest.data(), digest.size()) << std::endl;
auto const sk = randomSecretKey();
auto const pk = derivePublicKey(KeyType::secp256k1, sk);
log << "public " << pk << std::endl;
log << "secret " << sk.to_string() << std::endl;
auto sig = signDigest(pk, sk, digest);
log << "canonical sig " << strHex(sig) << std::endl;
auto const non = makeNonCanonical(sig);
log << "non-canon sig " << strHex(non) << std::endl;
{
auto const canonicality = ecdsaCanonicality(sig);
BEAST_EXPECT(canonicality);
BEAST_EXPECT(*canonicality == ECDSACanonicality::fullyCanonical);
}
{
auto const canonicality = ecdsaCanonicality(non);
BEAST_EXPECT(canonicality);
BEAST_EXPECT(*canonicality != ECDSACanonicality::fullyCanonical);
}
BEAST_EXPECT(verifyDigest(pk, digest, sig, false));
BEAST_EXPECT(verifyDigest(pk, digest, sig, true));
BEAST_EXPECT(verifyDigest(pk, digest, non, false));
BEAST_EXPECT(! verifyDigest(pk, digest, non, true));
}
*/
// Ensure that verification does the right thing with
// respect to the matrix of canonicality variables.
void