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

Improves checksum error message #3031

Merged
merged 6 commits into from
Nov 17, 2017
Merged

Improves checksum error message #3031

merged 6 commits into from
Nov 17, 2017

Conversation

wadealexc
Copy link
Contributor

@wadealexc wadealexc commented Oct 5, 2017

Now displays the correct checksummed address and gives a link to ethereum/EIPs#55

Issue 2094: #2094

@@ -103,3 +103,26 @@ bool dev::passesAddressChecksum(string const& _str, bool _strict)
}
return true;
}

std::string dev::getChecksumAddress(std::string const& _addr)
Copy link
Member

Choose a reason for hiding this comment

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

This could use some refactor and common parts be shared between this and passesAddressChecksum.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll push something up in a moment. One thing I think I could do as well, is just get rid of the check to see if addressCharacter is a number or not - according to isupper docs, it'll return the same character if a number (or something without an uppercase component) is passed in. I wasn't sure if I should leave the check in for clarity though.

@wadealexc
Copy link
Contributor Author

Refactored. Let me know if that's what you had in mind.

@axic
Copy link
Member

axic commented Oct 10, 2017

Sorry, by refactoring I've meant to pull out the common parts between the two functions.

"If this is not used as an address, please prepend '00'."
"If this is not used as an address, please prepend '00'. "
"Correct checksummed address: '" + _literal.getChecksumAddress() + "'. "
"For more information, please see https://github.com/ethereum/EIPs/issues/55"
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. I'll change that.

@wadealexc
Copy link
Contributor Author

Okay - for clarification, you want a few helper functions that both functions call? Like "getAddressSubstring," "getAddressHash," and "getNibble"?

@axic
Copy link
Member

axic commented Oct 11, 2017

There should be one which converts an address (like the one you have right now) to the mixed-case version and that can be used in the verify function to compare with the supplied one.

@wadealexc
Copy link
Contributor Author

Changed and fixed. Let me know if there's anything else you see

@axic axic force-pushed the develop branch 4 times, most recently from ad54a55 to d0dd7b1 Compare October 20, 2017 14:29
Copy link
Member

@axic axic left a comment

Choose a reason for hiding this comment

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

I think this should be good now.

@axic
Copy link
Member

axic commented Oct 20, 2017

@chriseth can you review this now?

h256 hash = keccak256(boost::algorithm::to_lower_copy(s, std::locale::classic()));

assertThrow(s.length == 40, "");
assertThrow(hash.find_first_not_of("abcdef") == string::npos, "");
Copy link
Contributor

Choose a reason for hiding this comment

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

hash is a h256, i.e. it is binary data. I don't think we should search for hex digits there.

Copy link
Member

Choose a reason for hiding this comment

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

Yeh it should be done before on the input.

@@ -2000,7 +2000,9 @@ void TypeChecker::endVisit(Literal const& _literal)
m_errorReporter.warning(
_literal.location(),
"This looks like an address but has an invalid checksum. "
"If this is not used as an address, please prepend '00'."
"If this is not used as an address, please prepend '00'. "
"Correct checksummed address: '" + _literal.getChecksumAddress() + "'. "
Copy link
Contributor

Choose a reason for hiding this comment

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

looksLikeAddress cat retur true for strings of length 39, 40 and 41, but getChecksumAddress asserts that the string is exactly 40 hex digits long.

Copy link
Member

Choose a reason for hiding this comment

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

Either we add another condition here and display the "correct" checksum if it is 40 characters or we just don't display it at all. It is worth displaying it?

Copy link
Contributor

Choose a reason for hiding this comment

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

We should display the correct checksum for 40 characters. Otherwise, we tell the user the correct length. I think a compiler should always supply an "easy fix" method, if it exists. It is in the user's responsibility to accept it or not.

Copy link
Member

Choose a reason for hiding this comment

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

What is the idea behind doing this for 41 hex digits?

Copy link
Contributor

Choose a reason for hiding this comment

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

I basically see the following reasons for a checksum failure:

  • typing a wrong hex digit
  • swapping two hex digits
  • repeating a hex digit (or generally, adding a non-existing hex digit)
  • leaving out a hex digit

Because of that, we should treat hex digit sequences of lengths 39, 40 and 41 as possible addresses.

Copy link
Contributor

@chriseth chriseth left a comment

Choose a reason for hiding this comment

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

Please do not call getChecksummedAddress for strings of wrong length (instead, tell the user about that fact).

@axic axic force-pushed the develop branch 4 times, most recently from f51577c to 0e7742c Compare October 24, 2017 11:19
@axic
Copy link
Member

axic commented Oct 24, 2017

@chriseth ready for review

@axic
Copy link
Member

axic commented Nov 15, 2017

Should add separate tests for getChecksummedAddress.

@axic axic merged commit 2b5ef80 into ethereum:develop Nov 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants