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

[BUG] Zilliqa::Util::Validator.address? false positives #8

Open
zhulik opened this issue Sep 17, 2019 · 0 comments
Open

[BUG] Zilliqa::Util::Validator.address? false positives #8

zhulik opened this issue Sep 17, 2019 · 0 comments

Comments

@zhulik
Copy link

zhulik commented Sep 17, 2019

Zilliqa::Util::Validator.address? returns false positives for obviously invalid addresses.

address = "zil1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Zilliqa::Util::Validator.address?(address)

Expected result:
false

Actual result:
true

Seems like Zilliqa::Util::Validator.address? uses only regexps to validate the address and doesn't check if the argument is a valid bech32 address.

I found a workaround:

address = "zil1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Zilliqa::Util::Validator.address?(Zilliqa::Util::Bech32.from_bech32(address)) rescue false

this snippet returns false because Zilliqa::Util::Bech32.from_bech32(address) raises an error when invalid address is passed:

2.6.3 :006 > Zilliqa::Util::Bech32.from_bech32(address)
Traceback (most recent call last):
        2: from (irb):6
        1: from (irb):6:in `rescue in irb_binding'
NoMethodError (undefined method `[]' for nil:NilClass)

It might make sense to check if the argument of Zilliqa::Util::Validator.address? is a valid bech32 address. WDYT?

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

No branches or pull requests

1 participant