Skip to content

Commit 7718ab8

Browse files
committed
cpp: fix verify functions to ignore errors
1 parent faa5445 commit 7718ab8

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

include/wally.hpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ inline int ae_signer_commit_from_bytes(const PRIV_KEY& priv_key, const BYTES& by
374374
}
375375

376376
template <class PUB_KEY, class BYTES, class ENTROPY, class S2C_OPENING, class SIG>
377-
inline int ae_verify(const PUB_KEY& pub_key, const BYTES& bytes, const ENTROPY& entropy, const S2C_OPENING& s2c_opening, uint32_t flags, const SIG& sig) {
377+
inline bool ae_verify(const PUB_KEY& pub_key, const BYTES& bytes, const ENTROPY& entropy, const S2C_OPENING& s2c_opening, uint32_t flags, const SIG& sig) {
378378
int ret = ::wally_ae_verify(pub_key.data(), pub_key.size(), bytes.data(), bytes.size(), entropy.data(), entropy.size(), s2c_opening.data(), s2c_opening.size(), flags, sig.data(), sig.size());
379-
return detail::check_ret(__FUNCTION__, ret);
379+
return ret == WALLY_OK;
380380
}
381381

382382
template <class KEY, class BYTES, class BYTES_OUT>
@@ -630,9 +630,9 @@ inline int ec_private_key_bip341_tweak(const PRIV_KEY& priv_key, const MERKLE_RO
630630
}
631631

632632
template <class PRIV_KEY>
633-
inline int ec_private_key_verify(const PRIV_KEY& priv_key) {
633+
inline bool ec_private_key_verify(const PRIV_KEY& priv_key) {
634634
int ret = ::wally_ec_private_key_verify(priv_key.data(), priv_key.size());
635-
return detail::check_ret(__FUNCTION__, ret);
635+
return ret == WALLY_OK;
636636
}
637637

638638
template <class PUB_KEY, class MERKLE_ROOT, class BYTES_OUT>
@@ -660,9 +660,9 @@ inline int ec_public_key_negate(const PUB_KEY& pub_key, BYTES_OUT& bytes_out) {
660660
}
661661

662662
template <class PUB_KEY>
663-
inline int ec_public_key_verify(const PUB_KEY& pub_key) {
663+
inline bool ec_public_key_verify(const PUB_KEY& pub_key) {
664664
int ret = ::wally_ec_public_key_verify(pub_key.data(), pub_key.size());
665-
return detail::check_ret(__FUNCTION__, ret);
665+
return ret == WALLY_OK;
666666
}
667667

668668
template <class SCALAR, class OPERAND, class BYTES_OUT>
@@ -702,9 +702,9 @@ inline int ec_scalar_subtract_from(SCALAR& scalar, const OPERAND& operand) {
702702
}
703703

704704
template <class SCALAR>
705-
inline int ec_scalar_verify(const SCALAR& scalar) {
705+
inline bool ec_scalar_verify(const SCALAR& scalar) {
706706
int ret = ::wally_ec_scalar_verify(scalar.data(), scalar.size());
707-
return detail::check_ret(__FUNCTION__, ret);
707+
return ret == WALLY_OK;
708708
}
709709

710710
template <class PRIV_KEY, class BYTES, class BYTES_OUT>
@@ -756,15 +756,15 @@ inline int ec_sig_to_public_key(const BYTES& bytes, const SIG& sig, BYTES_OUT& b
756756
}
757757

758758
template <class PUB_KEY, class BYTES, class SIG>
759-
inline int ec_sig_verify(const PUB_KEY& pub_key, const BYTES& bytes, uint32_t flags, const SIG& sig) {
759+
inline bool ec_sig_verify(const PUB_KEY& pub_key, const BYTES& bytes, uint32_t flags, const SIG& sig) {
760760
int ret = ::wally_ec_sig_verify(pub_key.data(), pub_key.size(), bytes.data(), bytes.size(), flags, sig.data(), sig.size());
761-
return detail::check_ret(__FUNCTION__, ret);
761+
return ret == WALLY_OK;
762762
}
763763

764764
template <class PUB_KEY>
765-
inline int ec_xonly_public_key_verify(const PUB_KEY& pub_key) {
765+
inline bool ec_xonly_public_key_verify(const PUB_KEY& pub_key) {
766766
int ret = ::wally_ec_xonly_public_key_verify(pub_key.data(), pub_key.size());
767-
return detail::check_ret(__FUNCTION__, ret);
767+
return ret == WALLY_OK;
768768
}
769769

770770
template <class PUB_KEY, class PRIV_KEY, class BYTES_OUT>
@@ -819,9 +819,9 @@ inline int hex_n_to_bytes(const HEX& hex, size_t hex_len, BYTES_OUT& bytes_out,
819819
}
820820

821821
template <class HEX>
822-
inline int hex_n_verify(const HEX& hex, size_t hex_len) {
822+
inline bool hex_n_verify(const HEX& hex, size_t hex_len) {
823823
int ret = ::wally_hex_n_verify(detail::get_p(hex), hex_len);
824-
return detail::check_ret(__FUNCTION__, ret);
824+
return ret == WALLY_OK;
825825
}
826826

827827
template <class HEX, class BYTES_OUT>
@@ -830,9 +830,9 @@ inline int hex_to_bytes(const HEX& hex, BYTES_OUT& bytes_out, size_t* written) {
830830
return detail::check_ret(__FUNCTION__, ret);
831831
}
832832

833-
inline int hex_verify(const char* hex) {
833+
inline bool hex_verify(const char* hex) {
834834
int ret = ::wally_hex_verify(hex);
835-
return detail::check_ret(__FUNCTION__, ret);
835+
return ret == WALLY_OK;
836836
}
837837

838838
template <class KEY, class BYTES, class BYTES_OUT>
@@ -858,9 +858,9 @@ inline int is_elements_build(size_t* written) {
858858
}
859859

860860
template <class KEY, class VAL>
861-
inline int keypath_bip32_verify(const KEY& key, const VAL& val) {
861+
inline bool keypath_bip32_verify(const KEY& key, const VAL& val) {
862862
int ret = ::wally_keypath_bip32_verify(key.data(), key.size(), val.data(), val.size());
863-
return detail::check_ret(__FUNCTION__, ret);
863+
return ret == WALLY_OK;
864864
}
865865

866866
template <class VAL, class BYTES_OUT>
@@ -882,15 +882,15 @@ inline int keypath_get_path_len(const VAL& val, size_t* written) {
882882
}
883883

884884
template <class KEY, class VAL>
885-
inline int keypath_public_key_verify(const KEY& key, const VAL& val) {
885+
inline bool keypath_public_key_verify(const KEY& key, const VAL& val) {
886886
int ret = ::wally_keypath_public_key_verify(key.data(), key.size(), val.data(), val.size());
887-
return detail::check_ret(__FUNCTION__, ret);
887+
return ret == WALLY_OK;
888888
}
889889

890890
template <class KEY, class VAL>
891-
inline int keypath_xonly_public_key_verify(const KEY& key, const VAL& val) {
891+
inline bool keypath_xonly_public_key_verify(const KEY& key, const VAL& val) {
892892
int ret = ::wally_keypath_xonly_public_key_verify(key.data(), key.size(), val.data(), val.size());
893-
return detail::check_ret(__FUNCTION__, ret);
893+
return ret == WALLY_OK;
894894
}
895895

896896
template <class MAP_IN, class KEY, class VALUE>
@@ -988,9 +988,9 @@ inline int map_get_num_items(const MAP_IN& map_in, size_t* written) {
988988
}
989989

990990
template <class KEY, class VAL>
991-
inline int map_hash_preimage_verify(const KEY& key, const VAL& val) {
991+
inline bool map_hash_preimage_verify(const KEY& key, const VAL& val) {
992992
int ret = ::wally_map_hash_preimage_verify(key.data(), key.size(), val.data(), val.size());
993-
return detail::check_ret(__FUNCTION__, ret);
993+
return ret == WALLY_OK;
994994
}
995995

996996
inline int map_init(size_t allocation_len, wally_map_verify_fn_t verify_fn, struct wally_map* output) {
@@ -1109,9 +1109,9 @@ inline int map_sort(const MAP_IN& map_in, uint32_t flags) {
11091109
}
11101110

11111111
template <class KEY, class VAL>
1112-
inline int merkle_path_xonly_public_key_verify(const KEY& key, const VAL& val) {
1112+
inline bool merkle_path_xonly_public_key_verify(const KEY& key, const VAL& val) {
11131113
int ret = ::wally_merkle_path_xonly_public_key_verify(key.data(), key.size(), val.data(), val.size());
1114-
return detail::check_ret(__FUNCTION__, ret);
1114+
return ret == WALLY_OK;
11151115
}
11161116

11171117
template <class PASS, class SALT, class BYTES_OUT>
@@ -1612,9 +1612,9 @@ inline int ripemd160(const BYTES& bytes, BYTES_OUT& bytes_out) {
16121612
}
16131613

16141614
template <class SIG, class S2C_DATA, class S2C_OPENING>
1615-
inline int s2c_commitment_verify(const SIG& sig, const S2C_DATA& s2c_data, const S2C_OPENING& s2c_opening, uint32_t flags) {
1615+
inline bool s2c_commitment_verify(const SIG& sig, const S2C_DATA& s2c_data, const S2C_OPENING& s2c_opening, uint32_t flags) {
16161616
int ret = ::wally_s2c_commitment_verify(sig.data(), sig.size(), s2c_data.data(), s2c_data.size(), s2c_opening.data(), s2c_opening.size(), flags);
1617-
return detail::check_ret(__FUNCTION__, ret);
1617+
return ret == WALLY_OK;
16181618
}
16191619

16201620
template <class PRIV_KEY, class BYTES, class S2C_DATA, class S2C_OPENING_OUT, class BYTES_OUT>
@@ -2326,9 +2326,9 @@ inline int explicit_rangeproof(uint64_t value, const NONCE& nonce, const VBF& vb
23262326
}
23272327

23282328
template <class RANGEPROOF, class COMMITMENT, class GENERATOR>
2329-
inline int explicit_rangeproof_verify(const RANGEPROOF& rangeproof, uint64_t value, const COMMITMENT& commitment, const GENERATOR& generator) {
2329+
inline bool explicit_rangeproof_verify(const RANGEPROOF& rangeproof, uint64_t value, const COMMITMENT& commitment, const GENERATOR& generator) {
23302330
int ret = ::wally_explicit_rangeproof_verify(rangeproof.data(), rangeproof.size(), value, commitment.data(), commitment.size(), generator.data(), generator.size());
2331-
return detail::check_ret(__FUNCTION__, ret);
2331+
return ret == WALLY_OK;
23322332
}
23332333

23342334
template <class OUTPUT_ASSET, class OUTPUT_ABF, class OUTPUT_GENERATOR, class BYTES_OUT>
@@ -2338,9 +2338,9 @@ inline int explicit_surjectionproof(const OUTPUT_ASSET& output_asset, const OUTP
23382338
}
23392339

23402340
template <class SURJECTIONPROOF, class OUTPUT_ASSET, class OUTPUT_GENERATOR>
2341-
inline int explicit_surjectionproof_verify(const SURJECTIONPROOF& surjectionproof, const OUTPUT_ASSET& output_asset, const OUTPUT_GENERATOR& output_generator) {
2341+
inline bool explicit_surjectionproof_verify(const SURJECTIONPROOF& surjectionproof, const OUTPUT_ASSET& output_asset, const OUTPUT_GENERATOR& output_generator) {
23422342
int ret = ::wally_explicit_surjectionproof_verify(surjectionproof.data(), surjectionproof.size(), output_asset.data(), output_asset.size(), output_generator.data(), output_generator.size());
2343-
return detail::check_ret(__FUNCTION__, ret);
2343+
return ret == WALLY_OK;
23442344
}
23452345

23462346
template <class PSBT, class SCALAR>

tools/build_wrappers.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ def gen_wally_hpp(funcs, all_funcs):
302302
if skip:
303303
skip = False
304304
continue
305+
is_verify_function = func.name.endswith('_verify')
305306
if is_buffer(func, arg, n, num_args) or is_int_buffer(func, arg, n, num_args):
306307
t_types.append(f'class {arg.name.upper()}')
307308
const = u'const ' if arg.is_const else ''
@@ -328,14 +329,18 @@ def gen_wally_hpp(funcs, all_funcs):
328329
if len(t_types):
329330
impl.append(f'template <{", ".join(t_types)}>')
330331
func_name = strip_wally_prefix(func.name)
331-
impl.append(f'inline int {func_name}({", ".join(cpp_args)}) {{')
332+
return_type = 'bool' if is_verify_function else 'int'
333+
impl.append(f'inline {return_type} {func_name}({", ".join(cpp_args)}) {{')
332334
if vardecl:
333335
impl.append(vardecl)
334336
impl.append(f' int ret = ::{func.name}({", ".join(call_args)});')
335337
if vardecl:
336338
prev = func.args[-3]
337339
impl.append(f' if (ret == WALLY_OK && n != static_cast<size_t>({prev.name}.size())) ret = WALLY_EINVAL;')
338-
impl.append(f' return detail::check_ret(__FUNCTION__, ret);')
340+
if is_verify_function:
341+
impl.append(f' return ret == WALLY_OK;')
342+
else:
343+
impl.append(f' return detail::check_ret(__FUNCTION__, ret);')
339344
impl.extend([u'}', u''])
340345
(cpp_elements if func.is_elements else cpp)[func.name] = impl
341346

0 commit comments

Comments
 (0)