forked from ethereum/EIPs
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EIP-1191: extends EIP-55 by optionally adding a chain id defined by E…
…IP-155 to the checksum calculation (ethereum#1191) * EIP Add chain id to mixed-case checksum address encoding * Fixes header * Update eip-1186.md * Change assigned EIP number
- Loading branch information
Showing
1 changed file
with
97 additions
and
0 deletions.
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: 1191 | ||
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_eip1191 = [30, 31] | ||
hash_input = str(chainid) + addr.lower() if chainid in adopted_eip1191 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 | | ||
|