Skip to content

Commit 811d835

Browse files
authored
Merge pull request #1439 from tomt1664/fix/check-missing-proofs
Add missing proof checks and tests
2 parents 3c1782e + 51f81f3 commit 811d835

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/blindpsbt.cpp

+3-1
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

+3
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

+44
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,44 @@ def test_wallet_recovery(self):
106106
# clean up blind_details
107107
os.remove(file_path)
108108

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

@@ -160,6 +198,12 @@ def test_null_rangeproof_enforcement(self):
160198

161199
def run_test(self):
162200

201+
print("Testing a transaction with a missing surjection proof")
202+
self.test_no_surj()
203+
204+
print("Testing a transaction with a missing range proof")
205+
self.test_no_range()
206+
163207
print("Testing that null issuances must have null rangeproofs")
164208
self.test_null_rangeproof_enforcement()
165209

0 commit comments

Comments
 (0)