You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
eip: 1850
title: Hashed Time-Locked Principal Contract transactions
author: Matthew Black matthew@atomicloans.io, Tony Cai tony@atomicloans.io, Atomic Loans team info@atomicloans.io
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 from
borrower: entity that locks collateral on another blockchain and receives loan amount from lender following the approval of the borrower’s borrow request
lender: entity that contributes funds to the HTLPC, to be borrowed by the borrower upon the locking of collateral on the collateral chain and the lender’s approval
bidder: entity that bids on the collateral to enable liquidation of the collateral
repay: when the borrower pays back the principal + interest before loanExpiration
default: when the borrower fails to pay back the principal + interest before the loanExpiration
secret: random number chosen by the borrower or lender, revealed to allow the parties to change the state of the debt agreement
secretHash: hash of the secret, used in the construction of HTLPC
now: current block timestamp
principal: the amount borrowed within the loan, upon which interest is calculated
interest: a percentage amount of the loan principal paid by the borrower to the lender, in addition to the repayment of principal
approved: bool state where if true, the request to borrow, as well as the collateral from the borrower has been accepted by the lender
bidding: bool state where if true, third party bidders are able to bid on the collateral in order to liquidate it
currentBid: highest bid on the collateral so far
liquidatedCollateralWidthdrawn: bool state where the borrower and lender have withdrawn their share of the liquidated collateral
SecretA1: secret generated by the borrower, used to prove that the borrower has withdrawn the loan
SecretA2: secret generated by the borrower, used to allow the bidder to withdraw the liquidated collateral funds
SecretB1: secret generated by the lender, used to accept the locking of collateral by borrower, enabling borrower to withdraw the loan amount
SecretB2: secret generated by the lender, used to refund themselves in the event they aren't satisfied with borrower’slocking of collateral. Also used to accept borrower’s repayment of principal plus interest
SecretB3: secret generated by the lender, used to allow the bidder to withdraw the liquidated collateral funds
SecretC: secret generated by the bidder, used to accept the signatures of the borrower and lender for authorizing the liquidation of collateral
ApproveExpiration: timestamp after which the lender can no longer approve the loan by accepting requests to borrow from the borrower
LoanExpiration: timestamp before which the borrower must repay the loan; or otherwise risk the liquidation or seizure of their collateral
AcceptExpiration: timestamp before which the lender must accept the repayment of the loan
BiddingExpiration: timestamp that determines the amount of time allocated to bidding before seizure period occurs
Approve Period:
During this time, the lender deploys 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). The lender then either reveals secretB1 to signify that they are satisfied with the collateral, and the borrower can withdraw the loan by revealing secretA1. If the lender is not satisfied with the collateral locked by the borrower, the lender can refunds their loan amount by revealing secretB2, which will subsequently allow the borrower to refund the collateral amount they deposited.
Loan Period:
Once the borrower has withdrawn the loan amount, the Loan Period begins. Once the Loan Period is finished, the borrower is expected to repay the loan. If they do, the lender can then accept the repayment by revealing secretB2, enabling the borrower to refund their collateral amount. In the case that the borrower defaults or does not repay the full principal plus interest amount, the lender can 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 lender not accepting the borrower repayment, the lender and borrower can 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 the lender or the borrower. Once the bidding timeout occurs, the lender and borrower must each provide a signature, followed by secretC revealed by the winning bidder once they have checked that the signature is proper. Finally, the lender and borrower must each reveal secretA2 and secretB3 to allow the collateral to be withdrawn by the winning bidder.
Seizure Period:
In the case that either the lender or borrower don’t accept the bid, the lender can 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 the borrower can also refund the funds locked in the Refundable Collateral script.
Refund Period:
In the case of a default where the lender does 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.sender transfers funds to the smart contract during its deployment.
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.
eip: 1850
title: Hashed Time-Locked Principal Contract transactions
author: Matthew Black matthew@atomicloans.io, Tony Cai tony@atomicloans.io, Atomic Loans team info@atomicloans.io
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.