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

Merkle Proof to verify the key-value pair is part of Merkle root #705

Open
elitex45 opened this issue Jan 20, 2025 · 2 comments
Open

Merkle Proof to verify the key-value pair is part of Merkle root #705

elitex45 opened this issue Jan 20, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@elitex45
Copy link

We're planning to store large amounts of data (>1M records) in NOMT for efficiency. We need to verify this data on-chain without storing all records in the smart contract.

Technical Requirements

  1. Store Merkle root on-chain
  2. Our API will return below after querying NOMT:
    • Value for a given key
    • Merkle proof for verification

From what we saw in the examples and docs, we get old Merkle root, new Merkle root, and witness. Is there any way that we can get a Merkle proof of a single key-value pair to prove its a part of Merkle root?

Example Implementation

import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";

contract DataVerifier {
    bytes32 public merkleRoot;

    function verifyData(
        bytes32 key,
        uint256 value,
        bytes32[] memory proof
    ) public view returns (bool) {
        bytes32 leaf = keccak256(abi.encodePacked(key, value));
        return MerkleProof.verify(proof, merkleRoot, leaf);
    }
}

Current Blocker

Need access to get_proof function to generate valid Merkle proofs compatible with OpenZeppelin's verification for a given key.

Request

Looking for guidance on implementing/accessing the get_proof function in NOMT to generate Merkle proofs for on-chain verification,

Summary

Essentially when user calls our API with a key, we need to return value stored for that key, Merkle proof to verify that key & value are part of the Merkle root stored onchain.

@rphmeier rphmeier added the enhancement New feature or request label Jan 20, 2025
@rphmeier
Copy link
Contributor

We currently don't provide any way to generate a proof of a single key. We will look into this after 1.0!

One question about your use-case: do you need merkle proofs to be generated within a session or outside of it?

@elitex45
Copy link
Author

One question about your use-case: do you need merkle proofs to be generated within a session or outside of it?

We need Merkle proofs to be generated for all the keys regardless of the session. That way we can verify any key-value pair on-chain with Merkle root.

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

No branches or pull requests

2 participants