ERC 1850 - Hashed Time-Locked Principal Contract Standard#1850
Closed
matthewjablack wants to merge 9 commits intoethereum:masterfrom
Closed
ERC 1850 - Hashed Time-Locked Principal Contract Standard#1850matthewjablack wants to merge 9 commits intoethereum:masterfrom
matthewjablack wants to merge 9 commits intoethereum:masterfrom
Conversation
nicksavers
approved these changes
Mar 22, 2019
|
There has been no activity on this pull request 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 pull request 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
eip: 1850
title: Hashed Time-Locked Principal Contract transactions
author: Matthew Black [email protected], Tony Cai [email protected], Atomic Loans team [email protected]
status: Draft
discussions-to: #1851
type: Standards Track
category: ERC
created: 2019-03-19
Simple Summary
This EIP describes a script for a generalized debt agreement contract based on Hashed Time-Lock Contract (ERC 1630) transactions according to the Atomic Loans specification (https://arxiv.org/pdf/1901.05117.pdf).
Abstract
A Hashed Time-Locked Principal Contract (HTLPC) is a script that permits a designated party (the "lender") to provide ERC20 denominated funds for a debt agreement for a specified amount of time, with collateral locked on another blockchain (denoted as the collateral blockchain for the purposes of this EIP). It also permits a second party (the "borrower") to withdraw the lent funds once their request to borrow has been approved by the lender, repay the loan after the loan period has passed and in the case of default, liquidate the collateral.
Motivation
HTLPC transactions are a safe method for exchanging multiple secrets for the purposes of executing a cross-chain debt agreement, due to the ability to recover a percentage of funds from an uncooperative counterparty.
HLTPC's enable cross-chain atomic loans
Definitions
msg.sender: is always the address where the current function call came fromborrower: entity that locks collateral on another blockchain and receives loan amount fromlenderfollowing the approval of theborrower’sborrow requestlender: entity that contributes funds to the HTLPC, to be borrowed by theborrowerupon the locking of collateral on the collateral chain and thelender’sapprovalbidder: entity that bids on the collateral to enable liquidation of the collateralrepay: when theborrowerpays back theprincipal+interestbeforeloanExpirationdefault: when theborrowerfails to pay back theprincipal+interestbefore theloanExpirationsecret: random number chosen by theborrowerorlender, revealed to allow the parties to change the state of the debt agreementsecretHash: hash of thesecret, used in the construction of HTLPCnow: current block timestampprincipal: the amount borrowed within the loan, upon which interest is calculatedinterest: a percentage amount of the loan principal paid by theborrowerto thelender, in addition to the repayment of principalapproved:boolstate where if true, the request to borrow, as well as the collateral from theborrowerhas been accepted by thelenderbidding:boolstate where if true, third partybiddersare able to bid on the collateral in order to liquidate itcurrentBid: highest bid on the collateral so farliquidatedCollateralWidthdrawn:boolstate where theborrowerandlenderhave withdrawn their share of the liquidated collateralSecretA1: secret generated by theborrower, used to prove that theborrowerhas withdrawn the loanSecretA2: secret generated by theborrower, used to allow thebidderto withdraw the liquidated collateral fundsSecretB1: secret generated by thelender, used to accept the locking of collateral byborrower, enablingborrowerto withdraw the loan amountSecretB2: secret generated by thelender, used to refund themselves in the event they aren't satisfied withborrower’slocking of collateral. Also used to acceptborrower’srepayment of principal plus interestSecretB3: secret generated by thelender, used to allow thebidderto withdraw the liquidated collateral fundsSecretC: secret generated by thebidder, used to accept the signatures of theborrowerandlenderfor authorizing the liquidation of collateralApproveExpiration: timestamp after which thelendercan no longerapprovethe loan by accepting requests to borrow from theborrowerLoanExpiration: timestamp before which theborrowermust repay the loan; or otherwise risk the liquidation or seizure of their collateralAcceptExpiration: timestamp before which thelendermust accept the repayment of the loanBiddingExpiration: timestamp that determines the amount of time allocated to bidding before seizure period occursApprove Period:
During this time, the
lenderdeploys the HTLPC. Following this, the borrower locks their collateral on the collateral blockchain in a Hashed Time-Locked Collateral Contract (HTLCC) (Bitcoin version specified here: https://github.com/bitcoin/bips/blob/master/bip-0197.mediawiki). Thelenderthen either revealssecretB1to signify that they are satisfied with the collateral, and the borrower can withdraw the loan by revealingsecretA1. If thelenderis not satisfied with the collateral locked by theborrower, thelendercan refunds their loan amount by revealingsecretB2, which will subsequently allow the borrower to refund the collateral amount they deposited.Loan Period:
Once the
borrowerhas withdrawn the loan amount, the Loan Period begins. Once the Loan Period is finished, theborroweris expected to repay the loan. If they do, thelendercan then accept the repayment by revealingsecretB2, enabling the borrower to refund their collateral amount. In the case that theborrowerdefaults or does not repay the full principal plus interest amount, thelendercan choose to not accept the loan repayment, and the parties can opt for liquidation of the collateral in the Bidding Period.Bidding Period:
In the case of a default or the
lendernot accepting theborrowerrepayment, thelenderandborrowercan opt for liquidation of the collateral through the process of third party bidders bidding on the collateral. The Bidding Period can be initiated by either thelenderor theborrower. Once the bidding timeout occurs, thelenderandborrowermust each provide a signature, followed bysecretCrevealed by the winningbidderonce they have checked that the signature is proper. Finally, thelenderandborrowermust each revealsecretA2andsecretB3to allow the collateral to be withdrawn by the winningbidder.Seizure Period:
In the case that either the
lenderorborrowerdon’t accept the bid, thelendercan seize a percentage of the collateral. The amount is dependent on the amount of collateral locked in the Seizable Collateral script and Refundable Collateral script as described in the BIP (https://github.com/bitcoin/bips/blob/master/bip-0197.mediawiki). During this period theborrowercan also refund the funds locked in the Refundable Collateral script.Refund Period:
In the case of a default where the
lenderdoes not seize the collateral locked in the Seizable Collateral script, then the borrower can refund the funds locked in the Seizable Collateral script described in the BIP (https://github.com/bitcoin/bips/blob/master/bip-0197.mediawiki).Specification
Constructor
The
msg.sendertransfers funds to the smart contract during its deployment.Methods
fund
The
msg.senderorlendertransfers tokens for the loan amount to the contractSHOULD throw if
fundedis trueapprove
The
msg.senderorlenderapproves the locking of collateral done by the Borrower on the collateral blockchain.SHOULD throw if
msg.senderdoes not equallenderaddressSHOULD throw if hash of
_secretB1does not equalsecretHashB1SHOULD throw if
nowis greater thanapproveExpirationNote
secretcan be any bytesize, but that should be specified by the two parties before the HTLC is initiated. The recommended size is 32 bytes.withdraw
The
msg.senderorborrowerwithdraws the loan amountSHOULD throw if hash of
_secretA1does not equalsecretHashA1SHOULD throw if hash of
_secretB1does not equalsecretHashB1SHOULD throw if
approveddoes not equal trueacceptOrCancel
The
msg.senderorlenderaccepts theborrowerrepayment of theprincipalplusinterestSHOULD throw if hash of
_secretB2does not equalsecretHashB2SHOULD throw if
nowis less than or equal towithdrawExpirationSHOULD throw if
nowis greater thanacceptExpirationSHOULD throw if
biddingis truepayback
The
msg.senderorborrowerrepays the loan amountSHOULD throw if
msg.valuedoes not equalprincipalplusinterestNote that in this version, it is expected that the borrower make just one repayment, which covers the entirety of
principalplusinterestrefundPayback
The
msg.senderorborrowerrefunds the repayment amount they put forth in the event their repayment is not accepted by thelenderSHOULD throw if
nowless than or equal toacceptExpirationSHOULD throw if
repaidis falseSHOULD throw if
msg.senderis not the borrowerstartBidding
The
msg.sender(either thelenderorborrower) initiates the bidding processSHOULD throw if
repaidis trueSHOULD throw if
withdrawnis falseSHOULD throw if
nowis less than or equal toloanExpirationSHOULD throw if
msg.senderis neither aborroweraddress nor alenderaddressbid
The
msg.sender(anyone who is interested in bidding on the collateral) bids on the collateralSHOULD throw if
biddingis nottrueSHOULD throw if
nowis less than or equal toloanExpirationSHOULD throw if
nowis greater than biddingTimeoutExpirationSHOULD throw if
_bidValueis less than or equal tocurrentBidSHOULD throw if token balance of
msg.senderis less than_bidValueprovideSignature
The
msg.senderprovides asignaturefor the collateral blockchain enabling thebidderto spend thecollateralin the liquidation processSHOULD throw if
nowis less than or equal toloanExpirationprovideSecret
The
msg.senderprovides asecretto enable thebidderto spend thecollateralin the liquidation processSHOULD throw if
nowis less than or equal toloanExpirationif
msg.senderis theborrower, then SHOULD throw if the hash of_secretdoes not equalsecretHashA2if
msg.senderis thelender, then SHOULD throw if the hash of_secretdoes not equalsecretHashB3if
msg.senderis neither thelenderorborrower, it SHOULD throwwithdrawLiquidatedCollateral
The
msg.sender(eitherborrowerorlender) withdraws the liquidated collateralSHOULD throw if
nowis less than or equal tobiddingTimeoutExpirationif
msg.senderis the borrower, then SHOULD throw ifborrowerLiquidatedCollateralWithdrawnis trueif
msg.senderis the lender, then SHOULD throw iflenderLiquidatedCollateralWithdrawis trueif
msg.senderis neither the lender or borrower, it SHOULD throwrefundBid
The
msg.senderorbidderrefunds their bid in the case that theborrowerandlenderdo not opt into liquidating the collateralSHOULD throw if
repaidis trueSHOULD throw if
nowless than or equal tobiddingRefundExpirationSHOULD throw if the hash of
secretCequalssecretHashCand the hash ofsecretA2equalssecretHashA2and the hash ofsecretB2equalssecretHashB2SHOULD throw if
borrowerLiquidatedCollateralWithdrawnis trueSHOULD throw if
lenderLiquidatedCollateralWithdrawnis trueSHOULD throw if
currentBidis less than or equal to 0Compatibility
ERC 1850 is compatible with BIP 197 for atomicloans with Bitcoin and other HTLC compatible chains.
Implementation
This implementation is a simple example of a HTLPC using Solidity
https://github.com/AtomicLoans/ethereum-contracts/blob/master/contracts/AtomicLoan.sol
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 HTLPC is initialized.References
Papers
Standards
Discussions
Copyright
Copyright and related rights waived via CC0.