Pedersen vs Poseidon Merkle Tree Gas Comparison #234
Replies: 2 comments 2 replies
-
Hi. This is due to the layout used that has some specific ratios between number of steps and number of builtin used, and it effectively limits the number of builtin you can use in a given cairo program relatively to the number of steps. However this is fortunately going to change with dynamic layouts, where depending on the number of resources you've used in your transaction, you will be charged accordingly and precisely because they will compute a layout specially made for what you've used. Basically you should view your cairo program as a matrix. Note that the gas usage you see locally (not on testnet or mainnet) with the latest version of cairo reflects this dynamic cost property. I suggest looking at this if you want to learn more : https://starkware.medium.com/builtins-and-dynamic-layouts-e419a73e29e TLDR : continue using poseidon and trust the process. |
Beta Was this translation helpful? Give feedback.
-
Btw I didn't read your code but based on the resources you've posted it seems you have an overhead, you should use the hades permutation directly if you are not already : |
Beta Was this translation helpful? Give feedback.
-
Hey guys quick question. I'm running some tests to compare the gas consumption for both tree types to determine the cheaper one to use in my contract (typical WL mint setup).
Other devs I'm working with initially said that Poseidon would be cheaper for 1) Creating the leaf hash & 2) Verifying the (root, leaf, proof) call.
My gas tests are calling
.verify()
using the same root, leaf, and proof (proof -> list of length 20).On Goerli, the gas consumption for Pedersen is 1698 and for Poseidon is 1701. And the breakdown on Katana is
Pedersen: Steps: 6748 | ECDSA: 1 | L1 Gas: 2448 | Pedersen: 36 | Range Checks: 230
Poseidon: Steps: 7329 | ECDSA: 1 | L1 Gas: 2448 | Pedersen: 16 | Poseidon Builtin: 40 | Range Checks: 230
Can you guys offer any input ? Am I getting incorrect outputs ? Or is the initial assumption of Poseidon being cheaper wrong ?
Beta Was this translation helpful? Give feedback.
All reactions