-
-
Notifications
You must be signed in to change notification settings - Fork 455
[UTXO-BUG] fix bridge_api validate_chain_address_format — ethereum chain accepted any string #6629
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
Open
Ivan-LB
wants to merge
2
commits into
Scottcjn:main
Choose a base branch
from
Ivan-LB:bridge-ethereum-address-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| """ | ||
| PoC: validate_chain_address_format accepted any non-empty string >= 10 chars | ||
| for the 'ethereum' chain because no elif branch existed. | ||
|
|
||
| Before fix: validate_chain_address_format("ethereum", "garbage123") -> (True, "") | ||
| After fix: validate_chain_address_format("ethereum", "garbage123") -> (False, "...") | ||
| """ | ||
| import unittest | ||
|
|
||
| try: | ||
| from bridge_api import validate_chain_address_format | ||
| except ImportError: | ||
| import sys | ||
| import os | ||
| sys.path.insert(0, os.path.dirname(__file__)) | ||
| from bridge_api import validate_chain_address_format | ||
|
|
||
|
|
||
| class TestBridgeEthereumAddressValidation(unittest.TestCase): | ||
|
|
||
| # --- rejection cases (all were previously accepted) --- | ||
|
|
||
| def test_rejects_garbage_string(self): | ||
| ok, msg = validate_chain_address_format("ethereum", "garbage1234567890") | ||
| self.assertFalse(ok, "Garbage string must be rejected") | ||
|
|
||
| def test_rejects_missing_0x_prefix(self): | ||
| ok, msg = validate_chain_address_format("ethereum", "aabbccddeeff00112233445566778899aabbccdd") | ||
| self.assertFalse(ok) | ||
| self.assertIn("0x", msg) | ||
|
|
||
| def test_rejects_wrong_length(self): | ||
| ok, msg = validate_chain_address_format("ethereum", "0xdeadbeef") | ||
| self.assertFalse(ok) | ||
|
|
||
| def test_rejects_non_hex_chars(self): | ||
| ok, msg = validate_chain_address_format("ethereum", "0x" + "g" * 40) | ||
| self.assertFalse(ok) | ||
|
|
||
| def test_rejects_empty(self): | ||
| ok, msg = validate_chain_address_format("ethereum", "") | ||
| self.assertFalse(ok) | ||
|
|
||
| # --- acceptance cases --- | ||
|
|
||
| def test_accepts_valid_lowercase(self): | ||
| ok, _ = validate_chain_address_format("ethereum", "0x" + "a" * 40) | ||
| self.assertTrue(ok) | ||
|
|
||
| def test_accepts_valid_eip55_checksum(self): | ||
| # EIP-55 checksummed address — mixed-case must match keccak-derived checksum | ||
| ok, _ = validate_chain_address_format("ethereum", "0xabCDEF1234567890ABcDEF1234567890aBCDeF12") | ||
| self.assertTrue(ok) | ||
|
|
||
| def test_rejects_invalid_mixed_case(self): | ||
| # Typo'd mixed-case that does not satisfy EIP-55 checksum | ||
| ok, msg = validate_chain_address_format("ethereum", "0xAbCdEf1234567890AbCdEf1234567890AbCdEf12") | ||
| self.assertFalse(ok) | ||
| self.assertIn("EIP-55", msg) | ||
|
|
||
| def test_accepts_zero_address(self): | ||
| ok, _ = validate_chain_address_format("ethereum", "0x" + "0" * 40) | ||
| self.assertTrue(ok) | ||
|
|
||
| # --- other chains unaffected --- | ||
|
|
||
| def test_base_still_validated(self): | ||
| ok, msg = validate_chain_address_format("base", "not-an-address") | ||
| self.assertFalse(ok) | ||
|
|
||
| def test_rustchain_unaffected(self): | ||
| ok, _ = validate_chain_address_format("rustchain", "RTC" + "a" * 40) | ||
| self.assertTrue(ok) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Reviewed #6629 against the Ethereum address validation bug. This is focused: 2 files changed, the new ethereum branch applies the same 0x/42-char/hex validation shape as Base, and the added tests cover garbage, missing prefix, wrong length, non-hex, valid lowercase, mixed case, zero address, and unchanged Base/RustChain behavior. I ran python -m pytest node/test_bridge_ethereum_address_poc.py -q and got 10 passed, and python -m py_compile node/bridge_api.py node/test_bridge_ethereum_address_poc.py passed. No blocking findings from this pass.