Solidity

乙太坊零知識或有支付?

  • January 12, 2022

我知道比特幣支持零知識或有支付(ZKCP),乙太坊能支持這種ZKCP支付嗎?

我只是在學習這個術語,但我很確定答案是“是的”。來自https://bitcoincore.org/en/2016/02/26/zero-knowledge-contingent-payments-announcement/

所以買家最初想為他的程序購買輸入,但現在他會很樂意購買雜湊的原像。事實證明,比特幣已經提供了一種以安全方式出售雜湊原像的方法。

當且僅當它提供了一些雜湊的原像時,很容易製作一個支付某個帳戶的乙太坊智能合約。完全未經測試:

pragma solidity 0.5.2;

contract BuyPreimage {
   address payable buyer;
   address payable seller;
   bytes32 public hash;
   uint256 public deadline;

   constructor(address payable _seller, bytes32 _hash, uint256 timeout) public payable {
       buyer = msg.sender;
       seller = _seller;

       hash = _hash;
       deadline = now + timeout;
   }

   // If this is called with the correct preimage, the seller gets paid.
   function providePreimage(bytes calldata preimage) external {
       require(keccak256(preimage) == hash);
       seller.transfer(address(this).balance);
   }

   // Issue a refund back to the buyer if the timeout has expired.
   function refund() external {
       require(msg.sender == buyer);
       require(now >= deadline);

       msg.sender.transfer(address(this).balance);
   }
}

引用自:https://ethereum.stackexchange.com/questions/65884