Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix merkle tree hashing for poseidon (#277)
<!--- Please provide a general summary of your changes in the title above --> ## Pull Request type <!-- Please try to limit your pull request to one type; submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [x] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no API changes) - [ ] Build-related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> Issue Number: N/A ## What is the new behavior? The current Poseidon hashing implementation for the merkle tree is incorrect. It uses ``` let mut state = PoseidonTrait::new(); state = state.update(data1); state = state.update(data2); state.finalize() ``` Under the hood this actually hashes the elements twice (once from the state update and once from finalization, see [corelib](https://github.com/starkware-libs/cairo/blob/main/corelib/src/poseidon.cairo)), the intended behaviours is that only one round of hashing is done (when hashing two elements). This is noted in https://docs.starknet.io/documentation/architecture_and_concepts/Cryptography/hash-functions/#poseidon_hash where by the hash of two elements is simply <img width="417" alt="Screenshot 2024-02-19 at 11 53 04" src="https://github.com/keep-starknet-strange/alexandria/assets/106159231/b4421134-d522-4ab6-be62-e41f61e335a4">. Also please see POC https://github.com/Leonard-Pat/merkle-tree-failing <!-- Please describe the behavior or changes that are being added by this PR. --> - Fixes Poseidon hashing for merkle tree poseidon impl ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this does introduce a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information Updated tests to reflect this change - note the gas limit was exceeded and therefore needed to be udpated as well <!-- Any other information that is important to this PR, such as screenshots of how the component looks before and after the change. -->
- Loading branch information