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

[TODOs] refactor: proof path calculation #659

Merged
merged 6 commits into from
Jul 15, 2024

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Jul 4, 2024

Summary

  • Promotes GetProofPath() static function out of the proof keeper pkg into pkg/crypto/protocol. This should streamline the relayminer's dependency tree.
  • Refactors proof path calculation to hash the seed block hash together with the session ID using the same hasher type as the SMT used to generate the proof.

Issue

Type of change

Select one or more:

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Documentation
  • Other (specify)

Testing

Documentation changes (only if making doc changes)

  • make docusaurus_start; only needed if you make doc changes

Local Testing (only if making code changes)

  • Unit Tests: make go_develop_and_test
  • LocalNet E2E Tests: make test_e2e
  • See quickstart guide for instructions

PR Testing (only if making code changes)

  • DevNet E2E Tests: Add the devnet-test-e2e label to the PR.
    • THIS IS VERY EXPENSIVE, so only do it after all the reviews are complete.
    • Optionally run make trigger_ci if you want to re-trigger tests without any code changes
    • If tests fail, try re-running failed tests only using the GitHub UI as shown here

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have commented my code
  • I have performed a self-review of my own code; both comments & source code
  • I create and reference any new tickets, if applicable
  • I have left TODOs throughout the codebase, if applicable

Summary by CodeRabbit

  • New Features

    • Introduced proof verification functionality using Sparse Merkle Tree (SMT).
    • Added method to compute paths for proof validation with hashing.
  • Refactor

    • Updated proof-related functions to use the new protocol package.
    • Reorganized proof submission logic for a more structured approach.
  • Tests

    • Adjusted integration tests to accommodate new proof path parameters.

These changes enhance the cryptographic proof verification process, improving security and reliability.

@bryanchriswhite bryanchriswhite added protocol General core protocol related changes off-chain Off-chain business logic on-chain On-chain business logic labels Jul 4, 2024
@bryanchriswhite bryanchriswhite self-assigned this Jul 4, 2024
Copy link

coderabbitai bot commented Jul 4, 2024

Walkthrough

The changes introduce a new proof_path.go file for managing Sparse Merkle Tree (SMT) proof verification within the protocol package. Functions and variables related to proof verification are centralized in protocol, improving consistency and maintainability. Updates were made across several files to adopt this new structure, enhancing proof generation and validation methods, particularly within the relayer and tokenomics modules.

Changes

Files/Groups Change Summaries
pkg/crypto/protocol/proof_path.go Introduced SMT proof verification functionality, including a specific SmtSpec and GetPathForProof.
pkg/relayer/session/proof.go Updated to use protocol.GetPathForProof instead of proofkeeper.
tests/integration/tokenomics/... Modified test functions to utilize new proof path parameters and GetPathForProof from protocol.
x/proof/keeper/msg_server_submit_proof.go Refactored proof submission and verification to use protocol's SMT specifications and functions.
x/tokenomics/keeper/update_relay_mining_difficulty.go Changed import path to use protocol for cryptographic operations.

Poem

In the realm of code, where proofs do dance,
A new path forged, giving checks a chance.
From roots to leaves, the Merkle sings,
Protocol's strength, to projects it brings.
Hashes align, in cryptographic trance,
The relayer smiles, in a secure glance. 🐇🔒


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@bryanchriswhite bryanchriswhite changed the base branch from issues/584/refactor/count-difficulty-bits to main July 8, 2024 12:25
@bryanchriswhite bryanchriswhite force-pushed the issues/584/refactor/proot-path branch from 1429fe8 to 6d831f7 Compare July 8, 2024 12:28
@bryanchriswhite bryanchriswhite linked an issue Jul 8, 2024 that may be closed by this pull request
15 tasks
@bryanchriswhite bryanchriswhite added push-image CI related - pushes images to ghcr.io devnet-test-e2e labels Jul 8, 2024
Copy link

github-actions bot commented Jul 8, 2024

The image is going to be pushed after the next commit.

You can use make trigger_ci to push an empty commit.

If you also want to run E2E tests, please add devnet-test-e2e label.

Copy link

github-actions bot commented Jul 8, 2024

The CI will now also run the e2e tests on devnet, which increases the time it takes to complete all CI checks.

You may need to run make trigger_ci to submit an empty commit that'll trigger the tests.

GCP workloads (requires changing the namespace to 659)
Grafana network dashboard for devnet-issue-{issue-id}

@github-actions github-actions bot added the devnet label Jul 8, 2024
@bryanchriswhite bryanchriswhite marked this pull request as ready for review July 9, 2024 11:29
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bdbc365 and 565e299.

Files selected for processing (6)
  • pkg/crypto/protocol/proof_path.go (1 hunks)
  • pkg/relayer/session/proof.go (3 hunks)
  • tests/integration/tokenomics/relay_mining_difficulty_test.go (4 hunks)
  • x/proof/keeper/msg_server_submit_proof.go (5 hunks)
  • x/proof/keeper/msg_server_submit_proof_test.go (13 hunks)
  • x/tokenomics/keeper/update_relay_mining_difficulty.go (2 hunks)
