Add GenIdentity, an identity function for MappedShuffle.
We use this function in z_sendmany as part of the fix for #1779.
This commit is contained in:
parent
7c463780cf
commit
38276c6ba2
|
@ -24,4 +24,12 @@ TEST(Random, MappedShuffle) {
|
|||
std::vector<int> em2 {0, 1, 2, 3, 4};
|
||||
EXPECT_EQ(ea2, a2);
|
||||
EXPECT_EQ(em2, m2);
|
||||
|
||||
auto a3 = a;
|
||||
auto m3 = m;
|
||||
MappedShuffle(a3.begin(), m3.begin(), a3.size(), GenIdentity);
|
||||
std::vector<int> ea3 {8, 4, 6, 3, 5};
|
||||
std::vector<int> em3 {0, 1, 2, 3, 4};
|
||||
EXPECT_EQ(ea3, a3);
|
||||
EXPECT_EQ(em3, m3);
|
||||
}
|
||||
|
|
|
@ -57,10 +57,11 @@ JSDescription JSDescription::Randomized(
|
|||
// Randomize the order of the inputs and outputs
|
||||
inputMap = {0, 1};
|
||||
outputMap = {0, 1};
|
||||
if (gen) {
|
||||
MappedShuffle(inputs.begin(), inputMap.begin(), ZC_NUM_JS_INPUTS, gen);
|
||||
MappedShuffle(outputs.begin(), outputMap.begin(), ZC_NUM_JS_OUTPUTS, gen);
|
||||
}
|
||||
|
||||
assert(gen);
|
||||
|
||||
MappedShuffle(inputs.begin(), inputMap.begin(), ZC_NUM_JS_INPUTS, gen);
|
||||
MappedShuffle(outputs.begin(), outputMap.begin(), ZC_NUM_JS_OUTPUTS, gen);
|
||||
|
||||
return JSDescription(
|
||||
params, pubKeyHash, anchor, inputs, outputs,
|
||||
|
|
|
@ -137,3 +137,8 @@ void seed_insecure_rand(bool fDeterministic)
|
|||
insecure_rand_Rw = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
int GenIdentity(int n)
|
||||
{
|
||||
return n-1;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,11 @@ uint64_t GetRand(uint64_t nMax);
|
|||
int GetRandInt(int nMax);
|
||||
uint256 GetRandHash();
|
||||
|
||||
/**
|
||||
* Identity function for MappedShuffle, so that elements retain their original order.
|
||||
*/
|
||||
int GenIdentity(int n);
|
||||
|
||||
/**
|
||||
* Rearranges the elements in the range [first,first+len) randomly, assuming
|
||||
* that gen is a uniform random number generator. Follows the same algorithm as
|
||||
|
|
|
@ -875,7 +875,6 @@ Object AsyncRPCOperation_sendmany::perform_joinsplit(
|
|||
{info.vjsout[0], info.vjsout[1]};
|
||||
boost::array<size_t, ZC_NUM_JS_INPUTS> inputMap;
|
||||
boost::array<size_t, ZC_NUM_JS_OUTPUTS> outputMap;
|
||||
std::function<int(int)> emptyFunc;
|
||||
JSDescription jsdesc = JSDescription::Randomized(
|
||||
*pzcashParams,
|
||||
joinSplitPubKey_,
|
||||
|
@ -888,7 +887,7 @@ Object AsyncRPCOperation_sendmany::perform_joinsplit(
|
|||
info.vpub_new,
|
||||
!this->testmode,
|
||||
// Temporary fix for #1779 is to disable shuffling of inputs and outputs.
|
||||
emptyFunc);
|
||||
GenIdentity);
|
||||
|
||||
if (!(jsdesc.Verify(*pzcashParams, joinSplitPubKey_))) {
|
||||
throw std::runtime_error("error verifying joinsplit");
|
||||
|
|
Loading…
Reference in New Issue