Skip to content
New issue

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

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

Already on GitHub? # to your account

Change address constructors to explicit #1151

Merged
merged 4 commits into from
Oct 11, 2022

Conversation

abitmore
Copy link
Member

@abitmore abitmore commented Jul 18, 2018

This PR is mainly for making clear how public keys are being ordered in the system, aka explicitly implement

bool operator < ( const public_key_type&, const public_key_type&);

and make sure it's backward-compatible (convert the public keys to addresses and compare the addresses).

More info is here: cryptonomex/graphene#630 (comment) .

The == operators are mainly used in balance_evaluator.cpp, actually I'm not sure whether it's good to have them (does it make sense to compare a pts_address with an address, or compare a public key to an address?), please advise.

GRAPHENE_ASSERT(
op.balance_owner_key == balance->owner ||
pts_address(op.balance_owner_key, false, 56) == balance->owner ||
pts_address(op.balance_owner_key, true, 56) == balance->owner ||
pts_address(op.balance_owner_key, false, 0) == balance->owner ||
pts_address(op.balance_owner_key, true, 0) == balance->owner,

@jmjatlanta
Copy link
Contributor

The equality operator here boils down to a memcmp of the 2 ripemd160 hashes.

https://github.com/bitshares/bitshares-fc/blob/d679377312d715840408d2990f824d2c6e729aea/src/crypto/ripemd160.cpp#L98-L100

Are you attempting to replace the GRAPHENE_ASSERT with something else? What would you suggest they be replaced with?

Perhaps I am misunderstanding why you are questioning whether it is good to have the equality operators.

@abitmore
Copy link
Member Author

My question was: does it make sense to compare a pts_address with an address, or compare a public key to an address?

@abitmore abitmore requested a review from pmconrad July 21, 2018 18:51
@pmconrad
Copy link
Contributor

As mentioned on Telegram, I'm undecided if we should merge this in the upcoming release.

I generally think explicit constructors are better, because that avoids surprising automatic conversion.

OTOH making existing constructors explicit can have surprising side effects, so the change is a bit dangerous.

@pmconrad
Copy link
Contributor

Surprising side-effects could be avoided by changing all one-argument constructors to explicit.
SonarQube lists 61 such issues in the core code, not counting those in fc nor test suites.

@abitmore
Copy link
Member Author

Makes sense. I've removed it from this milestone.

@ryanRfox
Copy link
Contributor

ryanRfox commented Sep 3, 2018

Is there a desire to revisit this PR for the 201810 Feature Release?

@pmconrad
Copy link
Contributor

Like I said, we should make all one-arg constructors explicit in one go. But I think we have more important stuff and little time for the next release, so I'd drop it from this one.

@abitmore
Copy link
Member Author

Moving to next milestone.

@ryanRfox
Copy link
Contributor

ryanRfox commented Feb 1, 2019

@pmconrad Sorry, my meeting notes are lacking, so request you comment here with proper instructions for this PR. This is what I captured: "recommendation for now until we decide how to do all explicit constructors"

@pmconrad
Copy link
Contributor

pmconrad commented Feb 4, 2019

See my comment above - merging this now could have unforeseeable side effects. Better to switch all one-arg constructors to explicit at once.

@abitmore abitmore changed the title Changed address constructors to explicit Change address constructors to explicit Apr 23, 2019
Resolved conflicts:
- libraries/chain/include/graphene/chain/protocol/types.hpp
- libraries/chain/protocol/types.cpp
- libraries/protocol/include/graphene/protocol/address.hpp
- libraries/wallet/wallet.cpp
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

90.0% 90.0% Coverage
0.0% 0.0% Duplication

@abitmore abitmore merged commit e37fa14 into develop Oct 11, 2022
@abitmore abitmore deleted the explicit-address-construction branch October 11, 2022 18:39
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants