Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit dcb1148

Browse files
authored
Merge pull request #438 from keep-network/remove-funder-bond
Remove funder bond We removed revokeFunderBond, returnFunderBond and getFunderBondAmount functions as we won't require funder to put up a bond. The funder will need to send a fee for opening a new keep which will be forwarded to the keep factory.
2 parents 01eb296 + dc557ce commit dcb1148

File tree

5 files changed

+14
-94
lines changed

5 files changed

+14
-94
lines changed

implementation/contracts/deposit/DepositFunding.sol

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,6 @@ library DepositFunding {
7474
return true;
7575
}
7676

77-
/// @notice Transfers the funders bond to the signers if the funder never funds
78-
/// @dev Called only by notifyFundingTimeout
79-
function revokeFunderBond(DepositUtils.Deposit storage _d) internal {
80-
if (address(this).balance >= TBTCConstants.getFunderBondAmount()) {
81-
_d.pushFundsToKeepGroup(TBTCConstants.getFunderBondAmount());
82-
} else if (address(this).balance > 0) {
83-
_d.pushFundsToKeepGroup(address(this).balance);
84-
}
85-
}
86-
87-
/// @notice Returns the funder's bond plus a payment at contract teardown
88-
/// @dev Returns the balance if insufficient. Always call this before distributing signer payments
89-
function returnFunderBond(DepositUtils.Deposit storage _d) internal {
90-
if (address(this).balance >= TBTCConstants.getFunderBondAmount()) {
91-
_d.depositOwner().transfer(TBTCConstants.getFunderBondAmount());
92-
} else if (address(this).balance > 0) {
93-
_d.depositOwner().transfer(address(this).balance);
94-
}
95-
}
96-
9777
/// @notice slashes the signers partially for committing fraud before funding occurs
9878
/// @dev called only by notifyFraudFundingTimeout
9979
function partiallySlashForFraudInFunding(DepositUtils.Deposit storage _d) internal {
@@ -122,7 +102,6 @@ library DepositFunding {
122102
_d.setFailedSetup();
123103
_d.logSetupFailed();
124104

125-
returnFunderBond(_d);
126105
fundingTeardown(_d);
127106
}
128107

@@ -159,7 +138,6 @@ library DepositFunding {
159138
_d.setFailedSetup();
160139
_d.logSetupFailed();
161140

162-
revokeFunderBond(_d);
163141
fundingTeardown(_d);
164142
}
165143

@@ -197,7 +175,6 @@ library DepositFunding {
197175
/* NB: This is reuse of the variable */
198176
_d.fundingProofTimerStart = block.timestamp;
199177
_d.setFraudAwaitingBTCFundingProof();
200-
returnFunderBond(_d);
201178
}
202179
}
203180

@@ -297,13 +274,6 @@ library DepositFunding {
297274

298275
require(_d.inAwaitingBTCFundingProof(), "Not awaiting funding");
299276

300-
// Design decision:
301-
// We COULD revoke the funder bond here if the funding proof timeout has elapsed
302-
// HOWEVER, that would only create a situation where the funder loses eerything
303-
// It would be a large punishment for a small crime (being slightly late)
304-
// So if the funder manages to call this before anyone notifies of timeout
305-
// We let them have a freebie
306-
307277
bytes8 _valueBytes;
308278
bytes memory _utxoOutpoint;
309279

@@ -327,8 +297,6 @@ library DepositFunding {
327297
_d.setActive();
328298
_d.logFunded();
329299

330-
returnFunderBond(_d);
331-
332300
return true;
333301
}
334302
}

