diff options
| author | luigi1111 <luigi1111w@gmail.com> | 2021-08-20 16:45:15 -0400 |
|---|---|---|
| committer | luigi1111 <luigi1111w@gmail.com> | 2021-08-20 16:45:15 -0400 |
| commit | 1b079e51956b4fea5f8e014566b8da489727fcae (patch) | |
| tree | d4a8396047b6036c30b1416da1aad298a26b0859 /src/wallet/wallet2.cpp | |
| parent | 294d58c58d280a2c4c59e339d7e9c6f42d06a11a (diff) | |
| parent | e1af8dc02cd7363a5592b539819db02aeb902b9d (diff) | |
| download | monzero-core-1b079e51956b4fea5f8e014566b8da489727fcae.tar.gz monzero-core-1b079e51956b4fea5f8e014566b8da489727fcae.tar.xz monzero-core-1b079e51956b4fea5f8e014566b8da489727fcae.zip | |
Merge pull request #7845
e1af8dc Protect client from divide by 0 caused by integer truncation (j-berman)
Diffstat (limited to 'src/wallet/wallet2.cpp')
| -rw-r--r-- | src/wallet/wallet2.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 6475592fa..7f23ed4d6 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1022,7 +1022,13 @@ gamma_picker::gamma_picker(const std::vector<uint64_t> &rct_offsets, double shap end = rct_offsets.data() + rct_offsets.size() - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE; num_rct_outputs = *(end - 1); THROW_WALLET_EXCEPTION_IF(num_rct_outputs == 0, error::wallet_internal_error, "No rct outputs"); + THROW_WALLET_EXCEPTION_IF(outputs_to_consider == 0, error::wallet_internal_error, "No rct outputs to consider"); average_output_time = DIFFICULTY_TARGET_V2 * blocks_to_consider / outputs_to_consider; // this assumes constant target over the whole rct range + if (average_output_time == 0) { + // TODO: apply this to all cases; do so alongside a hard fork, where all clients will update at the same time, preventing anonymity puddle formation + average_output_time = DIFFICULTY_TARGET_V2 * blocks_to_consider / static_cast<double>(outputs_to_consider); + } + THROW_WALLET_EXCEPTION_IF(average_output_time == 0, error::wallet_internal_error, "Average seconds per output cannot be 0."); }; gamma_picker::gamma_picker(const std::vector<uint64_t> &rct_offsets): gamma_picker(rct_offsets, GAMMA_SHAPE, GAMMA_SCALE) {} |
