blockchain: reject unsorted ins and outs from v7
This ensures no information is leaked by the ordering
This commit is contained in:
@@ -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]); });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user