-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ERC 1630 Discussion #1631
Comments
I have a suggestion for the optimised version of the contract. Replace the Reasoning: In the case of the solidity implementation, a failed call to
|
Great suggestion @monokh. Added the necessary changes to Also fixed an implementation typo, where |
We made another amendment to the bytecode contract that fixes the expiration size and as a result also the size of the contract in total. This makes it less error prone and easier to parse. |
There has been no activity on this issue for two months. It will be closed in a week if no further activity occurs. If you would like to move this EIP forward, please respond to any outstanding feedback or add a comment indicating that you have addressed all required feedback and are ready for a review. |
Updated bytecode contract with fixed expiration size |
There has been no activity on this issue for two months. It will be closed in a week if no further activity occurs. If you would like to move this EIP forward, please respond to any outstanding feedback or add a comment indicating that you have addressed all required feedback and are ready for a review. |
This issue was closed due to inactivity. If you are still pursuing it, feel free to reopen it and respond to any feedback or request a review in a comment. |
eip: 1630
title: Hashed Time-Locked Contracts
author: Matthew Black [email protected], TingWei Liu [email protected], Liquality Team [email protected]
status: Draft
discussions-to: #1631
type: Standards Track
category: ERC
created: 2018-11-28
Simple Summary
A standard EVM script for generalized payments that acknowledges receiving the payment prior to a deadline.
Abstract
A Hashed Time-Lock Contract (HTLC) is a script that permits a designated party (the "seller") to spend funds by disclosing the preimage of a hash. It also permits a second party (the "buyer") to spend the funds after a timeout is reached, in a refund situation.
Motivation
HTLC transactions are a safe and cheap method of exchanging secrets for money over the blockchain, due to the ability to recover funds from an uncooperative counterparty, and the opportunity that the possessor of a secret has to receive the funds before such a refund can occur.
HTLC's enable cross-chain atomic swaps
Definitions
msg.sender
: is always the address where the current (external) function call came from.buyer
: entity that receives funds fromseller
once theseller
reveals thesecret
seller
: entity that contributes funds to thebuyer
by revealing thesecret
or refunds afterexpiration
secret
: random number chosen by theseller
, revealed to allow thebuyer
to redeem the fundssecretHash
: hash of thesecret
, used in the construction of HTLCexpiration
: timestamp the determines whenseller
andbuyer
can redeemnow
: current block timestampSpecification
Constructor
The
msg.sender
, transfers funds to the smart contract while deployingMethods
claim
The
msg.sender
, transfer funds from the contract to thebuyer
SHOULD throw if hash of
secret
SHOULD throw if
now
is greater thanexpiration
Note
secret
can be any bytesize, but that should be specified by the two parties before the HTLC is initiated. The recommended size is 32 bytesrefund
The
msg.sender
, transfer funds from the contract to theseller
SHOULD throw if
now
less than or equal toexpiration
Backwards Compatibility
ERC-1630 is compatible with BIP 199 for atomic swaps with Bitcoin and other HTLC compatible chains.
Implementation
This implementation is a simple example of a HTLC using Solidity
Note other hash functions can also be used, such as
keccak256
,ripemd160
. However both parties should specify the hash function to be used before the HTLC is initialized.Also if the HTLC is being used for the purpose of atomic swaps, both parties should ensure that the hash function specified is available on both chains (i.e.
keccak256
is not available on Bitcoin)Optimized Implementation
This is an optimized HTLC with significant gas saving features
Liquality Atomic Swaps
Optimized Implementation Definitions
dataSize
112
+ expiration size112
is the size of the contract in bytes after the constructorsecretHash
hash of secret generated by seller
redeemDestination
66 + expiration size
66 is the number of bytes between Contract and Redeem self destruct
refundDestination
89 + expiration size
89 is the number of bytes between Contract and Refund self destruct
expirationSize
bytecode length of expiration
expiration
expiration time encoded hex
recipientAddress
buyer address
refundAddress
seller address
Optimized Implementation Rationale
Constructor
deploys the contract, using the datasize which is the bytecode size of the rest of the contract
Contract
compute (Keccak-256) hash of contract address
Get secret
copy input data of secret in the current environment to memory
SHA 256
hashes the secret in memory
Validate with SecretHash
checks if secretHash is equal to hash of secret provided
Redeem if secret is valid
jump to the redeem self destruct section of the contract
Check timelock
check block's timestamp is greater than expiration
Refund if timelock passed
jump to the refund self destruct section of the contract
Redeem self destruct
pushes buyer address to the stack, which is passed to SELFDESTRUCT which sends funds to the buyer, and destroys the contract
Refund self destruct
pushes seller address to the stack, which is passed to SELFDESTRUCT which sends funds to the seller, and destroys the contractal
Copyright
Copyright and related rights waived via CC0.
The text was updated successfully, but these errors were encountered: