1

I know that bitcoin supports Zero knowledge contingent payment (ZKCP) , can etherum support such ZKCP Payment ?

3

I'm just learning that term, but I'm pretty sure the answer is "yes." From https://bitcoincore.org/en/2016/02/26/zero-knowledge-contingent-payments-announcement/:

So the buyer initially wanted to buy an input for his program, but now he would be just as happy to buy the preimage of a hash. As it turns out, Bitcoin already provides a way to sell hash preimages in a secure manner.

It's easy to make an Ethereum smart contract that pays a certain account if and only if it's provided with the preimage of some hash. Completely untested:

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);
    }
}
  • Could you please explain the line seller.transfer(address(this).balance); ? what is the balance word refere to ? – Mohamed Feb 18 at 0:59
  • It's the balance of (amount of ether owned by) the given address. In this case, the contract. – user19510 Feb 18 at 1:51
  • @smarks: but in this way, the function transfer will transfer all the amount of ether that owned by the given address. I think the balance value should be predefined? – Mohamed Feb 18 at 2:06
  • Yes, it will transfer the contract's entire balance. If you don't want that, you can put in some different amount. – user19510 Feb 18 at 2:08
  • I read that the after the buyer construct that smart contract with the deposit value, he can unlock this deposit and it can not be used anymore when calling provideimage function . How can that misbehaving prevented? – Mohamed Feb 19 at 3:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.