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

Revise hashing to support Merkle proofs #1110

Merged
merged 24 commits into from
Feb 6, 2024
Merged

Revise hashing to support Merkle proofs #1110

merged 24 commits into from
Feb 6, 2024

Conversation

td202
Copy link
Contributor

@td202 td202 commented Dec 14, 2023

Purpose

This involves several changes to support hashing blocks to support Merkle proofs. Primarily, these involves updating how LFMBTree hashes are computed for the new P7 protocol version.

Changes

  • New hashing scheme for LFMBTrees, which includes the size of the tree at the root.
  • CapitalDistribution is hashed differently depending on BlockHashVersion, which determines the LFMBTree hashing scheme to use.
  • PoolRewards parametrised by BlockHashVersion. The next and current capital distribution hashes are dependent on the BlockHashVersion, as well as the hashing of the bakerPoolRewardDetails LFMBTree.
  • As the majority of Concordium.GlobalState.Basic.BlockState.PoolRewards was not used, the remaining useful definitions are lifted to Concordium.GlobalState.PoolRewards.
  • Introduce new AccountsHash, ModulesHash and InstancesHash types for the accounts, modules and instances tables, which are parametrised by the protocol version.
  • A lot of legacy code for the in-memory instances/instance table is removed. The tests on the instances table are revised to use the persistent version.
  • Accounts hashing revised to use the new LFMBTree hashing scheme in P7.
  • BlockRewardDetails is revised to parametrise by the BlockHashVersion.
  • TransactionOutcomes are moved from base into a new Concordium.Types.TransactionOutcomes.
  • PersistentTransactionOutcomes supports a new TransactionOutcomesVersion that uses the new LFMBTree hashing scheme. A TransactionOutcomesHashV that is parametrised by the TransactionOutcomesVersion is introduced for hashing the PersistentTransactionOutcomes. TransactionOutcomesHash is still used in places where the version parameter is inconvenient or unnecessary.
  • Module table hashing revised to use the new LFMBTree hashing scheme in P7.
  • Changes to the instances table:
    • Fix a bug in newContractInstanceIT when inserting in a table with vacancies.
    • Change the instances table to track the total number of leaves including vacancies, instead of just the non-vacant leaves. This is a non-breaking change since it has never yet been possible to delete an instance, and so these numbers have historically been the same. This change affects the behaviour of newContractInstance and deleteContractInstance.
    • Change the hashing scheme at P7 to incorporate the number of leaves in the root hash (as for the LFMBTree).
  • ConsensusV1 block types are now parametrised by the protocol version.
  • Partial implementation of MerkleProvable for BakedBlock, supporting deriving Merkle proofs about a range of block attributes.

Checklist

  • My code follows the style of this project.
  • The code compiles without warnings.
  • I have performed a self-review of the changes.
  • I have documented my code, in particular the intent of the
    hard-to-understand areas.
  • (If necessary) I have updated the CHANGELOG.

Copy link
Contributor

@limemloh limemloh left a comment

Choose a reason for hiding this comment

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

Only very minor comments

Copy link
Contributor

@MilkywayPirate MilkywayPirate left a comment

Choose a reason for hiding this comment

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

Looks good 👍

I think we should add some tests for the provable properties of the block.

Copy link
Contributor

@abizjak abizjak left a comment

Choose a reason for hiding this comment

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

I think this suffers from some of the same as the related PR in base.

Ideally this would be 2 pull requests, one changing the hashing scheme, and the other one doing the Merkle proof production.

@td202 td202 merged commit 0e2e59f into main Feb 6, 2024
3 checks passed
@td202 td202 deleted the merkle-proofs branch February 6, 2024 14:40
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.

4 participants