aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-09-12 21:41:30 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-09-18 11:23:15 +0100
commit6137a0b94d86e9f1c3321969da1c74f1d5e72b4f (patch)
tree5f22756053d60d8200e138192c94cd918911871e /src/common
parentcore: sort ins and outs key key image and public key, respectively (diff)
downloadmonero-6137a0b94d86e9f1c3321969da1c74f1d5e72b4f.tar.xz
blockchain: reject unsorted ins and outs from v7
This ensures no information is leaked by the ordering
Diffstat (limited to 'src/common')
-rw-r--r--src/common/apply_permutation.h9
1 files changed, 8 insertions, 1 deletions
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 <vector>
#include <functional>
+#include "misc_log_ex.h"
namespace tools
{
-void apply_permutation(std::vector<size_t> permutation, const std::function<void(size_t, size_t)> &swap)
+template<typename F>
+void apply_permutation(std::vector<size_t> 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<size_t> permutation, const std::function<void
template<typename T>
void apply_permutation(const std::vector<size_t> &permutation, std::vector<T> &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]); });
}