Skip to content

Conversation

@stevenroose
Copy link
Contributor

@stevenroose stevenroose commented May 7, 2019

Fixes #612 and #613.

  • prevents a double claim from entering mempool
  • makes claimpegin throw an exception when trying to double claim a pegin
  • check the last commit message on all the extra cases that are tested.

@stevenroose stevenroose requested a review from instagibbs May 7, 2019 19:11

// ELEMENTS:
// Don't look for coins that only exist in parent chain
// For pegin inputs check whether the pegins have already been claimed before.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to note this is just a coin UTXO check, not a mempool check at all. At the mempool level we rely on the GetConflictTx check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some explanation.

@instagibbs
Copy link
Contributor

Can you also explain the regression from 0.14 in the OP for people reading code history?

@stevenroose
Copy link
Contributor Author

stevenroose commented May 8, 2019

Can you also explain the regression from 0.14 in the OP for people reading code history?

Please verify the commit message of the new commit.

@stevenroose stevenroose changed the title Prevent pegin double spends from entering the mempool Improve double pegin claim behavior May 8, 2019
This bug got introduced with the 0.17 rebase. In 0.14.1 the double pegin
claim check was done in the beginning of the validation logic, where the
coins view was the actual UTXO set. In 0.17, Core moved several checks
because the intermediate method CheckInputs was removed and some logic
moved to tx_verify.cpp, where we also put the pegin check.  In the
mempool acceptance check, however (as opposed to the ConnectBlock
check), CheckTxInputs is called with only a partial UTXO view for
optimization reasons. This commit adds an extra pegin check in the
beginning of the mempool code where we have a full UTXO view.
Currently it will commit to the transaction without it being able to
enter the mempool. This makes the block creation code include the tx
into the block and create an invalid block.
@stevenroose
Copy link
Contributor Author

I think I also addressed all comments on the other PR about using raises_rpc_exception and the case-by-case explanation.

- changes the expected behavior of claimpegin to fail on double spend
- adds extra test to make sure a block with a double spend is also not
  accepted:
  1. a tx with two identical pegin inputs (mempool & block)
  2. a tx claiming a pegin that another mempool tx also claims
  3. a tx claiming a pegin that a confirmed tx already claimed (mempool
     & block)
// To check if it's not double spending an existing pegin UTXO, we check mempool acceptance.
CValidationState acceptState;
bool accepted = ::AcceptToMemoryPool(mempool, acceptState, MakeTransactionRef(mtx), nullptr /* pfMissingInputs */,
nullptr /* plTxnReplaced */, false /* bypass_limits */, maxTxFee, true /* test_accept */);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, cute!

@instagibbs
Copy link
Contributor

ACK!

@instagibbs instagibbs merged commit 52ef283 into ElementsProject:master May 8, 2019
instagibbs added a commit that referenced this pull request May 8, 2019
52ef283 Improve the fedpeg test with extra double claim tests (Steven Roose)
48a82fa Make claimpegin fail in the case of a double claim (Steven Roose)
af22646 Prevent pegin double spends from entering the mempool (Steven Roose)
50c5570 Report IsValidPeginWitness error message (Steven Roose)

Pull request description:

  Fixes #612 and #613.

  - prevents a double claim from entering mempool
  - makes `claimpegin` throw an exception when trying to double claim a pegin
  - check the last commit message on all the extra cases that are tested.

Tree-SHA512: dd9602cd4bc78a3e8f7a6b566f881ede09dba54900425348c1eb528268a3e869416e3c9ca97c1a8da4d120875ef59c4e21a857256312ce77e06b7b6ae04abf92
@stevenroose stevenroose deleted the fix-double-pegin branch February 2, 2020 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transaction that double-spends a pegin should not be accepted in mempool

2 participants