Additional comments not posted (22)
pkg/crypto/protocol/proof_path.go (1)

15-22: LGTM! Verify SMT specification initialization.

The initialization logic for the SMT specification looks good. Ensure that the SmtSpec is correctly used in the rest of the codebase.

x/tokenomics/keeper/update_relay_mining_difficulty.go (2)

13-13: LGTM! Verify usage of protocol.SmtSpec.

The logic for updating relay mining difficulty looks good. Ensure that the protocol.SmtSpec is correctly used throughout the function.


150-152: LGTM! Verify usage of protocol.SmtSpec.

The logic for returning the default difficulty target hash looks good. Ensure that the protocol.SmtSpec is correctly used in this function.

tests/integration/tokenomics/relay_mining_difficulty_test.go (2)

32-32: LGTM! Verify test coverage.

The test logic for updating relay mining difficulty for a new service looks good. Ensure that the test covers all relevant scenarios.


206-215: LGTM! Verify proof generation logic.

The proof generation logic looks good. Ensure that the proof is correctly generated and used in the tests.

pkg/relayer/session/proof.go (2)

8-8: LGTM! Verify proof submission logic.

The logic for submitting proofs looks good. Ensure that the proof submission is correctly handled and tested.


Line range hint 219-241:
LGTM! Verify proof generation logic.

The proof generation logic looks good. Ensure that the proof is correctly generated and used in the proof submission process.

x/proof/keeper/msg_server_submit_proof.go (4)

154-154: Correct usage of protocol.SmtSpec in GetValueHash.

The change to use protocol.SmtSpec in GetValueHash is correct and aligns with the centralization of SMT specifications.


517-520: Correct usage of protocol.GetPathForProof.

The change to use protocol.GetPathForProof for proof path validation is correct and aligns with the centralization of proof path calculations.


443-443: Correct usage of protocol.SmtSpec in VerifyClosestProof.

The change to use protocol.SmtSpec in VerifyClosestProof is correct and aligns with the centralization of SMT specifications.


Line range hint 197-198:
Correct usage of protocol.GetPathForProof.

The change to use protocol.GetPathForProof for computing the expected proof path is correct and aligns with the centralization of proof path calculations.

x/proof/keeper/msg_server_submit_proof_test.go (11)

58-58: Correct usage of protocol.GetPathForProof in init.

The change to use protocol.GetPathForProof in the init function is correct and aligns with the centralization of proof path calculations.


76-76: Correct usage of shared.GetEarliestSupplierProofCommitHeight.

The change to use shared.GetEarliestSupplierProofCommitHeight for proof message height calculation is correct and aligns with the new logic.


166-169: Correct block height advancement for claim message height.

The change to advance the block height for claim message height is correct and ensures proper timing for proof submission.


183-195: Correct block height advancement and block hash storage for proof path seed height.

The changes to advance the block height to the proof path seed height and store the block hash are correct and ensure proper proof path validation.


197-198: Correct usage of protocol.GetPathForProof for expected proof path calculation.

The change to use protocol.GetPathForProof for computing the expected proof path is correct and aligns with the centralization of proof path calculations.


201-201: Correct block height advancement for proof message height.

The change to advance the block height for proof message height is correct and ensures proper timing for proof submission.


406-406: Correct usage of keepertest.WithBlockHash.

The change to use keepertest.WithBlockHash for block hash setup is correct and ensures proper proof path validation.


520-520: Correct block height advancement for claim message height.

The change to advance the block height for claim message height is correct and ensures proper timing for proof submission.


1087-1091: Correct usage of protocol.GetPathForProof for expected proof path calculation.

The change to use protocol.GetPathForProof for computing the expected proof path is correct and aligns with the centralization of proof path calculations.


1201-1211: Correct block height advancement and block hash storage for proof path seed height.

The changes to advance the block height to the proof path seed height and store the block hash are correct and ensure proper proof path validation.


1428-1428: Correct usage of protocol.SmtSpec in GetValueHash.

The change to use protocol.SmtSpec in GetValueHash is correct and aligns with the centralization of SMT specifications.