implementation/contracts/deposit/TBTCConstants.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ library TBTCConstants {
2222
uint256 public constant FUNDING_PROOF_TIMEOUT = 3 * 60 * 60; // seconds
2323
uint256 public constant FORMATION_TIMEOUT = 3 * 60 * 60; // seconds
2424
uint256 public constant FRAUD_FUNDING_PROOF_TIMEOUT = 3 * 60 * 60; // seconds
25-
uint256 public constant FUNDER_BOND_AMOUNT_WEI = 10 ** 5; // wei
2625

2726
// Liquidation Flow
2827
uint256 public constant COURTESY_CALL_DURATION = 6 * 60 * 60; // seconds
@@ -45,7 +44,6 @@ library TBTCConstants {
4544
function getFundingTimeout() public pure returns (uint256) { return FUNDING_PROOF_TIMEOUT; }
4645
function getSigningGroupFormationTimeout() public pure returns (uint256) { return FORMATION_TIMEOUT; }
4746
function getFraudFundingTimeout() public pure returns (uint256) { return FRAUD_FUNDING_PROOF_TIMEOUT; }
48-
function getFunderBondAmount() public pure returns (uint256) { return FUNDER_BOND_AMOUNT_WEI; }
4947

5048
function getCourtesyCallTimeout() public pure returns (uint256) { return COURTESY_CALL_DURATION; }
5149
function getAuctionDuration() public pure returns (uint256) { return AUCTION_DURATION; }

implementation/test/DepositFraudTest.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import expectThrow from './helpers/expectThrow'
22
import deployTestDeposit from './helpers/deployTestDeposit'
3+
import {
4+
createSnapshot,
5+
restoreSnapshot,
6+
} from './helpers/snapshot'
37

48
import BN from 'bn.js'
59
import utils from './utils'
@@ -33,7 +37,6 @@ const _signerPubkeyX = '0xd4aee75e57179f7cd18adcbaa7e2fca4ff7b1b446df88bf0b4398e
3337
const _signerPubkeyY = '0xe8bfb23428a4efecb3ebdc636139de9a568ed427fff20d28baa33ed48e9c44e1'
3438
const _merkleProof = '0x886f7da48f4ccfe49283c678dedb376c89853ba46d9a297fe39e8dd557d1f8deb0fb1a28c03f71b267f3a33459b2566975b1653a1238947ed05edca17ef64181b1f09d858a6e25bae4b0e245993d4ea77facba8ed0371bb9b8a6724475bcdc9edf9ead30b61cf6714758b7c93d1b725f86c2a66a07dd291ef566eaa5a59516823d57fd50557f1d938cc2fb61fe0e1acee6f9cb618a9210688a2965c52feabee66d660a5e7f158e363dc464fca2bb1cc856173366d5d20b5cd513a3aab8ebc5be2bd196b783b8773af2472abcea3e32e97938283f7b454769aa1c064c311c3342a755029ee338664999bd8d432080eafae3ca86b52ad2e321e9e634a46c1bd0d174e38bcd4c59a0f0a78c5906c015ef4daf6beb0500a59f4cae00cd46069ce60db2182e74561028e4462f59f639c89b8e254602d6ad9c212b7c2af5db9275e48c467539c6af678d6f09214182df848bd79a06df706f7c3fddfdd95e6f27326c6217ee446543a443f82b711f48c173a769ae8d1e92a986bc76fca732f088bbe049'
3539

36-
3740
contract('DepositFraud', (accounts) => {
3841
let tbtcConstants
3942
let mockRelay
@@ -138,24 +141,6 @@ contract('DepositFraud', (accounts) => {
138141
'Signature is not fraudulent'
139142
)
140143
})
141-
142-
it('returns the funder bond if the timer has not elapsed', async () => {
143-
const funderBondAmount = new BN('10').pow(new BN('5'))
144-
const blockNumber = await web3.eth.getBlock('latest').number
145-
await testDeposit.send(funderBondAmount, { from: beneficiary })
146-
const initialBalance = await web3.eth.getBalance(beneficiary)
147-
148-
await ecdsaKeepStub.setBondAmount(funderBondAmount)
149-
await testDeposit.setFundingProofTimerStart(fundingProofTimerStart * 6)
150-
await testDeposit.provideFundingECDSAFraudProof(0, utils.bytes32zero, utils.bytes32zero, utils.bytes32zero, '0x00')
151-
152-
const finalBalance = await web3.eth.getBalance(beneficiary)
153-
const eventList = await tbtcSystemStub.getPastEvents('FraudDuringSetup', { fromBlock: blockNumber, toBlock: 'latest' })
154-
const balanceCheck = new BN(initialBalance).add(funderBondAmount)
155-
156-
assert.equal(eventList.length, 1)
157-
expect(finalBalance, 'funder should be included in final result').to.eq.BN(balanceCheck)
158-
})
159144
})
160145

161146
describe('notifyFraudFundingTimeout', async () => {
@@ -300,11 +285,19 @@ contract('DepositFraud', (accounts) => {
300285
})
301286
})
302287

303-
304288
describe('provideECDSAFraudProof', async () => {
305-
beforeEach(async () => {
289+
before(async () => {
306290
await testDeposit.setState(utils.states.ACTIVE)
307291
await ecdsaKeepStub.send(1000000, { from: accounts[0] })
292+
await ecdsaKeepStub.setSuccess(true)
293+
})
294+
295+
beforeEach(async () => {
296+
await createSnapshot()
297+
})
298+
299+
afterEach(async () => {
300+
await restoreSnapshot()
308301
})
309302

310303
it('executes', async () => {

implementation/test/DepositFundingTest.js

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -213,21 +213,6 @@ contract('DepositFunding', (accounts) => {
213213
'Signing group formation timeout not yet elapsed'
214214
)
215215
})
216-
217-
it('returns funder bond', async () => {
218-
await testDeposit.send(funderBondAmount, { from: beneficiary })
219-
220-
const initialBalance = await web3.eth.getBalance(beneficiary)
221-
222-
await testDeposit.setSigningGroupRequestedAt(fundingProofTimerStart)
223-
await ecdsaKeepStub.setBondAmount(funderBondAmount)
224-
225-
await testDeposit.notifySignerSetupFailure()
226-
227-
const balance = await web3.eth.getBalance(beneficiary)
228-
const balanceCheck = new BN(initialBalance).add(funderBondAmount)
229-
expect(balance, 'bond not returned to funder').to.eq.BN(balanceCheck)
230-
})
231216
})
232217

233218
describe('retrieveSignerPubkey', async () => {
@@ -333,15 +318,6 @@ contract('DepositFunding', (accounts) => {
333318
'Funding timeout has not elapsed'
334319
)
335320
})
336-
337-
it('distributes the funder bond to the keep group', async () => {
338-
await testDeposit.setFundingProofTimerStart(fundingProofTimerStart)
339-
await testDeposit.send(funderBondAmount, { from: beneficiary })
340-
await testDeposit.notifyFundingTimeout()
341-
342-
const keepBalance = await web3.eth.getBalance(ecdsaKeepStub.address)
343-
assert.equal(keepBalance, new BN(funderBondAmount), 'funder bond not distributed properly')
344-
})
345321
})
346322

347323
describe('provideBTCFundingProof', async () => {
@@ -393,18 +369,5 @@ contract('DepositFunding', (accounts) => {
393369
'Not awaiting funding'
394370
)
395371
})
396-
397-
it('returns funder bonds', async () => {
398-
await testDeposit.send(funderBondAmount, { from: beneficiary })
399-
400-
const initialBalance = await web3.eth.getBalance(beneficiary)
401-
402-
await testDeposit.provideBTCFundingProof(_version, _txInputVector, _txOutputVector, _txLocktime, _fundingOutputIndex, _merkleProof, _txIndexInBlock, _bitcoinHeaders)
403-
404-
const actualBalance = await web3.eth.getBalance(beneficiary)
405-
const expectedBalance = new BN(initialBalance).add(funderBondAmount)
406-
407-
assert.equal(actualBalance, expectedBalance, 'funder bond not correctly returned')
408-
})
409372
})
410373
})

