-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool
crates/merkle-tree/src/class.rs
Outdated
return Ok(None); | ||
}; | ||
|
||
MerkleTree::<PedersenHash, 251>::get_proof(root, &storage, casm.view_bits()) |
There was a problem hiding this comment.
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.
crates/merkle-tree/src/class.rs
Outdated
/// Tree data is persisted by a sqlite table 'tree_class'. | ||
|
||
pub struct ClassStorageTree<'tx> { | ||
tree: MerkleTree<PedersenHash, 251>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, use PoseidonHash
.
There was a problem hiding this 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>, | ||
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub struct GetProofOutputClass { | |
pub struct GetClassProofOutput { |
pub struct GetProofInputClass { | ||
pub block_id: BlockId, | ||
pub class_hash: ClassHash, | ||
pub keys: Vec<StorageAddress>, |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub async fn get_proof_class( | |
pub async fn get_class_proof( |
e | ||
})?; | ||
class_proofs.push(ProofNodes(proof)); | ||
} |
There was a problem hiding this comment.
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.
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:
CHANGELOG.md