consensus: Statically check funding stream numerators and denominators
This commit is contained in:
parent
bfeaa0e4c0
commit
768534a8b9
|
@ -10,7 +10,7 @@ namespace Consensus
|
|||
* General information about each funding stream.
|
||||
* Ordered by Consensus::FundingStreamIndex.
|
||||
*/
|
||||
const struct FSInfo FundingStreamInfo[Consensus::MAX_FUNDING_STREAMS] = {
|
||||
constexpr struct FSInfo FundingStreamInfo[Consensus::MAX_FUNDING_STREAMS] = {
|
||||
{
|
||||
.recipient = "Electric Coin Company",
|
||||
.specification = "https://zips.z.cash/zip-0214",
|
||||
|
@ -31,6 +31,16 @@ const struct FSInfo FundingStreamInfo[Consensus::MAX_FUNDING_STREAMS] = {
|
|||
}
|
||||
};
|
||||
|
||||
static constexpr bool validateFundingStreamInfo(uint32_t idx) {
|
||||
return (idx >= Consensus::MAX_FUNDING_STREAMS || (
|
||||
FundingStreamInfo[idx].valueNumerator < FundingStreamInfo[idx].valueDenominator &&
|
||||
FundingStreamInfo[idx].valueNumerator < (INT64_MAX / MAX_MONEY) &&
|
||||
validateFundingStreamInfo(idx + 1)));
|
||||
}
|
||||
static_assert(
|
||||
validateFundingStreamInfo(Consensus::FIRST_FUNDING_STREAM),
|
||||
"Invalid FundingStreamInfo");
|
||||
|
||||
CAmount FSInfo::Value(CAmount blockSubsidy) const
|
||||
{
|
||||
// Integer division is floor division for nonnegative integers in C++
|
||||
|
|
|
@ -14,8 +14,8 @@ namespace Consensus
|
|||
{
|
||||
|
||||
struct FSInfo {
|
||||
std::string recipient;
|
||||
std::string specification;
|
||||
const char* recipient;
|
||||
const char* specification;
|
||||
uint64_t valueNumerator;
|
||||
uint64_t valueDenominator;
|
||||
|
||||
|
|
Loading…
Reference in New Issue