Skip to content

feat(sign): optimize signing exception log#5446

Merged
halibobo1205 merged 1 commit intotronprotocol:developfrom
lurais:feature/optimize_validate_sign_log
Aug 30, 2023
Merged

feat(sign): optimize signing exception log#5446
halibobo1205 merged 1 commit intotronprotocol:developfrom
lurais:feature/optimize_validate_sign_log

Conversation

@lurais
Copy link
Copy Markdown
Contributor

@lurais lurais commented Aug 23, 2023

What does this PR do?
Optimize signing exception log, close #5423

Why are these changes required?
Standardize the signing related exception

This PR has been tested by:

  • Unit Tests
  • Manual Testing

Follow up

Extra details

@lurais lurais changed the title feat(sign): optimize sign exception log feat(sign): optimize signing exception log Aug 23, 2023
@lurais lurais force-pushed the feature/optimize_validate_sign_log branch from 2b033c6 to 5c8a233 Compare August 23, 2023 10:04
}
return SM2.signatureToAddress(messageHash, signatureBase64);
} catch(IllegalArgumentException e) {
if (e.getMessage().contains("Invalid point compression")) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why special treatment, I understand that you can throw a SignatureException whenever signatureToAddress is incorrect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Currently only the exception with message like "Invalid point compression" can be sure to deal like this way, and other kind of messages can not be found now, that means just treat it like this may be not correct and that will not be noticed in this way.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not sure I agree with this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From the method signatureToKeyBytes in class ECKey, other kinds of error messages has been judged, that means not treat them the same, and it is core method ,any error messages deserved to be noticed, if we are not sure how to deal, we should throw it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Which scenarios will generate IllegalArgumentException?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IllegalArgumentException

When the signature is not correct but the length is right, for example, if someone send a transaction , and the correct signature is "abc", but it was replaced to "001", that will bring it a IllegalArgumentException.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually, I think all exceptions in this scene are SignatureException even 001

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, I think all exceptions in this scene are SignatureException even 001

yes , it is clear to throw an SignatureException in this scene, while the point is that shall we just throw a SignatureException in any unknown scene. @tomatoishealthy

Copy link
Copy Markdown
Contributor

@tomatoishealthy tomatoishealthy Aug 29, 2023

Choose a reason for hiding this comment

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

I guess I have got your point, let's analogy with an example: imaging that there is a method func add(Object a, Object b) return int which is used for plus a and b and returns the sum.

As you mentioned above, if a or b is a string type, we should throw IllegalArgumentException. If a or b is a float or double type which is not an integer but can be executed with math calculation, we should throw another exception(whatever the exception type is).

In this example, we can clearly know all exceptions may occur, but for signature, how you can identify other exceptions? Just as you say, the signature was replaced to 001 from abc, and the length is the same, for the signatureToAddress() it won't know whether the signature is matched only after doing the check.

Do you think 001 is a wrong signature just because it was constructed by number? if so, you may need to do research on whether numbers can be parts of a signature.

Meanwhile, if numbers can't be parts of a signature and you want to intercept these exceptions, better to add an extra parameter check logic and put the logic before signatureToAddress()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated.

@halibobo1205
Copy link
Copy Markdown
Collaborator

@lurais Please re-check your PR and don't bring any irrelevant information.

@lurais lurais force-pushed the feature/optimize_validate_sign_log branch from 8b59783 to 0efeae8 Compare August 24, 2023 08:41
@tomatoishealthy
Copy link
Copy Markdown
Contributor

Better link an issue and show your motivation, or give more details in this content

@lurais
Copy link
Copy Markdown
Contributor Author

lurais commented Aug 25, 2023

updated. @tomatoishealthy

@lurais lurais force-pushed the feature/optimize_validate_sign_log branch 2 times, most recently from 11141c6 to ffc08a5 Compare August 29, 2023 14:03
@lurais lurais force-pushed the feature/optimize_validate_sign_log branch from ffc08a5 to 52a3e53 Compare August 29, 2023 14:16
Copy link
Copy Markdown
Collaborator

@halibobo1205 halibobo1205 left a comment

Choose a reason for hiding this comment

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

LGTM

@halibobo1205 halibobo1205 merged commit 4ada90e into tronprotocol:develop Aug 30, 2023
@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.7.3 milestone Sep 12, 2023
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.

Optimize error logs in signature verification

4 participants