| 111 | constexpr uint32_t MAX_START_TIME = 4102444800; // 2100-01-01 |
| 112 | |
| 113 | FUZZ_TARGET_INIT(versionbits, initialize) |
| 114 | { |
| 115 | const CChainParams& params = *g_params; |
| 116 | const int64_t interval = params.GetConsensus().nPowTargetSpacing; |
| 117 | assert(interval > 1); // need to be able to halve it |
| 118 | assert(interval < std::numeric_limits<int32_t>::max()); |
| 119 | |
| 120 | FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); |
| 121 | |
| 122 | // making period/max_periods larger slows these tests down significantly |
| 123 | const int period = 32; |
| 124 | const size_t max_periods = 16; |
| 125 | const size_t max_blocks = 2 * period * max_periods; |
| 126 | |
| 127 | const int threshold = fuzzed_data_provider.ConsumeIntegralInRange(1, period); |
| 128 | assert(0 < threshold && threshold <= period); // must be able to both pass and fail threshold! |
| 129 | |
| 130 | // too many blocks at 10min each might cause uint32_t time to overflow if |
| 131 | // block_start_time is at the end of the range above |
| 132 | assert(std::numeric_limits<uint32_t>::max() - MAX_START_TIME > interval * max_blocks); |
| 133 | |
| 134 | const int64_t block_start_time = fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(params.GenesisBlock().nTime, MAX_START_TIME); |
| 135 | |
| 136 | // what values for version will we use to signal / not signal? |
| 137 | const int32_t ver_signal = fuzzed_data_provider.ConsumeIntegral<int32_t>(); |
| 138 | const int32_t ver_nosignal = fuzzed_data_provider.ConsumeIntegral<int32_t>(); |
| 139 | |
| 140 | // select deployment parameters: bit, start time, timeout |
| 141 | const int bit = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, VERSIONBITS_NUM_BITS - 1); |
| 142 | |
| 143 | bool always_active_test = false; |
| 144 | bool never_active_test = false; |
| 145 | int64_t start_time; |
| 146 | int64_t timeout; |
| 147 | if (fuzzed_data_provider.ConsumeBool()) { |
| 148 | // pick the timestamp to switch based on a block |
| 149 | // note states will change *after* these blocks because mediantime lags |
| 150 | int start_block = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, period * (max_periods - 3)); |
| 151 | int end_block = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, period * (max_periods - 3)); |
| 152 | |
| 153 | start_time = block_start_time + start_block * interval; |
| 154 | timeout = block_start_time + end_block * interval; |
| 155 | |
| 156 | // allow for times to not exactly match a block |
| 157 | if (fuzzed_data_provider.ConsumeBool()) start_time += interval / 2; |
| 158 | if (fuzzed_data_provider.ConsumeBool()) timeout += interval / 2; |
| 159 | } else { |
| 160 | if (fuzzed_data_provider.ConsumeBool()) { |
| 161 | start_time = Consensus::BIP9Deployment::ALWAYS_ACTIVE; |
| 162 | always_active_test = true; |
| 163 | } else { |
| 164 | start_time = Consensus::BIP9Deployment::NEVER_ACTIVE; |
| 165 | never_active_test = true; |
| 166 | } |
| 167 | timeout = fuzzed_data_provider.ConsumeBool() ? Consensus::BIP9Deployment::NO_TIMEOUT : fuzzed_data_provider.ConsumeIntegral<int64_t>(); |
| 168 | } |
| 169 | int min_activation = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, period * max_periods); |
| 170 |
nothing calls this directly
no test coverage detected