implementation/test/contracts/deposit/TestTBTCConstants.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ library TestTBTCConstants {
2222
uint256 public constant FUNDING_PROOF_TIMEOUT = 3 * 60 * 60; // seconds
2323
uint256 public constant FORMATION_TIMEOUT = 3 * 60 * 60; // seconds
2424
uint256 public constant FRAUD_FUNDING_PROOF_TIMEOUT = 3 * 60 * 60; // seconds
25-
uint256 public constant FUNDER_BOND_AMOUNT_WEI = 10 ** 5; // wei
2625

2726
// Liquidation Flow
2827
uint256 public constant COURTESY_CALL_DURATION = 6 * 60 * 60; // seconds
@@ -44,7 +43,6 @@ library TestTBTCConstants {
4443
function getFundingTimeout() public pure returns (uint256) { return FUNDING_PROOF_TIMEOUT; }
4544
function getSigningGroupFormationTimeout() public pure returns (uint256) { return FORMATION_TIMEOUT; }
4645
function getFraudFundingTimeout() public pure returns (uint256) { return FRAUD_FUNDING_PROOF_TIMEOUT; }
47-
function getFunderBondAmount() public pure returns (uint256) { return FUNDER_BOND_AMOUNT_WEI; }
4846

4947
function getCourtesyCallTimeout() public pure returns (uint256) { return COURTESY_CALL_DURATION; }
5048
function getAuctionDuration() public pure returns (uint256) { return AUCTION_DURATION; }

0 commit comments

Comments
 (0)