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

feat : added pathfinder_getClassProof method #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ocdbytes
Copy link

Added pathfinder_getClassProof method in order to get the class proof tree and other vars neccessary for calculating the inputs for the SNOS.


Added pathfinder_getClassProof method in order to get the class proof tree and other vars neccessary for calculating the inputs for the SNOS. Need to add test cases also for this particular end point and testing needs to be done for an example execution.


Consider motivating any new dependencies.


Delete once completed:

  • link any issues closed by this pull-request
  • add all user-facing changes to CHANGELOG.md
  • new dependencies were added to the workspace toml

Copy link

@odesenfans odesenfans left a comment

Choose a reason for hiding this comment

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

Some minor comments, I still need to test it but it looks good!

.gitignore Outdated

# Intellij IDE generated files
.idea

Choose a reason for hiding this comment

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

Pretty sure that the Pathfinder guys will disapprove this. Note that you can set up a global .gitignore file in your home directory to avoid this.

Copy link
Author

Choose a reason for hiding this comment

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

cool

return Ok(None);
};

MerkleTree::<PedersenHash, 251>::get_proof(root, &storage, casm.view_bits())

Choose a reason for hiding this comment

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

The class trie uses Poseidon hashing. I'm unsure of how much the hash function generic is useful in the function you call here but I'm pretty sure we should use PoseidonHash for correctness.

/// Tree data is persisted by a sqlite table 'tree_class'.

pub struct ClassStorageTree<'tx> {
tree: MerkleTree<PedersenHash, 251>,

Choose a reason for hiding this comment

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

Same, use PoseidonHash.

Copy link

@odesenfans odesenfans left a comment

Choose a reason for hiding this comment

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

A better review! Sorry it took me so long.

pub struct ClassStorageTree<'tx> {
tree: MerkleTree<PoseidonHash, 251>,
storage: ClassStorage<'tx>,
}

Choose a reason for hiding this comment

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

After looking at the Pathfinder implementation, I don't see the point of this structure. While the contract tree is made of one main tree that maps contract addresses to contract state, and then N subtrees that map the storage key and values for each contract, the class tree is unique and maps class hashes to class metadata. This is already implemented by ClassCommitmentTree.

Long story short, ClassStorageTree does not appear to be relevant and IMO can be deleted entirely.

@@ -16,6 +17,13 @@ pub struct GetProofInput {
pub keys: Vec<StorageAddress>,
}

#[derive(Deserialize, Debug, PartialEq, Eq)]
pub struct GetProofInputClass {

Choose a reason for hiding this comment

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

Suggested change
pub struct GetProofInputClass {
pub struct GetClassProofInput {

Following the naming of the endpoint (pathfinder_getClassProof), this should be renamed GetClassProofInput.

@@ -151,6 +159,18 @@ pub struct GetProofOutput {
contract_data: Option<ContractData>,
}

#[derive(Debug, Serialize)]
#[skip_serializing_none]
pub struct GetProofOutputClass {

Choose a reason for hiding this comment

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

Suggested change
pub struct GetProofOutputClass {
pub struct GetClassProofOutput {

pub struct GetProofInputClass {
pub block_id: BlockId,
pub class_hash: ClassHash,
pub keys: Vec<StorageAddress>,

Choose a reason for hiding this comment

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

Here the keys parameter does not make sense. pathfinder_getProof returns the global state proof for a single contract and storage proofs for each key requested.

For the class proof, we do not have a notion of keys: we just want the proof that the class is defined in the class tree. You can just remove this parameter.

@@ -278,6 +298,95 @@ pub async fn get_proof(
jh.await.context("Database read panic or shutting down")?
}

/// Returns all the necessary data to trustlessly verify class changes for a
/// particular contract.
pub async fn get_proof_class(

Choose a reason for hiding this comment

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

Suggested change
pub async fn get_proof_class(
pub async fn get_class_proof(

e
})?;
class_proofs.push(ProofNodes(proof));
}

Choose a reason for hiding this comment

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

Concluding the point on the keys param, you never use class_proofs. Meaning, we can safely delete the keys parameter as suggested above.

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.

2 participants