-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
3311509
to
81b0259
Compare
There was a problem hiding this 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
src/model/types/account_id.rs
Outdated
.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"]; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 thenaddress
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 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
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