-
Notifications
You must be signed in to change notification settings - Fork 38.7k
test: Validate UTXO snapshot with coin height > base height & amount > MAX_MONEY supply #29617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the Possibly this is due to a silent merge conflict (the changes in this pull request being Leave a comment here, if you need help tracking down a confusing failure. |
BrandonOdiwuor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- You should remove the TODO:
bitcoin/test/functional/feature_assumeutxo.py
Lines 19 to 20 in a945f09
- TODO: Valid hash but invalid snapshot file (bad coin height or bad other serialization)
ismaelsadeeq
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass Partial review.
- Please squash the two commits https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits
- From the PR OP and description you mention base height, I am not familiar with the term "base height" did you mean chain tip?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "Testing snapshot file with an incorrect coin code: height 364 and coinbase 0" | |
| "Testing snapshot file with an incorrect coin height 364 and coinbase 0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ismaelsadeeq, I've squashed them.
Base height is related to AssumeUTXO snapshot, refers to the block height at which the UTXOset snapshot was taken.
Also coin code in this context encodes the block height and whether the tx is Coinbase or not
|
Missing |
46f16a3 to
4104d9f
Compare
885be24 to
0ca552c
Compare
|
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the Possibly this is due to a silent merge conflict (the changes in this pull request being Leave a comment here, if you need help tracking down a confusing failure. |
21825ad to
28ab34d
Compare
|
@ismaelsadeeq @BrandonOdiwuor I've updated the PR with your feedbacks. Also included my test case in |
28ab34d to
a94cfca
Compare
a94cfca to
1349ea9
Compare
|
I've just added another test case to invalidate snapshots containing outputs whose amounts exceed the MAX_MONEY supply limit |
1349ea9 to
e807838
Compare
rkrux
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK e807838
I was able to successfully build and run all the functional tests.
Provided a refactoring suggestion in favour of clear separation of variables.
fjahr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
I think it would be helpful for reviewers if you could add information in the commit message how you arrived at the content values b"\x84\x58" and b"\xCA\xD2\x8F\x5A".
f614e0e to
6428b36
Compare
|
@fjahr I've updated the code based on your feedback. In the commit & PR description, you can find the steps followed to arrive at the content values, along with a tool to decode a UTXO snapshot |
fjahr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 6428b363e68fee51a455ebd4f9bf7ed6d813caa8
Ignore the nit unless there is other feedback to address or you need to rebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: exceeds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed and rebased.
8766cbb to
ef27f36
Compare
… money_supply You can use this tool to decode the utxo snapshot https://github.com/jrakibi/utxo-live Here’s an overview of how it’s done: The serialization forma for a UTXO in the snapshot is as follows: 1. Transaction ID (txid) - 32 bytes 2. Output Index (outnum)- 4 bytes 3. VARINT (code) - A varible-length integer encoding the height and whether the transaction is a coinbase. The format of this VARINT is (height << 1) | coinbase_flag. 4. VARINT (amount_v) - A variable-length integer that represents a compressed format of the output amount (in satoshis). For the test cases mentioned: * b"\x84\x58" - This value corresponds to a VARINT representing the height and coinbase flag. Once we decode this code, we can extract the height and coinbase using height = code_decoded >> 1 and coinbase = code_decoded & 0x01. In our case, with code_decoded = 728, it results in height = 364 and coinbase = 0. * b"\xCA\xD2\x8F\x5A" - This byte sequence represents a compressed amount value. The decompression function takes this value and translates it into a full amount in satoshis. In our case, the decompression of this amount translates to a number larger than the maximum allowed value of coins (21 million BTC) test:Validate UTXO snapshot with coin_height > base_height & amount > money_supply test:Validate UTXO snapshot with coin_height > base_height & amount > money_supply
ef27f36 to
ec1f1ab
Compare
|
re-ACK ec1f1ab |
|
ACK ec1f1ab 👑 Show signatureSignature: |
|
ACK ec1f1ab |
Summary: This is a partial backport of [[bitcoin/bitcoin#27596 | core#27596]], [[bitcoin/bitcoin#28652 | core#28652]], [[bitcoin/bitcoin#29345 | core#29345]], [[bitcoin/bitcoin#28589 | core#28589]], [[bitcoin/bitcoin#28590 | core#28590]], [[bitcoin/bitcoin#28625 | core#28625]], [[bitcoin/bitcoin#28639 | core#28639]], [[bitcoin/bitcoin#28647 | core#28647]], [[bitcoin/bitcoin#28562 | core#28562]], [[bitcoin/bitcoin#28666 | core#28666]], [[bitcoin/bitcoin#28669 | core#28669]], [[bitcoin/bitcoin#28685 | core#28685]], [[bitcoin/bitcoin#29215 | core#29215]], [[bitcoin/bitcoin#29726 | core#29726]], [[bitcoin/bitcoin#29354 | core#29354]], [[bitcoin/bitcoin#29394 | core#29394]], [[bitcoin/bitcoin#29478 | core#29478]], [[bitcoin/bitcoin#29370 | core#29370]], [[bitcoin/bitcoin#29617 | core#29617]], [[bitcoin/bitcoin#28685 | core#28685]], [[bitcoin/bitcoin#30053 | core#30053]], [[bitcoin/bitcoin#29973 | core#29973]], [[bitcoin/bitcoin#28838 | core#28838]], [[bitcoin/bitcoin#29354 | core#29354]], [[bitcoin/bitcoin#29478 | core#29478]], [[bitcoin/bitcoin#30678 | core#30678]], [[bitcoin/bitcoin#31556 | core#31556]] and [[bitcoin/bitcoin#30909 | core#30909]] Depends on D17945 ------ rpc: add loadtxoutset Co-authored-by: Sebastian Falbesoner <[email protected]> bitcoin/bitcoin@ce585a9 [[bitcoin/bitcoin#28652 | core#28652]] [[bitcoin/bitcoin#29345 | core#29345]] ------ rpc: add getchainstates Co-authored-by: Ryan Ofsky <[email protected]> bitcoin/bitcoin@0f64bac bitcoin/bitcoin@a9ef702 ---- test: add feature_assumeutxo functional test Initial commit: bitcoin/bitcoin@42cae39 [[bitcoin/bitcoin#28589 | core#28589]] (race fixes) [[bitcoin/bitcoin#28590 | core#28590]] (getchainstates return a list of chainstates) [[bitcoin/bitcoin#28625 | core#28625]] ( check that loading snapshot not matching AssumeUTXO parameters fails) bitcoin/bitcoin@fafde92 [[bitcoin/bitcoin#28647 | core#28647]] (Add assumeutxo test for wrong hash) [[bitcoin/bitcoin#28652 | core#28652]] (fail early if snapshot block hash doesn't match AssumeUTXO parameters) [[bitcoin/bitcoin#28562 | core#28562]] (`self.no_op`, `self.wait_until`) [[bitcoin/bitcoin#28666 | core#28666]] (assumeutxo file with unknown block hash) [[bitcoin/bitcoin#28669 | core#28669]] (check au file with changed outpoint index) [[bitcoin/bitcoin#28685 | core#28685]] (add tests for coin maleation) [[bitcoin/bitcoin#29215 | core#29215]] (spend coin from snapshot chainstate after loading) bitcoin/bitcoin@b7ba60f (add coverage for -reindex and assumeutxo) [[bitcoin/bitcoin#29354 | core#29354]] (Assumeutxo with more than just coinbase transactions) [[bitcoin/bitcoin#29394 | core#29394]] (Add test to ensure failure when mempool not empty) bitcoin/bitcoin@2bc1ecf (Remove unnecessary sync_blocks in assumeutxo tests) [[bitcoin/bitcoin#29478 | core#29478]] (Add test for loadtxoutset when headers are not synced) [[bitcoin/bitcoin#29370 | core#29370]] (RPC test for fake nTx and nChainTX values, stale block CheckBlockIndex crash test & assumeutxo snapshot block CheckBlockIndex crash test) [[bitcoin/bitcoin#29617 | core#29617]] (test for coin_height > base_height & amount > money_supply) bitcoin/bitcoin@f621392 (Check deserialized coins for out of range values) [[bitcoin/bitcoin#30053 | core#30053]] (coverage for "Couldn't open file..." error) [[bitcoin/bitcoin#29973 | core#29973]] (ensure failure when importing a snapshot twice) ------ test: add assumeutxo wallet test initial commit: [[bitcoin/bitcoin#28838 | core#28838]] bitcoin/bitcoin@fa5cd66 (Assumeutxo with more than just coinbase transactions) bitcoin/bitcoin@2bc1ecf (Remove unnecessary sync_blocks in assumeutxo tests) bitcoin/bitcoin@7e3dbe4 (functional test only) bitcoin/bitcoin@f20fe33 (Add basic balance coverage) bitcoin/bitcoin@bc43eca (test for balance after snapshot completion) bitcoin/bitcoin@595edee (import descriptors during background sync) Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D17931
Ensure snapshot loading fails for coins exceeding base height
Objective: This test verifies that snapshot loading is correctly rejected for coins with a height greater than the base height.
Update:
test_invalid_snapshot_wrong_coin_codetofeature_assumeutxo.py.This implementation addresses the request for enhancing
assumeutxotesting as outlined in issue #28648Edit: This is an explanation on how I arrive at content values: b"\x84\x58" and b"\xCA\xD2\x8F\x5A"
You can use this tool to decode the utxo snapshot https://github.com/jrakibi/utxo-live
Here’s an overview of how it’s done:
The serialization format for a UTXO in the snapshot is as follows:
For the test cases mentioned:
b"\x84\x58"- This value corresponds to a VARINT representing the height and coinbase flag. Once we decode this code, we can extract the height and coinbase usingheight = code_decoded >> 1andcoinbase = code_decoded & 0x01. In our case, with code_decoded = 728, it results inheight = 364andcoinbase = 0.b"\xCA\xD2\x8F\x5A"- This byte sequence represents a compressed amount value. The decompression function takes this value and translates it into a full amount in satoshis. In our case, the decompression of this amount translates to a number larger than the maximum allowed value of coins (21 million BTC)