Skip to content

Add missing proof checks and tests #1439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/blindpsbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ bool CreateAssetSurjectionProof(std::vector<unsigned char>& output_proof, const

bool VerifyBlindAssetProof(const uint256& asset, const std::vector<unsigned char>& proof, const CConfidentialAsset& conf_asset)
{
if (conf_asset.vchCommitment.size() != CConfidentialAsset::nCommittedSize || proof.empty()) {
return false;
}
secp256k1_surjectionproof surj_proof;
if (secp256k1_surjectionproof_parse(secp256k1_blind_context, &surj_proof, proof.data(), proof.size()) == 0) {
return false;
}

secp256k1_generator blinded_asset_gen;
if (secp256k1_generator_parse(secp256k1_blind_context, &blinded_asset_gen, conf_asset.vchCommitment.data()) == 0) {
return false;
Expand Down
3 changes: 3 additions & 0 deletions src/confidential_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ bool VerifyAmounts(const std::vector<CTxOut>& inputs, const CTransaction& tx, st
}
if (!ptxoutwit)
return false;
if (asset.vchCommitment.size() != CConfidentialAsset::nCommittedSize || ptxoutwit->vchSurjectionproof.empty()) {
return false;
}
if (secp256k1_generator_parse(secp256k1_ctx_verify_amounts, &gen, &asset.vchCommitment[0]) != 1)
return false;

Expand Down
44 changes: 44 additions & 0 deletions test/functional/feature_confidential_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,44 @@ def test_wallet_recovery(self):
# clean up blind_details
os.remove(file_path)

def test_no_surj(self):
self.generate(self.nodes[0], 1)

tx_hex = self.nodes[0].createrawtransaction([], [{self.nodes[1].getnewaddress(): 1000}])
tx_hex = self.nodes[0].fundrawtransaction(tx_hex)['hex']
tx_hex = self.nodes[0].blindrawtransaction(tx_hex)
# coming from initial free coins: no need to sign
assert_equal(self.nodes[0].testmempoolaccept([tx_hex])[0]['allowed'], True) # tx is ok

# remove a surjection proof from the tx
tx = CTransaction()
tx.deserialize(io.BytesIO(bytes.fromhex(tx_hex)))
tx.wit.vtxoutwit[0].vchSurjectionproof = b''
tx_hex = tx.serialize().hex()

# Both of these make the node crash
assert_equal(self.nodes[0].testmempoolaccept([tx_hex])[0]['allowed'], False)
assert_raises_rpc_error(-26, "bad-txns-in-ne-out", self.nodes[0].sendrawtransaction, tx_hex)

def test_no_range(self):
self.generate(self.nodes[0], 1)

tx_hex = self.nodes[0].createrawtransaction([], [{self.nodes[1].getnewaddress(): 1000}])
tx_hex = self.nodes[0].fundrawtransaction(tx_hex)['hex']
tx_hex = self.nodes[0].blindrawtransaction(tx_hex)
# coming from initial free coins: no need to sign
assert_equal(self.nodes[0].testmempoolaccept([tx_hex])[0]['allowed'], True) # tx is ok

# remove a surjection proof from the tx
tx = CTransaction()
tx.deserialize(io.BytesIO(bytes.fromhex(tx_hex)))
tx.wit.vtxoutwit[0].vchRangeproof = b''
tx_hex = tx.serialize().hex()

# Both of these make the node crash
assert_equal(self.nodes[0].testmempoolaccept([tx_hex])[0]['allowed'], False)
assert_raises_rpc_error(-26, "bad-txns-in-ne-out", self.nodes[0].sendrawtransaction, tx_hex)

def test_null_rangeproof_enforcement(self):
self.generate(self.nodes[0], 1)

Expand Down Expand Up @@ -160,6 +198,12 @@ def test_null_rangeproof_enforcement(self):

def run_test(self):

print("Testing a transaction with a missing surjection proof")
self.test_no_surj()

print("Testing a transaction with a missing range proof")
self.test_no_range()

print("Testing that null issuances must have null rangeproofs")
self.test_null_rangeproof_enforcement()

Expand Down