之前,我们展示了一种使用 零知识密钥声明证明 购买比特币虚荣地址的新颖且私密的方式。在实践中,它有一个缺点:买方在步骤 7 中验证了证明后,他可以中止交换协议,卖方浪费资源寻找答案却没有得到报酬。

为了克服这个缺点,我们使用智能合约完全在链上进行交换。只有提供了私钥(例如派生/组合公钥/地址)满足虚荣地址模式,它才会支付。完整代码如下所示。
import "ec.scrypt";
// outsource a vanity address generation
contract VanityAddr {
// buyer's public key
PubKey pubKey;
// vanity address pattern such as vanity prefix "nChain"
bytes pattern;
// x is the secret seller finds
// all other parameters are auxiliaries of it
public function offerVanityAddr(PrivKey x, PubKey X, PubKey derivedPubKey, int lambda, SigHashPreimage txPreimage) {
// verify = X = x * G?
require(Tx.checkPreimageAdvanced(txPreimage, x, X, Tx.invK, Tx.r, Tx.rBigEndian, SigHashType(SigHash.ALL | SigHash.FORKID)));
// verify P' = P + X
require(EC.isPubKeySum(this.pubKey, X, lambda, derivedPubKey));
// meet requirement
require(matchPattern(derivedPubKey, this.pattern));
}
// check if public key's address matches the given pattern
static function matchPattern(PubKey pubKey, bytes pattern) : bool {
// convert public key to address
bytes addr = ripemd160(sha256(pubKey));
// prefix match
int l = len(pattern);
return addr[:l] == pattern;
}
}
为了有效地计算点加法(第 16 行)和乘法(第 13 行),我们利用了与以前相同的技术。
在我们获得组合的公钥后,我们在第 19 行验证其对应的地址是否符合预定义的虚荣模式。
延展
我们只展示了如何验证派生地址是否具有特定前缀。但是可以直接扩展它以使地址或公钥满足任何任意要求。
本文介绍了一种利用智能合约改进的比特币虚荣地址交换方法,旨在解决卖家资源浪费和买家信任问题。通过在以太坊等区块链平台上部署智能合约,只有当卖家找到满足特定虚荣地址模式的私钥时,交易才会执行并支付给卖家,从而确保了交易的安全性和不可逆转性。

被折叠的 条评论
为什么被折叠?



