simplify poseidon_safe_domain_separator
#25
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I started looking at the following two comments:
to see if there was some room for optimization here by precomputing things (I don't believe so;
applyis only called in non hot code paths directly and is the only place where we construct the domain separator on each call). While looking into this, I realized that theposeidon_safe_domain_separatorhelper was more complicated than necessary.The doc comment previously explained that the function was specific to a single Poseidon permutation. However, it still tried to be generic. As a result the code was more complex than necessary (3 additional generic arguments) and technically broken for any permutation that does not use 24 field elements.
Instead it now is indeed specific to the poseidon2 permutation with 24 field elements.
For the use case of producing packed data, we simply broadcast the result after calling the function. This is only used in the preamble of the
compute_tree_leavescode anyway.I personally prefer code less generic than necessary, but I understand if we don't want to merge this.