-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
EIP-1191: extends EIP-55 by optionally adding a chain id defined by EIP-155 to the checksum calculation #1191
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a519ce0
EIP Add chain id to mixed-case checksum address encoding
juli f161fb1
Merge branch 'master' into master
juli 89a9eb9
Fixes header
juli d829db6
Update eip-1186.md
juli 5209166
Change assigned EIP number
a5782d6
Merge branch 'master' into master
juli 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 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,97 @@ | ||
--- | ||
eip: 1186 | ||
title: Add chain id to mixed-case checksum address encoding | ||
author: Juliano Rizzo (@juli) | ||
status: Draft | ||
type: Standards Track | ||
category: ERC | ||
created: 2018-03-18 | ||
requires: 55, 155 | ||
discussions-to: https://github.com/ethereum/EIPs/issues/1121 | ||
--- | ||
## Simple Summary | ||
This EIP extends EIP-55 by optionally adding a chain id defined by EIP-155 to the checksum calculation. | ||
|
||
## Specification | ||
Convert the address using the same algorithm defined by EIP-55 but if a registered chain id is provided, add it to the input of the hash function. If the chain id passed to the function belongs to a network that opted for using this checksum variant, prefix the address with the chain id and the `0x` separator before calculating the hash. Then convert the address to hexadecimal, but if the ith digit is a letter (ie. it's one of `abcdef`) print it in uppercase if the 4*ith bit of the calculated hash is 1 otherwise print it in lowercase. | ||
|
||
## Rationale | ||
Benefits: | ||
- By means of a minimal code change on existing libraries, users are protected from losing funds by mixing addresses of different Ethereum based networks. | ||
## Backwards Compatibility | ||
This proposal is fully backward compatible. The checksum calculation is changed only for new networks that choose to adopt this EIP and add their chain numbers to the Adoption Table included in this document. | ||
|
||
## Implementation | ||
```python | ||
#!/usr/bin/python3 | ||
from sha3 import keccak_256 | ||
import random | ||
""" | ||
addr (str): Hexadecimal address, 40 characters long with 2 characters prefix | ||
chainid (int): chain id from EIP-155 """ | ||
def eth_checksum_encode(addr, chainid=1): | ||
adopted_eipxxx = [30, 31] | ||
hash_input = str(chainid) + addr.lower() if chainid in adopted_eipxxx else addr[2:].lower() | ||
hash_output = keccak_256(hash_input.encode('utf8')).hexdigest() | ||
aggregate = zip(addr[2:].lower(),hash_output) | ||
out = addr[:2] + ''.join([c.upper() if int(a,16) >= 8 else c for c,a in aggregate]) | ||
return out | ||
``` | ||
## Test Cases | ||
```python | ||
eth_mainnet= [ | ||
'0x88021160C5C792225E4E5452585947470010289D', | ||
'0x27b1fdb04752bbc536007a920d24acb045561c26', | ||
'0x52908400098527886E0F7030069857D2E4169EE7', | ||
'0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed', | ||
'0x8617E340B3D01FA5F11F306F4090FD50E238070D', | ||
'0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', | ||
'0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB', | ||
'0xde709f2102306220921060314715629080e2fb77', | ||
'0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359', | ||
] | ||
rsk_mainnet = [ | ||
'0x6549F4939460DE12611948B3F82B88C3C8975323', | ||
'0x27b1FdB04752BBc536007A920D24ACB045561c26', | ||
'0x3599689E6292B81B2D85451025146515070129Bb', | ||
'0x52908400098527886E0F7030069857D2E4169ee7', | ||
'0x5aaEB6053f3e94c9b9a09f33669435E7ef1bEAeD', | ||
'0x8617E340b3D01Fa5f11f306f4090fd50E238070D', | ||
'0xD1220A0Cf47c7B9BE7a2e6ba89F429762E7B9adB', | ||
'0xDBF03B407c01E7CD3cBea99509D93F8Dddc8C6FB', | ||
'0xDe709F2102306220921060314715629080e2FB77', | ||
'0xFb6916095cA1Df60bb79ce92cE3EA74c37c5d359', | ||
] | ||
rsk_testnet= [ | ||
'0x42712D45473476B98452F434E72461577D686318', | ||
'0x27B1FdB04752BbC536007a920D24acB045561C26', | ||
'0x3599689e6292b81b2D85451025146515070129Bb', | ||
'0x52908400098527886E0F7030069857D2e4169EE7', | ||
'0x5aAeb6053F3e94c9b9A09F33669435E7EF1BEaEd', | ||
'0x66f9664F97F2b50f62d13eA064982F936DE76657', | ||
'0x8617e340b3D01fa5F11f306F4090Fd50e238070d', | ||
'0xDE709F2102306220921060314715629080e2Fb77', | ||
'0xFb6916095CA1dF60bb79CE92ce3Ea74C37c5D359', | ||
'0xd1220a0CF47c7B9Be7A2E6Ba89f429762E7b9adB', | ||
'0xdbF03B407C01E7cd3cbEa99509D93f8dDDc8C6fB', | ||
] | ||
test_cases = {30 : rsk_mainnet, 31 : rsk_testnet, 1 : eth_mainnet} | ||
|
||
for chainid, cases in test_cases.items(): | ||
for addr in cases: | ||
assert ( addr == eth_checksum_encode(addr,chainid) ) | ||
``` | ||
## Adoption | ||
### Adoption Table | ||
| Network | Chain id | Supports this EIP | | ||
|--------------|----------|-------------------| | ||
| RSK Mainnet | 30 | Yes | | ||
| RSK Testnet | 31 | Yes | | ||
|
||
|
||
| Wallet | Implements this EIP| | ||
|--------------|--------------------| | ||
| MyCrypto | In progress | | ||
| Ledger | In progress | | ||
| Trezor | In progress | | ||
|
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.
Why is this numbered 1186?
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.
Tell me what number to use. 1191?
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.
Yes, 1191 is fine.