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

fix: enforce ERC-55 addresses #368

Merged
merged 3 commits into from
Feb 19, 2024
Merged

fix: enforce ERC-55 addresses #368

merged 3 commits into from
Feb 19, 2024

Conversation

chris13524
Copy link
Member

@chris13524 chris13524 commented Feb 15, 2024

Description

Followup to #364. CAIP-10 requires the use of ERC-55, and until now we have been permissive about this and normalized to ERC-55 internally. However, we should follow the spec and require ERC-55 now so people don't get lazy in the future.

This PR updates the logic to require ERC-55 to construct an AccountId. If this fails validation, an error will be returned to the appropriate party.

Logs show that the only non-compliance with ERC-55 is in the use of the /notify endpoint from 1 obscure project with 0 subscribers, and 1 client that appeared today. I decided not to build backwards-compatibility for these 2 entities.

Also I manually checked that all existing database rows are all eip155 accounts and are ERC-55 compliant.

How Has This Been Tested?

Existing tests

Due Diligence

  • Breaking change
  • Requires a documentation update
  • Requires a e2e/integration test update

@chris13524 chris13524 self-assigned this Feb 15, 2024
@chris13524 chris13524 marked this pull request as ready for review February 15, 2024 23:04
Copy link

@nopestack nopestack left a comment

Choose a reason for hiding this comment

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

LGTM. Left a minor comment

.get_or_init(|| regex::Regex::new(r"^eip155:\d+:0x(?<address>[0-9a-fA-F]{40})$").unwrap());

if let Some(caps) = pattern.captures(account_id) {
let address = &caps["address"];

Choose a reason for hiding this comment

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

I'd do an if let Some here

Copy link
Member Author

@chris13524 chris13524 Feb 19, 2024

Choose a reason for hiding this comment

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

What's the error handling behavior if address isn't present? This is like a coding failure here, not a runtime error. If the regex matches then address must exist which is why I did [] instead of .get()

Copy link
Member Author

Choose a reason for hiding this comment

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

Index<&str> only panics if there isn't a capture group with the given name.

But this could panic if I made a mistake in the regex such as conditionally matching. Looks like there's a slightly better alternative, extract, which panics if the number of possible matching groups in this Captures value is not fixed to N in all circumstances. So although it doesn't support named capture groups, it would result in catching any introduction of | operators in the regex. I switched to this in 1658283

Choose a reason for hiding this comment

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

What's the error handling behavior if address isn't present? This is like a coding failure here, not a runtime error. If the regex matches then address must exist which is why I did [] instead of .get()

Initially I'd just log the error and figure it out if/when it becomes a problem but you found a better approach now 👍

Copy link
Contributor

@geekbrother geekbrother left a comment

Choose a reason for hiding this comment

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

Nice!

@chris13524 chris13524 merged commit c48df03 into main Feb 19, 2024
13 checks passed
@chris13524 chris13524 deleted the fix/enforce-erc55 branch February 19, 2024 19:55
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