-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
test: Validate UTXO snapshot with coin height > base height & amount > MAX_MONEY supply #29617
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. |
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)
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?
@@ -148,6 +148,42 @@ def test_invalid_mempool_state(self, dump_output_path): | |||
|
|||
self.restart_node(2, extra_args=self.extra_args[2]) | |||
|
|||
def test_invalid_snapshot_wrong_coin_code(self, valid_snapshot_path): | |||
self.log.info( | |||
"Testing snapshot file with an incorrect coin code: 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.
"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
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.
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 |
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 6428b36
Ignore the nit unless there is other feedback to address or you need to rebase.
[b"\x81", 36, "3da966ba9826fb6d2604260e01607b55ba44e1a5de298606b08704bc62570ea8", None], # wrong coin code VARINT | ||
[b"\x80", 36, "091e893b3ccb4334378709578025356c8bcb0a623f37c7c4e493133c988648e5", None], # another wrong coin code | ||
[b"\x84\x58", 36, None, "[snapshot] bad snapshot data after deserializing 0 coins"], # wrong coin case with height 364 and coinbase 0 | ||
[b"\xCA\xD2\x8F\x5A", 41, None, "[snapshot] bad snapshot data after deserializing 0 coins - bad tx out value"], # Amount exceed MAX_MONEY |
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 |
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_code
tofeature_assumeutxo.py
.This implementation addresses the request for enhancing
assumeutxo
testing 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 >> 1
andcoinbase = code_decoded & 0x01
. In our case, with code_decoded = 728, it results inheight = 364
andcoinbase = 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)