Skip to content
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

refactor: Revert additional univalue check in ParseSighashString #28162

Merged
merged 2 commits into from
Jul 28, 2023

Conversation

TheCharlatan
Copy link
Contributor

This is a follow up for #28113.

The string type check is already done by the rpc parser / RPCHelpMan. Re-doing it is adding dead code. Instead, throwing an exception when the assumption does not hold is the already correct behavior. Pointed out in this comment.

Also correct the release note for the correct sighashtype exception change. There is no change in the handling of non-string sighashtype arugments. Pointed out in this comment.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 26, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK stickies-v, MarcoFalke, jonatack

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach ACK on the release notes updates (nice catch MarcoFalke), not so sure about the code changes yet.

src/test/fuzz/parse_univalue.cpp Outdated Show resolved Hide resolved
@TheCharlatan
Copy link
Contributor Author

TheCharlatan commented Jul 27, 2023

Updated cc266f9 -> 06199a9 (kernelRmUnivalueFollowup_0 -> kernelRmUnivalueFollowup_1, compare)

  • Addressed @stickies-v's comment, changed univalue fuzz test implementation as suggested and added a docstring for documenting the function's precondition.
  • Addressed @jonatack's comment, changed description as suggested.

This check is already done by the rpc parser. Re-doing it is adding dead
code. Instead, throwing an exception when the assumption does not hold
is the already correct behavior.

To make the fuzz test more accurate and not swallow all runtime errors,
add a check that the passed in UniValue sighash argument is either a
string or null.

Co-authored-by: stickies-v <stickies-v@protonmail.com>
Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 06199a9

@maflcko
Copy link
Member

maflcko commented Jul 27, 2023

lgtm ACK 06199a9

@@ -67,7 +67,7 @@ FUZZ_TARGET(parse_univalue, .init = initialize_parse_univalue)
} catch (const std::runtime_error&) {
}
try {
(void)ParseSighashString(univalue);
if (univalue.isNull() || univalue.isStr()) (void)ParseSighashString(univalue);
Copy link
Contributor

@stickies-v stickies-v Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh actually, would this be better? Equally clear (I think), but we still feed it unexpected types.

diff --git a/src/test/fuzz/parse_univalue.cpp b/src/test/fuzz/parse_univalue.cpp
index a3d6ab6375..df3410eab8 100644
--- a/src/test/fuzz/parse_univalue.cpp
+++ b/src/test/fuzz/parse_univalue.cpp
@@ -67,8 +67,10 @@ FUZZ_TARGET(parse_univalue, .init = initialize_parse_univalue)
     } catch (const std::runtime_error&) {
     }
     try {
-        if (univalue.isNull() || univalue.isStr()) (void)ParseSighashString(univalue);
+        (void)ParseSighashString(univalue);
     } catch (const UniValue&) {
+    } catch (std::runtime_error&) {
+        if(univalue.isNull() || univalue.isStr()) throw;  //a non-null, non-string univalue is expected to throw on .get_str()
     }
     try {
         (void)AmountFromValue(univalue);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might also want to catch it NOT throwing an error when it ought to.

@jonatack
Copy link
Contributor

Tested ACK 06199a9

Verified relevant tests still pass after cherry-picking 647d95a from #28166 to this branch.

I don't mind re-ACKing if you like the suggestion in #28162 (comment) (mind the spaces on the last line of its diff or run clang-format on it).

@fanquake fanquake merged commit 42a9110 into bitcoin:master Jul 28, 2023
15 checks passed
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 9, 2023
…rseSighashString

06199a9 refactor: Revert addition of univalue sighash string check (TheCharlatan)
0b47c16 doc: Correct release-notes for sighashtype exceptions (TheCharlatan)

Pull request description:

  This is a follow up for bitcoin#28113.

  The string type check is already done by the rpc parser / RPCHelpMan. Re-doing it is adding dead code. Instead, throwing an exception when the assumption does not hold is the already correct behavior. Pointed out in this [comment](https://github.com/bitcoin/bitcoin/pull/28113/files#r1274568557).

  Also correct the release note for the correct sighashtype exception change. There is no change in the handling of non-string sighashtype arugments. Pointed out in this [comment](https://github.com/bitcoin/bitcoin/pull/28113/files#r1274567555).

ACKs for top commit:
  MarcoFalke:
    lgtm ACK 06199a9
  jonatack:
    Tested ACK 06199a9
  stickies-v:
    ACK 06199a9

Tree-SHA512: 3faa6b3d2247624c0973df8d79c09fbf1f90ffb99f1be484e359b528f485c31affea45976759bd206e4c81cbb54ebba5ad0ef4127d1deacbfe2a58153fcc94ee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants