diff --git a/implementation/contracts/deposit/DepositFunding.sol b/implementation/contracts/deposit/DepositFunding.sol index b5bd24a4c..14ef941d8 100644 --- a/implementation/contracts/deposit/DepositFunding.sol +++ b/implementation/contracts/deposit/DepositFunding.sol @@ -74,26 +74,6 @@ library DepositFunding { return true; } - /// @notice Transfers the funders bond to the signers if the funder never funds - /// @dev Called only by notifyFundingTimeout - function revokeFunderBond(DepositUtils.Deposit storage _d) internal { - if (address(this).balance >= TBTCConstants.getFunderBondAmount()) { - _d.pushFundsToKeepGroup(TBTCConstants.getFunderBondAmount()); - } else if (address(this).balance > 0) { - _d.pushFundsToKeepGroup(address(this).balance); - } - } - - /// @notice Returns the funder's bond plus a payment at contract teardown - /// @dev Returns the balance if insufficient. Always call this before distributing signer payments - function returnFunderBond(DepositUtils.Deposit storage _d) internal { - if (address(this).balance >= TBTCConstants.getFunderBondAmount()) { - _d.depositOwner().transfer(TBTCConstants.getFunderBondAmount()); - } else if (address(this).balance > 0) { - _d.depositOwner().transfer(address(this).balance); - } - } - /// @notice slashes the signers partially for committing fraud before funding occurs /// @dev called only by notifyFraudFundingTimeout function partiallySlashForFraudInFunding(DepositUtils.Deposit storage _d) internal { @@ -122,7 +102,6 @@ library DepositFunding { _d.setFailedSetup(); _d.logSetupFailed(); - returnFunderBond(_d); fundingTeardown(_d); } @@ -159,7 +138,6 @@ library DepositFunding { _d.setFailedSetup(); _d.logSetupFailed(); - revokeFunderBond(_d); fundingTeardown(_d); } @@ -197,7 +175,6 @@ library DepositFunding { /* NB: This is reuse of the variable */ _d.fundingProofTimerStart = block.timestamp; _d.setFraudAwaitingBTCFundingProof(); - returnFunderBond(_d); } } @@ -297,13 +274,6 @@ library DepositFunding { require(_d.inAwaitingBTCFundingProof(), "Not awaiting funding"); - // Design decision: - // We COULD revoke the funder bond here if the funding proof timeout has elapsed - // HOWEVER, that would only create a situation where the funder loses eerything - // It would be a large punishment for a small crime (being slightly late) - // So if the funder manages to call this before anyone notifies of timeout - // We let them have a freebie - bytes8 _valueBytes; bytes memory _utxoOutpoint; @@ -327,8 +297,6 @@ library DepositFunding { _d.setActive(); _d.logFunded(); - returnFunderBond(_d); - return true; } } diff --git a/implementation/contracts/deposit/TBTCConstants.sol b/implementation/contracts/deposit/TBTCConstants.sol index 71b7f3490..69881382d 100644 --- a/implementation/contracts/deposit/TBTCConstants.sol +++ b/implementation/contracts/deposit/TBTCConstants.sol @@ -22,7 +22,6 @@ library TBTCConstants { uint256 public constant FUNDING_PROOF_TIMEOUT = 3 * 60 * 60; // seconds uint256 public constant FORMATION_TIMEOUT = 3 * 60 * 60; // seconds uint256 public constant FRAUD_FUNDING_PROOF_TIMEOUT = 3 * 60 * 60; // seconds - uint256 public constant FUNDER_BOND_AMOUNT_WEI = 10 ** 5; // wei // Liquidation Flow uint256 public constant COURTESY_CALL_DURATION = 6 * 60 * 60; // seconds @@ -45,7 +44,6 @@ library TBTCConstants { function getFundingTimeout() public pure returns (uint256) { return FUNDING_PROOF_TIMEOUT; } function getSigningGroupFormationTimeout() public pure returns (uint256) { return FORMATION_TIMEOUT; } function getFraudFundingTimeout() public pure returns (uint256) { return FRAUD_FUNDING_PROOF_TIMEOUT; } - function getFunderBondAmount() public pure returns (uint256) { return FUNDER_BOND_AMOUNT_WEI; } function getCourtesyCallTimeout() public pure returns (uint256) { return COURTESY_CALL_DURATION; } function getAuctionDuration() public pure returns (uint256) { return AUCTION_DURATION; } diff --git a/implementation/test/DepositFraudTest.js b/implementation/test/DepositFraudTest.js index 616c8be55..a2ad33e8b 100644 --- a/implementation/test/DepositFraudTest.js +++ b/implementation/test/DepositFraudTest.js @@ -1,5 +1,9 @@ import expectThrow from './helpers/expectThrow' import deployTestDeposit from './helpers/deployTestDeposit' +import { + createSnapshot, + restoreSnapshot, +} from './helpers/snapshot' import BN from 'bn.js' import utils from './utils' @@ -33,7 +37,6 @@ const _signerPubkeyX = '0xd4aee75e57179f7cd18adcbaa7e2fca4ff7b1b446df88bf0b4398e const _signerPubkeyY = '0xe8bfb23428a4efecb3ebdc636139de9a568ed427fff20d28baa33ed48e9c44e1' const _merkleProof = '0x886f7da48f4ccfe49283c678dedb376c89853ba46d9a297fe39e8dd557d1f8deb0fb1a28c03f71b267f3a33459b2566975b1653a1238947ed05edca17ef64181b1f09d858a6e25bae4b0e245993d4ea77facba8ed0371bb9b8a6724475bcdc9edf9ead30b61cf6714758b7c93d1b725f86c2a66a07dd291ef566eaa5a59516823d57fd50557f1d938cc2fb61fe0e1acee6f9cb618a9210688a2965c52feabee66d660a5e7f158e363dc464fca2bb1cc856173366d5d20b5cd513a3aab8ebc5be2bd196b783b8773af2472abcea3e32e97938283f7b454769aa1c064c311c3342a755029ee338664999bd8d432080eafae3ca86b52ad2e321e9e634a46c1bd0d174e38bcd4c59a0f0a78c5906c015ef4daf6beb0500a59f4cae00cd46069ce60db2182e74561028e4462f59f639c89b8e254602d6ad9c212b7c2af5db9275e48c467539c6af678d6f09214182df848bd79a06df706f7c3fddfdd95e6f27326c6217ee446543a443f82b711f48c173a769ae8d1e92a986bc76fca732f088bbe049' - contract('DepositFraud', (accounts) => { let tbtcConstants let mockRelay @@ -138,24 +141,6 @@ contract('DepositFraud', (accounts) => { 'Signature is not fraudulent' ) }) - - it('returns the funder bond if the timer has not elapsed', async () => { - const funderBondAmount = new BN('10').pow(new BN('5')) - const blockNumber = await web3.eth.getBlock('latest').number - await testDeposit.send(funderBondAmount, { from: beneficiary }) - const initialBalance = await web3.eth.getBalance(beneficiary) - - await ecdsaKeepStub.setBondAmount(funderBondAmount) - await testDeposit.setFundingProofTimerStart(fundingProofTimerStart * 6) - await testDeposit.provideFundingECDSAFraudProof(0, utils.bytes32zero, utils.bytes32zero, utils.bytes32zero, '0x00') - - const finalBalance = await web3.eth.getBalance(beneficiary) - const eventList = await tbtcSystemStub.getPastEvents('FraudDuringSetup', { fromBlock: blockNumber, toBlock: 'latest' }) - const balanceCheck = new BN(initialBalance).add(funderBondAmount) - - assert.equal(eventList.length, 1) - expect(finalBalance, 'funder should be included in final result').to.eq.BN(balanceCheck) - }) }) describe('notifyFraudFundingTimeout', async () => { @@ -300,11 +285,19 @@ contract('DepositFraud', (accounts) => { }) }) - describe('provideECDSAFraudProof', async () => { - beforeEach(async () => { + before(async () => { await testDeposit.setState(utils.states.ACTIVE) await ecdsaKeepStub.send(1000000, { from: accounts[0] }) + await ecdsaKeepStub.setSuccess(true) + }) + + beforeEach(async () => { + await createSnapshot() + }) + + afterEach(async () => { + await restoreSnapshot() }) it('executes', async () => { diff --git a/implementation/test/DepositFundingTest.js b/implementation/test/DepositFundingTest.js index 7f3d76122..e78a89fe0 100644 --- a/implementation/test/DepositFundingTest.js +++ b/implementation/test/DepositFundingTest.js @@ -213,21 +213,6 @@ contract('DepositFunding', (accounts) => { 'Signing group formation timeout not yet elapsed' ) }) - - it('returns funder bond', async () => { - await testDeposit.send(funderBondAmount, { from: beneficiary }) - - const initialBalance = await web3.eth.getBalance(beneficiary) - - await testDeposit.setSigningGroupRequestedAt(fundingProofTimerStart) - await ecdsaKeepStub.setBondAmount(funderBondAmount) - - await testDeposit.notifySignerSetupFailure() - - const balance = await web3.eth.getBalance(beneficiary) - const balanceCheck = new BN(initialBalance).add(funderBondAmount) - expect(balance, 'bond not returned to funder').to.eq.BN(balanceCheck) - }) }) describe('retrieveSignerPubkey', async () => { @@ -333,15 +318,6 @@ contract('DepositFunding', (accounts) => { 'Funding timeout has not elapsed' ) }) - - it('distributes the funder bond to the keep group', async () => { - await testDeposit.setFundingProofTimerStart(fundingProofTimerStart) - await testDeposit.send(funderBondAmount, { from: beneficiary }) - await testDeposit.notifyFundingTimeout() - - const keepBalance = await web3.eth.getBalance(ecdsaKeepStub.address) - assert.equal(keepBalance, new BN(funderBondAmount), 'funder bond not distributed properly') - }) }) describe('provideBTCFundingProof', async () => { @@ -393,18 +369,5 @@ contract('DepositFunding', (accounts) => { 'Not awaiting funding' ) }) - - it('returns funder bonds', async () => { - await testDeposit.send(funderBondAmount, { from: beneficiary }) - - const initialBalance = await web3.eth.getBalance(beneficiary) - - await testDeposit.provideBTCFundingProof(_version, _txInputVector, _txOutputVector, _txLocktime, _fundingOutputIndex, _merkleProof, _txIndexInBlock, _bitcoinHeaders) - - const actualBalance = await web3.eth.getBalance(beneficiary) - const expectedBalance = new BN(initialBalance).add(funderBondAmount) - - assert.equal(actualBalance, expectedBalance, 'funder bond not correctly returned') - }) }) }) diff --git a/implementation/test/contracts/deposit/TestTBTCConstants.sol b/implementation/test/contracts/deposit/TestTBTCConstants.sol index c6eb7ca89..10b8e82fd 100644 --- a/implementation/test/contracts/deposit/TestTBTCConstants.sol +++ b/implementation/test/contracts/deposit/TestTBTCConstants.sol @@ -22,7 +22,6 @@ library TestTBTCConstants { uint256 public constant FUNDING_PROOF_TIMEOUT = 3 * 60 * 60; // seconds uint256 public constant FORMATION_TIMEOUT = 3 * 60 * 60; // seconds uint256 public constant FRAUD_FUNDING_PROOF_TIMEOUT = 3 * 60 * 60; // seconds - uint256 public constant FUNDER_BOND_AMOUNT_WEI = 10 ** 5; // wei // Liquidation Flow uint256 public constant COURTESY_CALL_DURATION = 6 * 60 * 60; // seconds @@ -44,7 +43,6 @@ library TestTBTCConstants { function getFundingTimeout() public pure returns (uint256) { return FUNDING_PROOF_TIMEOUT; } function getSigningGroupFormationTimeout() public pure returns (uint256) { return FORMATION_TIMEOUT; } function getFraudFundingTimeout() public pure returns (uint256) { return FRAUD_FUNDING_PROOF_TIMEOUT; } - function getFunderBondAmount() public pure returns (uint256) { return FUNDER_BOND_AMOUNT_WEI; } function getCourtesyCallTimeout() public pure returns (uint256) { return COURTESY_CALL_DURATION; } function getAuctionDuration() public pure returns (uint256) { return AUCTION_DURATION; }