ATNIO / AIPs

ATN Improvement Proposals
4 stars 0 forks source link

ARC: Add a precompiled contract for recovering public key from data and signature #5

Open hackfisher opened 6 years ago

hackfisher commented 6 years ago

关于ETH能否验证BTC签名/BTC跟ETH地址能否互换的问题 https://ethereum.stackexchange.com/questions/11508/deriving-ethereum-address-from-bitcoin-address?rq=1 https://ethereum.stackexchange.com/questions/32401/verifying-bicoin-signed-message-in-ethereum-smart-contract 看了这两个帖子感觉可行性。原理上说ETH BTC用了同样的签名算法包括同样的椭圆曲线,不同的是hash和地址生成不一样。 要做的话,一个可能的思路是根据输入的bitcoin signature, 恢复出public key(这一步是否要重写ecrecover, ),再恢复出对应的bitcoin address,与发送签名的地址比较检查。

然后我看有人在这帖里最后一楼说他做了在eth contract里验证btc signature的事情: https://forum.ethereum.org/discussion/2166/signature-generation-and-verification-in-solidity

OK,Thanks, 看来有了Message,签名,和地址(Bitcoin/Ethereum)就能验证签名,只是目前缺少一些直接recover成公钥,及公钥转地址(Bitcoin/Ethereum)的函数或库,需要开发一下。 这个特性可以用来开发一些有趣的功能。

ecrecover 是以太坊系统内置的一个合约,返回值是ETH地址,所以以太坊合约目前还无法恢复出公钥,ATN应该支持一个新的内置合约,用来根据数据和签名恢复公钥,进而可以验证Bitcoin/Qtum签名。

扩展研究:

比特币和以太坊签名格式的区别,似乎有不同,如何相互转化?. 以太坊里面直接恢复成公钥(而非以太坊地址)的函数/库? 以太坊公钥转化成Bitcoin/Qtum地址或者以太坊地址的规范说明以及代码?

Quote from Ethereum yellow paper.

As can be seen, there are four exceptions to the usage of the general execution framework Ξ for evaluation of the message call: these are four so-called ‘precompiled’ contracts, meant as a preliminary piece of architecture that may later become native extensions. The four contracts in addresses 1, 2, 3 and 4 execute the elliptic curve public key recovery function, the SHA2 256-bit hash scheme, the RIPEMD 160-bit hash scheme and the identity function respectively