Skip to content

Commit 668be09

Browse files
committed
Merge 811d835 into merged_master (Elements PR ElementsProject#1439)
2 parents fcd6674 + 811d835 commit 668be09

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/blindpsbt.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ bool CreateAssetSurjectionProof(std::vector<unsigned char>& output_proof, const
6868

6969
bool VerifyBlindAssetProof(const uint256& asset, const std::vector<unsigned char>& proof, const CConfidentialAsset& conf_asset)
7070
{
71+
if (conf_asset.vchCommitment.size() != CConfidentialAsset::nCommittedSize || proof.empty()) {
72+
return false;
73+
}
7174
secp256k1_surjectionproof surj_proof;
7275
if (secp256k1_surjectionproof_parse(secp256k1_blind_context, &surj_proof, proof.data(), proof.size()) == 0) {
7376
return false;
7477
}
75-
7678
secp256k1_generator blinded_asset_gen;
7779
if (secp256k1_generator_parse(secp256k1_blind_context, &blinded_asset_gen, conf_asset.vchCommitment.data()) == 0) {
7880
return false;

src/confidential_validation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ bool VerifyAmounts(const std::vector<CTxOut>& inputs, const CTransaction& tx, st
390390
}
391391
if (!ptxoutwit)
392392
return false;
393+
if (asset.vchCommitment.size() != CConfidentialAsset::nCommittedSize || ptxoutwit->vchSurjectionproof.empty()) {
394+
return false;
395+
}
393396
if (secp256k1_generator_parse(secp256k1_ctx_verify_amounts, &gen, &asset.vchCommitment[0]) != 1)
394397
return false;
395398

test/functional/feature_confidential_transactions.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,44 @@ def test_wallet_recovery(self):
109109
# clean up blind_details
110110
os.remove(file_path)
111111

112+
def test_no_surj(self):
113+
self.generate(self.nodes[0], 1)
114+
115+
tx_hex = self.nodes[0].createrawtransaction([], [{self.nodes[1].getnewaddress(): 1000}])
116+
tx_hex = self.nodes[0].fundrawtransaction(tx_hex)['hex']
117+
tx_hex = self.nodes[0].blindrawtransaction(tx_hex)
118+
# coming from initial free coins: no need to sign
119+
assert_equal(self.nodes[0].testmempoolaccept([tx_hex])[0]['allowed'], True) # tx is ok
120+
121+
# remove a surjection proof from the tx
122+
tx = CTransaction()
123+
tx.deserialize(io.BytesIO(bytes.fromhex(tx_hex)))
124+
tx.wit.vtxoutwit[0].vchSurjectionproof = b''
125+
tx_hex = tx.serialize().hex()
126+
127+
# Both of these make the node crash
128+
assert_equal(self.nodes[0].testmempoolaccept([tx_hex])[0]['allowed'], False)
129+
assert_raises_rpc_error(-26, "bad-txns-in-ne-out", self.nodes[0].sendrawtransaction, tx_hex)
130+
131+
def test_no_range(self):
132+
self.generate(self.nodes[0], 1)
133+
134+
tx_hex = self.nodes[0].createrawtransaction([], [{self.nodes[1].getnewaddress(): 1000}])
135+
tx_hex = self.nodes[0].fundrawtransaction(tx_hex)['hex']
136+
tx_hex = self.nodes[0].blindrawtransaction(tx_hex)
137+
# coming from initial free coins: no need to sign
138+
assert_equal(self.nodes[0].testmempoolaccept([tx_hex])[0]['allowed'], True) # tx is ok
139+
140+
# remove a surjection proof from the tx
141+
tx = CTransaction()
142+
tx.deserialize(io.BytesIO(bytes.fromhex(tx_hex)))
143+
tx.wit.vtxoutwit[0].vchRangeproof = b''
144+
tx_hex = tx.serialize().hex()
145+
146+
# Both of these make the node crash
147+
assert_equal(self.nodes[0].testmempoolaccept([tx_hex])[0]['allowed'], False)
148+
assert_raises_rpc_error(-26, "bad-txns-in-ne-out", self.nodes[0].sendrawtransaction, tx_hex)
149+
112150
def test_null_rangeproof_enforcement(self):
113151
self.generate(self.nodes[0], 1)
114152

@@ -163,6 +201,12 @@ def test_null_rangeproof_enforcement(self):
163201

164202
def run_test(self):
165203

204+
print("Testing a transaction with a missing surjection proof")
205+
self.test_no_surj()
206+
207+
print("Testing a transaction with a missing range proof")
208+
self.test_no_range()
209+
166210
print("Testing that null issuances must have null rangeproofs")
167211
self.test_null_rangeproof_enforcement()
168212

0 commit comments

Comments
 (0)