From 533a8909729bcd30e16d1425b42f83789653ea07 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Mon, 1 Jul 2019 10:06:46 -0400 Subject: [PATCH] Shrink sidechannel array, use wallet const for size --- src/blind.cpp | 10 ++++------ src/blind.h | 5 ++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/blind.cpp b/src/blind.cpp index 5f465f1e1d..41f715d7cc 100644 --- a/src/blind.cpp +++ b/src/blind.cpp @@ -59,10 +59,8 @@ bool UnblindConfidentialPair(const CKey& blinding_key, const CConfidentialValue& nonce = uint256(std::vector(blinding_key.begin(), blinding_key.end())); } - // API-prescribed sidechannel maximum size, though we only use 64 bytes - unsigned char msg[4096] = {0}; - // 32 bytes of asset type, 32 bytes of asset blinding factor in sidechannel - size_t msg_size = 64; + unsigned char msg[SIDECHANNEL_MSG_SIZE] = {0}; + size_t msg_size = SIDECHANNEL_MSG_SIZE; // If value is unblinded, we don't support unblinding just the asset if (!conf_value.IsCommitment()) { @@ -102,7 +100,7 @@ bool UnblindConfidentialPair(const CKey& blinding_key, const CConfidentialValue& // Asset sidechannel of asset type + asset blinder secp256k1_generator recalculated_gen; - if (msg_size != 64 || secp256k1_generator_generate_blinded(secp256k1_blind_context, &recalculated_gen, asset_type, asset_blinder) != 1) { + if (msg_size != SIDECHANNEL_MSG_SIZE || secp256k1_generator_generate_blinded(secp256k1_blind_context, &recalculated_gen, asset_type, asset_blinder) != 1) { return false; } @@ -175,7 +173,7 @@ bool GenerateRangeproof(std::vector& rangeproof, const std::vecto rangeproof.resize(nRangeProofLen); // Compose sidechannel message to convey asset info (ID and asset blinds) - unsigned char asset_message[64]; + unsigned char asset_message[SIDECHANNEL_MSG_SIZE]; memcpy(asset_message, asset.begin(), 32); memcpy(asset_message+32, asset_blindptrs[asset_blindptrs.size()-1], 32); diff --git a/src/blind.h b/src/blind.h index 4296b70ce7..d625978f29 100644 --- a/src/blind.h +++ b/src/blind.h @@ -14,8 +14,11 @@ #include #include -//! ELEMENTS: 36-bit rangeproof size +//! ELEMENTS: +// 36-bit rangeproof size static const size_t DEFAULT_RANGEPROOF_SIZE = 2893; +// 32 bytes of asset type, 32 bytes of asset blinding factor in sidechannel +static const size_t SIDECHANNEL_MSG_SIZE = 64; /* * Unblind a pair of confidential asset and value.