Files
xahaud/include/xrpl/protocol/HashPrefix.h
Nicholas Dudfield c92c0656ec feat(rng): tier 3 consensus-bound fallback entropy
Replace the zero-entropy fallback with a deterministic consensus-bound
digest so every RNG-enabled ledger carries usable entropy:

- sha512Half(HashPrefix::entropyFallback, prevLedgerHash, baseTxSetHash,
  seq) — all inputs are already consensus-agreed at injection time, so
  no new agreement machinery is needed and the digest is identical on
  every node building the same ledger
- new sfEntropyTier (UINT8) on the ttCONSENSUS_ENTROPY pseudo-tx and
  ConsensusEntropy ledger entry: EntropyCount says how many validators
  contributed, EntropyTier says which gate the result passed
  (validator_quorum vs consensus_fallback; participant_aligned reserved)
- the fallback digest derives from the BASE (pre-injection) tx set hash
  to avoid circularity; entropy pseudo-tx dedup is now type-based since
  an explicit-final synthetic set can carry a pseudo-tx whose txID
  implicit nodes cannot re-derive
- unparseable-entropy-set residual now falls back instead of skipping
  injection, so a fresh ConsensusEntropy entry exists every ledger
- CSF Peer mirrors the fallback analog; sims assert deterministic
  non-zero fallback digests across same-LCL peers
- testnet scenarios updated: degraded windows expect labeled fallback
  entropy, never validator-tier

The fallback tier is user-influenceable via tx submission (quiet-ledger
grinding) and is labeled accordingly — hook-facing gating lands with the
min_tier/min_count API change.
2026-06-10 16:32:49 +07:00

120 lines
4.1 KiB
C++

//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 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_PROTOCOL_HASHPREFIX_H_INCLUDED
#define RIPPLE_PROTOCOL_HASHPREFIX_H_INCLUDED
#include <xrpl/beast/hash/hash_append.h>
#include <cstdint>
namespace ripple {
namespace detail {
constexpr std::uint32_t
make_hash_prefix(char a, char b, char c)
{
return (static_cast<std::uint32_t>(a) << 24) +
(static_cast<std::uint32_t>(b) << 16) +
(static_cast<std::uint32_t>(c) << 8);
}
} // namespace detail
/** Prefix for hashing functions.
These prefixes are inserted before the source material used to generate
various hashes. This is done to put each hash in its own "space." This way,
two different types of objects with the same binary data will produce
different hashes.
Each prefix is a 4-byte value with the last byte set to zero and the first
three bytes formed from the ASCII equivalent of some arbitrary string. For
example "TXN".
@note Hash prefixes are part of the protocol; you cannot, arbitrarily,
change the type or the value of any of these without causing breakage.
*/
enum class HashPrefix : std::uint32_t {
/** transaction plus signature to give transaction ID */
transactionID = detail::make_hash_prefix('T', 'X', 'N'),
/** transaction plus metadata */
txNode = detail::make_hash_prefix('S', 'N', 'D'),
/** account state */
leafNode = detail::make_hash_prefix('M', 'L', 'N'),
/** inner node in V1 tree */
innerNode = detail::make_hash_prefix('M', 'I', 'N'),
/** ledger master data for signing */
ledgerMaster = detail::make_hash_prefix('L', 'W', 'R'),
/** inner transaction to sign */
txSign = detail::make_hash_prefix('S', 'T', 'X'),
/** inner transaction to multi-sign */
txMultiSign = detail::make_hash_prefix('S', 'M', 'T'),
/** validation for signing */
validation = detail::make_hash_prefix('V', 'A', 'L'),
/** proposal for signing */
proposal = detail::make_hash_prefix('P', 'R', 'P'),
/** Manifest */
manifest = detail::make_hash_prefix('M', 'A', 'N'),
/** Payment Channel Claim */
paymentChannelClaim = detail::make_hash_prefix('C', 'L', 'M'),
/** Emit Transaction Nonce */
emitTxnNonce = detail::make_hash_prefix('E', 'T', 'X'),
/** Random entropy for hook developers to use */
hookNonce = detail::make_hash_prefix('N', 'C', 'E'),
/* Hash of a Hook's actual code */
hookDefinition = detail::make_hash_prefix('W', 'S', 'M'),
/** Credentials signature */
credential = detail::make_hash_prefix('C', 'R', 'D'),
/** consensus extension sidecar object */
sidecar = detail::make_hash_prefix('S', 'C', 'R'),
/** consensus-bound fallback entropy digest (Tier 3: derived from
already-agreed round inputs when validator reveal quorum is not
available; never to be confused with validator entropy) */
entropyFallback = detail::make_hash_prefix('E', 'F', 'B'),
};
template <class Hasher>
void
hash_append(Hasher& h, HashPrefix const& hp) noexcept
{
using beast::hash_append;
hash_append(h, static_cast<std::uint32_t>(hp));
}
} // namespace ripple
#endif