From 6137a0b94d86e9f1c3321969da1c74f1d5e72b4f Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 12 Sep 2017 21:41:30 +0100 Subject: blockchain: reject unsorted ins and outs from v7 This ensures no information is leaked by the ordering --- src/common/apply_permutation.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/common/apply_permutation.h') diff --git a/src/common/apply_permutation.h b/src/common/apply_permutation.h index 4de224690..4fd952686 100644 --- a/src/common/apply_permutation.h +++ b/src/common/apply_permutation.h @@ -32,12 +32,18 @@ #include #include +#include "misc_log_ex.h" namespace tools { -void apply_permutation(std::vector permutation, const std::function &swap) +template +void apply_permutation(std::vector permutation, const F &swap) { + //sanity check + for (size_t n = 0; n < permutation.size(); ++n) + CHECK_AND_ASSERT_THROW_MES(std::find(permutation.begin(), permutation.end(), n) != permutation.end(), "Bad permutation"); + for (size_t i = 0; i < permutation.size(); ++i) { size_t current = i; @@ -55,6 +61,7 @@ void apply_permutation(std::vector permutation, const std::function void apply_permutation(const std::vector &permutation, std::vector &v) { + CHECK_AND_ASSERT_THROW_MES(permutation.size() == v.size(), "Mismatched vector sizes"); apply_permutation(permutation, [&v](size_t i0, size_t i1){ std::swap(v[i0], v[i1]); }); } -- cgit v1.2.3