Skip to content

Commit 93f49ed

Browse files
dgpvinstagibbs
authored andcommitted
fix vector length calculation for targets in BlindTransaction
the size of surjectionTargets and targetAssetGenerator vectors was calculated as tx.vin.size()*3, based on the fact that for each input there might also be up to 2 issuance pseudo-inputs, but did not take into account that the number of auxiliary generators may exceed the number of inputs. This fixes the size calculations by taking into account auxiliary generators supplied beyond vin size.
1 parent 09e20ab commit 93f49ed

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/blind.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,6 @@ int BlindTransaction(std::vector<uint256 >& input_value_blinding_factors, const
235235
assert(tx.vin.size() == input_asset_blinding_factors.size());
236236
assert(tx.vin.size() == input_assets.size());
237237
assert(tx.vin.size() == input_amounts.size());
238-
if (auxiliary_generators) {
239-
assert(auxiliary_generators->size() >= tx.vin.size());
240-
}
241238

242239
std::vector<unsigned char*> value_blindptrs;
243240
std::vector<const unsigned char*> asset_blindptrs;
@@ -255,8 +252,16 @@ int BlindTransaction(std::vector<uint256 >& input_value_blinding_factors, const
255252

256253
// Needed to construct the proof itself. Generators must match final transaction to be valid
257254
std::vector<secp256k1_generator> target_asset_generators;
258-
surjection_targets.resize(tx.vin.size()*3);
259-
target_asset_generators.resize(tx.vin.size()*3);
255+
256+
// maxTargets is a strict upper-bound for the size of target vectors.
257+
// The vectors will be shrunk later according to final count of totalTargets
258+
size_t maxTargets = tx.vin.size()*3;
259+
if (auxiliary_generators) {
260+
assert(auxiliary_generators->size() >= tx.vin.size());
261+
maxTargets += auxiliary_generators->size() - tx.vin.size();
262+
}
263+
surjection_targets.resize(maxTargets);
264+
target_asset_generators.resize(maxTargets);
260265

261266
// input_asset_blinding_factors is only for inputs, not for issuances(0 by def)
262267
// but we need to create surjection proofs against this list so we copy and insert 0's

0 commit comments

Comments
 (0)