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: Remove unused and fragile string interface from arith_uint256 #28924

Merged
merged 2 commits into from
Dec 7, 2023

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Nov 21, 2023

The string interface (base_uint(const std::string&), as well as base_uint::SetHex) is problematic for many reasons:

  • It is unused (except in test-only code).
  • It is redundant with the uint256 string interface: std::string -> uint256 -> UintToArith256.
  • It is brittle, because it inherits the brittle uint256 string interface, which is brittle due to the use of c_str() (embedded null will be treated as end-of string), etc ...

Instead of fixing the interface, remove it since it is unused and redundant with UintToArith256.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 21, 2023

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK TheCharlatan, ajtowns

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

@DrahtBot DrahtBot changed the title refactor: Remove unused and fragile string interface from arith_uint256 refactor: Remove unused and fragile string interface from arith_uint256 Nov 21, 2023
@@ -95,25 +96,25 @@ BOOST_AUTO_TEST_CASE( basics ) // constructors, equality, inequality
BOOST_CHECK(ZeroL == (OneL << 256));

// String Constructor and Copy Constructor
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment should be adjusted, since there is no arith_uint256(const std::string& str) constructor anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is fine to call construction from a string "string constructor", but may change if I have to re-touch again for other reasons.

src/test/uint256_tests.cpp Show resolved Hide resolved
BOOST_CHECK(arith_uint256S(R1L.ToString()) == R1L);
BOOST_CHECK(arith_uint256S(" 0x" + R1L.ToString() + " ") == R1L);
BOOST_CHECK(arith_uint256S("") == ZeroL);
BOOST_CHECK(R1L == arith_uint256S(R1ArrayHex));
Copy link
Contributor

Choose a reason for hiding this comment

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

These same tests also exist in uint256_tests. What are these additionally testing now? Can they be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

There are two files. arith_uint256_tests.cpp, which mostly tests the arith* class, and uint256_tests.cpp, which mostly tests the uint* class.

Copy link
Contributor

Choose a reason for hiding this comment

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

They're not really testing arith_uint256 anymore though, just the new conversion helper. I don't feel strongly about this, these are just a bunch of test lines after all, but was curious what the criteria was here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this line is checking the arith_uint::operator==, or maybe a test self-sanity-check? Seems fine to keep when in doubt, I guess.

Copy link
Contributor

@TheCharlatan TheCharlatan left a comment

Choose a reason for hiding this comment

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

ACK fa63f16

@ajtowns
Copy link
Contributor

ajtowns commented Dec 7, 2023

ACK fa63f16

@fanquake fanquake merged commit fcdb39d into bitcoin:master Dec 7, 2023
16 checks passed
@maflcko maflcko deleted the 2311-arith-less-brittle- branch January 3, 2024 15:01
@bitcoin bitcoin locked and limited conversation to collaborators Jan 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants