EIP55-以太坊账户地址校验算法

本文共251字。
Copyright: 知识共享署名 非商业性使用 相同方式共享 4.0 国际许可协议 | CC BY-NC-SA 4.0

以太坊账户地址是一个40个字符的Hex字符串,使用过程中发现地址中的字母包含了大写字母和小写字母,但实际交易时,使用大小写字母均可以正常完成操作。

例如:0x9Ca0e998dF92c5351cEcbBb6Dba82Ac2266f7e0C

查了一下资料,发现在地址中使用大小写是一种校验方式。这种方式最早由V神于2016年1月于GitHub提出,链接:https://github.com/ethereum/eips/issues/55

目前已形成EIP55标准:https://github.com/ethereum/ercs/blob/master/ERCS/erc-55.md

这种校验算法满足下面条件:

  • 向下兼容
  • 保持账户地址的长度和信息都不发生变化
  • 足够低的碰撞概率

上面提到的proposal提出了一种算法来解决这个问题,该算法原文描述如下:

In English, convert the address to hex, 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 hash of the lowercase hexadecimal address is 1 otherwise print it in lowercase.