Comment on lines +24 to +32
// GetPathForProof computes the path to be used for proof validation by hashing
// the block hash and session id.
func GetPathForProof(blockHash []byte, sessionId string) []byte {
hasher := newHasher()
if _, err := hasher.Write(append(blockHash, []byte(sessionId)...)); err != nil {
panic(err)
}

return hasher.Sum(nil)
Copy link

Choose a reason for hiding this comment

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

Consider handling potential errors more gracefully.

The hash computation logic looks good. However, consider handling potential errors more gracefully instead of using panic.

-  panic(err)
+  log.Fatalf("failed to write hash: %v", err)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// GetPathForProof computes the path to be used for proof validation by hashing
// the block hash and session id.
func GetPathForProof(blockHash []byte, sessionId string) []byte {
hasher := newHasher()
if _, err := hasher.Write(append(blockHash, []byte(sessionId)...)); err != nil {
panic(err)
}
return hasher.Sum(nil)
// GetPathForProof computes the path to be used for proof validation by hashing
// the block hash and session id.
func GetPathForProof(blockHash []byte, sessionId string) []byte {
hasher := newHasher()
if _, err := hasher.Write(append(blockHash, []byte(sessionId)...)); err != nil {
log.Fatalf("failed to write hash: %v", err)
}
return hasher.Sum(nil)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 565e299 and 9e8a9a9.

Files selected for processing (3)
  • pkg/relayer/session/proof.go (3 hunks)
  • x/proof/keeper/msg_server_submit_proof.go (5 hunks)
  • x/tokenomics/keeper/update_relay_mining_difficulty.go (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • pkg/relayer/session/proof.go
  • x/proof/keeper/msg_server_submit_proof.go
  • x/tokenomics/keeper/update_relay_mining_difficulty.go

@bryanchriswhite
Copy link
Contributor Author

E2E tests passing locally but failed to re-run in CI:

image

@bryanchriswhite bryanchriswhite merged commit f853bcb into main Jul 15, 2024
9 of 10 checks passed
@bryanchriswhite bryanchriswhite deleted the issues/584/refactor/proot-path branch July 15, 2024 10:25
bryanchriswhite added a commit that referenced this pull request Jul 15, 2024
…ent-balances

* pokt/main:
  [TODOs] refactor: proof path calculation (#659)
  [Dependencies] bump go-getter and ibc-go (#691)
  [Relayminer] refactor: `relayerSessionsManager#waitForBlock()` (#648)
  [Observables] chore: add `ReplayObservable#SubscribeFromLatestBufferedOffset()` (#647)
  [Observability] Add claim relays counter (#644)
  [Code Health] chore: log unused error when updating relay mining difficulty (#683)
  [Testing] chore: uncomment proof CLI query tests (#668)
  build(deps): bump ws from 7.5.9 to 7.5.10 in /docusaurus (#686)
  build(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 in /docusaurus (#688)
  build(deps): bump express from 4.18.2 to 4.19.2 in /docusaurus (#687)
  build(deps): bump follow-redirects from 1.15.3 to 1.15.6 in /docusaurus (#685)
  build(deps): bump braces from 3.0.2 to 3.0.3 in /docusaurus (#689)
  [CosmosSDK] Bump to v0.50.7 (#682)
bryanchriswhite added a commit that referenced this pull request Jul 15, 2024
…ation-overserviced

* pokt/main:
  [TODOs] refactor: proof path calculation (#659)
  [Dependencies] bump go-getter and ibc-go (#691)
  [Relayminer] refactor: `relayerSessionsManager#waitForBlock()` (#648)
  [Observables] chore: add `ReplayObservable#SubscribeFromLatestBufferedOffset()` (#647)
  [Observability] Add claim relays counter (#644)
  [Code Health] chore: log unused error when updating relay mining difficulty (#683)
  [Testing] chore: uncomment proof CLI query tests (#668)
  build(deps): bump ws from 7.5.9 to 7.5.10 in /docusaurus (#686)
  build(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 in /docusaurus (#688)
  build(deps): bump express from 4.18.2 to 4.19.2 in /docusaurus (#687)
  build(deps): bump follow-redirects from 1.15.3 to 1.15.6 in /docusaurus (#685)
  build(deps): bump braces from 3.0.2 to 3.0.3 in /docusaurus (#689)
  [CosmosSDK] Bump to v0.50.7 (#682)
bryanchriswhite added a commit that referenced this pull request Jul 15, 2024
…ation-use-index

* pokt/main:
  [TODOs] refactor: proof path calculation (#659)
  [Dependencies] bump go-getter and ibc-go (#691)
  [Relayminer] refactor: `relayerSessionsManager#waitForBlock()` (#648)
  [Observables] chore: add `ReplayObservable#SubscribeFromLatestBufferedOffset()` (#647)
  [Observability] Add claim relays counter (#644)
  [Code Health] chore: log unused error when updating relay mining difficulty (#683)
  [Testing] chore: uncomment proof CLI query tests (#668)
  build(deps): bump ws from 7.5.9 to 7.5.10 in /docusaurus (#686)
  build(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 in /docusaurus (#688)
  build(deps): bump express from 4.18.2 to 4.19.2 in /docusaurus (#687)
  build(deps): bump follow-redirects from 1.15.3 to 1.15.6 in /docusaurus (#685)
  build(deps): bump braces from 3.0.2 to 3.0.3 in /docusaurus (#689)
  [CosmosSDK] Bump to v0.50.7 (#682)
okdas pushed a commit that referenced this pull request Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devnet devnet-test-e2e off-chain Off-chain business logic on-chain On-chain business logic protocol General core protocol related changes push-image CI related - pushes images to ghcr.io
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[TODO] @Olshansk's (and now @Bryan's) Blocker TODOs
2 participants