EIPs/EIPS/eip-1191.md
lightclient 3194278525
Switch validator to eipv (#2860)
* switch to eipv

* fix

* fix

* 1153 remove trailing whitespace

* remove file name checks

* 615 remo whitespace before comma

* 884 remove extra single-quotes

* 1337 remove whitespace before comma

* 1057 remove extra spaces after comma

* 2470 update created date to Y/M/D format

* 1078 update required eips to be in ascending order

* 2477 update required eips to be in ascending order

* 1271 remove extra whitespace

* 2767 required eipupdated to be in ascending order

* 2525 update created date to Y/M/D format

* 2458 remove trailing whitespace

* 1884 remove trailing whitespace

* 712 authors should be on a single line

* 601 remove extra whitespace

* 1485 remove unneeded parentheses

* 634 remove trailing whitespace

* 2657 update discussions-to to correct spelling

* 2009 remove trailing whitespace

* 998 required eips updated to be in ascending order

* 1186 remove trailing whitespace

* 1470 remove extra whitespace

* 1895 update created date to Y/M/D format

* 2747 remove extra whitespace

* 1613 remove leading whitespace

* 1571 can'have both handle and email in author field

* 1191 remove trailing whitespace

* 1973 remove trailing whitespace

* 196 don't wrap title field

* 1679 required eips must be in ascending order

* 1620 author can't have both handle and email

* 197 don't line wrap title field

* 2378 remove extra newline

* 1355 author can't have both handle and email

* 698 update created date to Y/M/D format

* 2193 required eips must be in ascending order

* 214 remove extra info after author email

* use v0.0.3 of eipv

* 1 remove malformed field

* bump eipv to v0.0.4

* cache eipv build

* 1485 remove extra author info

* 2771 removing extra whitespaces
2020-08-10 11:18:25 -05:00

6.3 KiB

eip title author status review-period-end type category created requires discussions-to
1191 Add chain id to mixed-case checksum address encoding Juliano Rizzo (@juli) Last Call 2019-11-18 Standards Track ERC 2018-03-18 55, 155 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.

Abstract

The EIP-55 was created to prevent users from losing funds by sending them to invalid addresses. This EIP extends EIP-55 to protect users from losing funds by sending them to addresses that are valid but that where obtained from a client of another network.For example, if this EIP is implemented, a wallet can alert the user that is trying to send funds to an Ethereum Testnet address from an Ethereum Mainnet wallet.

Motivation

The motivation of this proposal is to provide a mechanism to allow software to distinguish addresses from different Ethereum based networks. This proposal is necessary because Ethereum addresses are hashes of public keys and do not include any metadata. By extending the EIP-55 checksum algorithm it is possible to achieve this objective.

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

#!/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

eth_mainnet = [
"0x27b1fdb04752bbc536007a920d24acb045561c26",
"0x3599689E6292b81B2d85451025146515070129Bb",
"0x42712D45473476b98452f434e72461577D686318",
"0x52908400098527886E0F7030069857D2E4169EE7",
"0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed",
"0x6549f4939460DE12611948b3f82b88C3C8975323",
"0x66f9664f97F2b50F62D13eA064982f936dE76657",
"0x8617E340B3D01FA5F11F306F4090FD50E238070D",
"0x88021160C5C792225E4E5452585947470010289D",
"0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb",
"0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB",
"0xde709f2102306220921060314715629080e2fb77",
"0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359",
]
rsk_mainnet = [
"0x27b1FdB04752BBc536007A920D24ACB045561c26",
"0x3599689E6292B81B2D85451025146515070129Bb",
"0x42712D45473476B98452f434E72461577d686318",
"0x52908400098527886E0F7030069857D2E4169ee7",
"0x5aaEB6053f3e94c9b9a09f33669435E7ef1bEAeD",
"0x6549F4939460DE12611948B3F82B88C3C8975323",
"0x66F9664f97f2B50F62d13EA064982F936de76657",
"0x8617E340b3D01Fa5f11f306f4090fd50E238070D",
"0x88021160c5C792225E4E5452585947470010289d",
"0xD1220A0Cf47c7B9BE7a2e6ba89F429762E7B9adB",
"0xDBF03B407c01E7CD3cBea99509D93F8Dddc8C6FB",
"0xDe709F2102306220921060314715629080e2FB77",
"0xFb6916095cA1Df60bb79ce92cE3EA74c37c5d359",
]
rsk_testnet = [
"0x27B1FdB04752BbC536007a920D24acB045561C26",
"0x3599689e6292b81b2D85451025146515070129Bb",
"0x42712D45473476B98452F434E72461577D686318",
"0x52908400098527886E0F7030069857D2e4169EE7",
"0x5aAeb6053F3e94c9b9A09F33669435E7EF1BEaEd",
"0x6549f4939460dE12611948b3f82b88C3c8975323",
"0x66f9664F97F2b50f62d13eA064982F936DE76657",
"0x8617e340b3D01fa5F11f306F4090Fd50e238070d",
"0x88021160c5C792225E4E5452585947470010289d",
"0xd1220a0CF47c7B9Be7A2E6Ba89f429762E7b9adB",
"0xdbF03B407C01E7cd3cbEa99509D93f8dDDc8C6fB",
"0xDE709F2102306220921060314715629080e2Fb77",
"0xFb6916095CA1dF60bb79CE92ce3Ea74C37c5D359",
]
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

Implementation Table

Project Adopted this EIP Implementation
MyCrypto Yes JavaScript
MyEtherWallet Yes JavaScript
Ledger Yes C
Trezor Yes Python and C
Web3.js Yes JavaScript
EthereumJS-util Yes JavaScript
ENS address-encoder Yes TypeScript

Copyright and related rights waived via CC0.