-
Notifications
You must be signed in to change notification settings - Fork 188
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(katana): classes trie hash #2876
Conversation
Caution Review failedThe pull request is closed. WalkthroughOhayo, sensei! This PR introduces a modification in the hashing algorithm for proof verification within the Katana RPC and trie components. The main change involves transitioning from the Pedersen hash function to the Poseidon hash function across several files. This update affects the verification processes for both class and contract proofs, ensuring consistency in the cryptographic approach used in multi-proof verification and trie structures. Changes
Possibly related PRs
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 2
🧹 Nitpick comments (2)
crates/katana/trie/src/classes.rs (1)
29-29
: Ohayo! Important architectural change detected, sensei!The transition from Pedersen to Poseidon in
BonsaiTrie
is a fundamental change that affects the entire trie structure. This change:
- Modifies the hash computation for all trie nodes
- Will result in different trie roots for the same data
- Requires careful migration planning for existing data
Consider documenting:
- Migration strategy for existing tries
- Performance implications of Poseidon vs Pedersen
- Backward compatibility considerations
crates/katana/rpc/rpc/tests/proofs.rs (1)
125-128
: Enhance test coverage for hash function transition, sensei!While the existing tests verify the proof functionality, consider adding specific test cases to:
- Verify that old Pedersen proofs are rejected
- Test the performance implications of Poseidon vs Pedersen
- Add edge cases specific to Poseidon hash characteristics
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
crates/katana/rpc/rpc/tests/proofs.rs
(1 hunks)crates/katana/trie/src/classes.rs
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: fmt
🔇 Additional comments (1)
crates/katana/trie/src/classes.rs (1)
4-4
: Ohayo! Import changes look good, sensei!The transition from Pedersen to Poseidon hash is properly reflected in the imports.
@@ -15,7 +14,7 @@ impl ClassesMultiProof { | |||
// TODO: maybe perform results check in this method as well. make it accept the compiled class | |||
// hashes | |||
pub fn verify(&self, root: Felt, class_hashes: Vec<ClassHash>) -> Vec<Felt> { | |||
crate::verify_proof::<Pedersen>(&self.0, root, class_hashes) | |||
crate::verify_proof::<Poseidon>(&self.0, root, class_hashes) |
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.
💡 Codebase verification
Ohayo! Test files need updating, sensei!
The switch to Poseidon affects these test files:
crates/katana/storage/db/src/trie/mod.rs
(test cases)crates/katana/rpc/rpc/tests/proofs.rs
Please update the test cases to use Poseidon instead of Pedersen to maintain consistency with the production code.
🔗 Analysis chain
Verify compatibility with existing callers, sensei!
The switch from Pedersen to Poseidon in verify_proof
is a breaking change. Let's verify all callers are updated.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for all calls to verify_proof to ensure they're updated
rg -l "verify_proof::<.*Pedersen>"
Length of output: 115
Script:
#!/bin/bash
# Check the actual usage in both files
echo "=== storage/db/src/trie/mod.rs ==="
rg "verify_proof::<.*Pedersen>" crates/katana/storage/db/src/trie/mod.rs -B 2 -A 2
echo -e "\n=== rpc/rpc/tests/proofs.rs ==="
rg "verify_proof::<.*Pedersen>" crates/katana/rpc/rpc/tests/proofs.rs -B 2 -A 2
Length of output: 1531
@@ -122,7 +122,7 @@ async fn genesis_states() { | |||
|
|||
let classes_proof = MultiProof::from(proofs.classes_proof.nodes); | |||
let classes_tree_root = proofs.global_roots.classes_tree_root; | |||
let classes_verification_result = katana_trie::verify_proof::<hash::Pedersen>( | |||
let classes_verification_result = katana_trie::verify_proof::<hash::Poseidon>( |
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.
Critical: Inconsistent hash function usage detected, sensei!
While classes verification has been updated to use Poseidon, contract and storage proofs are still using Pedersen. This inconsistency could lead to:
- Confusion in the codebase
- Potential verification issues
- Maintenance challenges
Consider:
- Updating all proof verifications to use Poseidon consistently
- Or documenting why different hash functions are used for different proofs
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/katana/storage/db/src/trie/mod.rs (1)
391-391
: Ohayo! Both hash functions are still imported but only Poseidon is used.While the code now uses Poseidon exclusively, the Pedersen import remains. Consider removing the unused import to maintain code cleanliness.
- use katana_primitives::hash::{Pedersen, Poseidon, StarkHash}; + use katana_primitives::hash::{Poseidon, StarkHash};
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/katana/storage/db/src/trie/mod.rs
(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: fmt
🔇 Additional comments (2)
crates/katana/storage/db/src/trie/mod.rs (2)
450-450
: LGTM! Consistent transition to Poseidon hash for proof verification.The changes correctly implement the transition from Pedersen to Poseidon hash across all proof verification scenarios:
- Single key proof for snapshot 0
- Single key proof for snapshot 1
- Multi-key proof for current state
Also applies to: 467-467, 478-478
Line range hint
391-486
: Verify the impact of the hash function transition.The switch from Pedersen to Poseidon hash is a significant architectural change that could affect:
- Proof verification compatibility with existing data
- Performance characteristics
- Security properties
Sensei, let's verify the broader impact:
✅ Verification successful
Ohayo sensei! The hash function transition has been properly implemented and verified.
The test demonstrates that the Poseidon hash implementation works correctly for:
- Root calculation
- Proof verification
- Hash value computation
No compatibility issues or remaining Pedersen dependencies were found in the proof verification system.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any remaining Pedersen hash usage in proof verification # and potential compatibility issues. echo "Checking for remaining Pedersen hash usage in proof verification..." rg -l "verify_proof::<Pedersen>" echo "Checking for potential compatibility handling..." ast-grep --pattern 'fn verify_proof<H: $_>($_) -> $_'Length of output: 342
Script:
#!/bin/bash # Search for broader Pedersen hash usage and hash implementations echo "Checking for Pedersen hash usage..." rg -l "Pedersen" echo "Looking for hash trait implementations..." ast-grep --pattern 'impl $_ for Pedersen' echo "Checking test files for hash function usage..." rg -l "Pedersen|Poseidon" "**/test*.rs" echo "Looking for hash-related configuration..." rg -l "hash.*config|hash.*const"Length of output: 2001
Script:
#!/bin/bash # Examine hash function usage context and compatibility echo "Checking hash function usage in trie files..." rg -A 5 "Pedersen|Poseidon" "crates/katana/trie/src/*.rs" echo "Checking test files with correct pattern..." fd -t f "test.*\.rs$" -x rg -l "Pedersen|Poseidon" {} echo "Looking for hash type parameters and trait bounds..." ast-grep --pattern 'H: Hash' echo "Checking for migration or compatibility code..." rg -A 5 "migration|compatibility|legacy.*hash"Length of output: 74712
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2876 +/- ##
==========================================
- Coverage 55.77% 55.76% -0.01%
==========================================
Files 447 447
Lines 57794 57794
==========================================
- Hits 32233 32230 -3
- Misses 25561 25564 +3 ☔ View full report in Codecov by Sentry. |
It was set to Pedersen based on the Starknet docs but Pathfinder is using Poseidon. Based on my experience, it's better to just follow what Pathfinder is doing.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Tests