Skip to content
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

[FreshEyes] test: Validate UTXO snapshot with coin height > base height & amount > MAX_MONEY supply #2

Open
wants to merge 1 commit into
base: bitcoin-fresheyes-staging-master-29617
Choose a base branch
from

Conversation

jrakibi
Copy link
Owner

@jrakibi jrakibi commented May 8, 2024

The author jrakibi wrote the following PR called test: Validate UTXO snapshot with coin height > base height & amount > MAX_MONEY supply, issue number 29617 in bitcoin/bitcoin cloned by FreshEyes below:

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:

  • Added test_invalid_snapshot_wrong_coin_code to feature_assumeutxo.py.
  • The test artificially sets a coin's height above 299 in a snapshot and checks for load failure.
  • Edit: Added a test case for outputs whose amounts surpass the MAX_MONEY supply limit.

This implementation addresses the request for enhancing assumeutxo testing as outlined in issue #28648


Edit: 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:

  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)

… 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
Copy link

An author commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#issuecomment-1987539987 at 2024/03/11, 03:00:54 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#issuecomment-1987598631 at 2024/03/11, 04:05:48 UTC.

Copy link

This is an OUTDATED review comment as the original pull request may have been rebased or force-pushed

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#discussion_r1519887039 at 2024/03/11, 15:10:17 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author reviewed and commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#pullrequestreview-1928106989 at 2024/03/11, 15:16:17 UTC.

Copy link

This is an OUTDATED review comment as the original pull request may have been rebased or force-pushed

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#discussion_r1519956212 at 2024/03/11, 15:50:14 UTC.

Copy link

This is an OUTDATED review comment as the original pull request may have been rebased or force-pushed

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#discussion_r1519962442 at 2024/03/11, 15:54:21 UTC.

Copy link

This is an OUTDATED review comment as the original pull request may have been rebased or force-pushed

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#discussion_r1519965353 at 2024/03/11, 15:55:45 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author reviewed and commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#pullrequestreview-1928222108 at 2024/03/11, 15:58:28 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#issuecomment-1988794302 at 2024/03/11, 16:02:17 UTC.

Copy link

This is an OUTDATED review comment as the original pull request may have been rebased or force-pushed

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#discussion_r1520352558 at 2024/03/11, 19:54:12 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author reviewed and commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#pullrequestreview-1929052753 at 2024/03/11, 19:54:12 UTC.

Copy link

This is an OUTDATED review comment as the original pull request may have been rebased or force-pushed

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#discussion_r1520359252 at 2024/03/11, 20:00:01 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author reviewed and commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#pullrequestreview-1929073517 at 2024/03/11, 20:00:01 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#issuecomment-1992758783 at 2024/03/13, 00:01:40 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#issuecomment-1992870694 at 2024/03/13, 00:47:12 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#issuecomment-2005493786 at 2024/03/19, 00:41:17 UTC.

Copy link

This is an OUTDATED review comment as the original pull request may have been rebased or force-pushed

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#discussion_r1565319719 at 2024/04/15, 07:46:36 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author reviewed and approved here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#pullrequestreview-2000245020 at 2024/04/15, 07:48:30 UTC.

Copy link

This is an OUTDATED review comment as the original pull request may have been rebased or force-pushed

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#discussion_r1565360894 at 2024/04/15, 08:19:00 UTC.

Copy link

This is an OUTDATED review comment as the original pull request may have been rebased or force-pushed

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#discussion_r1565361998 at 2024/04/15, 08:19:53 UTC.

Copy link

This is an OUTDATED review comment as the original pull request may have been rebased or force-pushed

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#discussion_r1565369875 at 2024/04/15, 08:25:42 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author reviewed and commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#pullrequestreview-2000312610 at 2024/04/15, 08:33:10 UTC.

Copy link

This is an OUTDATED review comment as the original pull request may have been rebased or force-pushed

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#discussion_r1574776450 at 2024/04/22, 13:39:16 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author reviewed and commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#pullrequestreview-2014792959 at 2024/04/22, 13:39:16 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#issuecomment-2069508021 at 2024/04/22, 13:48:22 UTC.

Copy link

This is an OUTDATED review comment as the original pull request may have been rebased or force-pushed

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#discussion_r1574985012 at 2024/04/22, 15:45:39 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author reviewed and commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#pullrequestreview-2015164071 at 2024/04/22, 16:53:01 UTC.

Copy link

This is an OUTDATED review comment as the original pull request may have been rebased or force-pushed

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#discussion_r1575459383 at 2024/04/22, 23:28:19 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author reviewed and commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#pullrequestreview-2015956968 at 2024/04/22, 23:28:19 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#issuecomment-2071123104 at 2024/04/22, 23:35:37 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#issuecomment-2071624163 at 2024/04/23, 07:33:45 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/29617#issuecomment-2091513768 at 2024/05/02, 20:38:55 UTC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant