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

types: Reject non canonical addresses in DecodeAddress #595

Merged
merged 2 commits into from
Aug 22, 2023

Conversation

algochoi
Copy link
Contributor

@algochoi algochoi commented Aug 21, 2023

Checks that the address to decode is a canonical representation (least significant bit is 00, i.e. the ending character is one of "AEIMQUY4"). Adds a test to check that non-canonical addresses are rejected.

Note that the server (and most goal commands) will reject non-canonical addresses, but our SDK clients don't seem to check this.

Closes #274

@algochoi algochoi self-assigned this Aug 21, 2023
@algochoi algochoi changed the title Reject non canonical addresses in DecodeAddress types: Reject non canonical addresses in DecodeAddress Aug 21, 2023
@@ -94,6 +95,13 @@ func DecodeAddress(addr string) (a Address, err error) {

// Checksum is good, copy address bytes into output
copy(a[:], addressBytes)

// Check if address is canonical
Copy link
Contributor Author

@algochoi algochoi Aug 21, 2023

Choose a reason for hiding this comment

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

@algochoi algochoi marked this pull request as ready for review August 21, 2023 15:58
@algochoi algochoi requested review from a team, winder, tzaffi, Eric-Warehime and shiqizng and removed request for a team August 22, 2023 14:05
Copy link
Contributor

@tzaffi tzaffi left a comment

Choose a reason for hiding this comment

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

Approving as this looks very good.

Minor nit: consider modding "correct, and ..." to "correct and canonical, and ..." in the function comment.

@@ -65,7 +65,8 @@ func (a *Address) UnmarshalText(text []byte) error {
}

// DecodeAddress turns a checksum address string into an Address object. It
// checks that the checksum is correct, and returns an error if it's not.
// checks that the checksum is correct and whether the address is canonical,
// and returns an error if it's not.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@algochoi algochoi merged commit 92cfa33 into develop Aug 22, 2023
3 checks passed
@algochoi algochoi deleted the non-canon-addr-check branch August 22, 2023 17:37
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.

Add canonical check
3 participants