consensus: Statically check funding stream numerators and denominators

This commit is contained in:
Jack Grigg 2020-08-20 14:48:01 +01:00
parent bfeaa0e4c0
commit 768534a8b9
2 changed files with 13 additions and 3 deletions

View File

@ -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++

View File

@ -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;