You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 22, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 22, 2026. It is now read-only.
When translating keys in a given policy/miniscript, translating:
and(pk(A), pk(B))
with F: { A -> X, B -> X }
creates
and(pk(X), pk(X))
bypassing the check that no duplicate/repeated keys are used.
Fixing this requires changing from a function to a bijective map of some kind, either by tracing the function as it's used or switching the type externally to some kind of map.
A simpler but slightly inefficient solution might be to retraverse the tree again. I am not against doing this because we are already traversing the tree once when translating.
@JeremyRubin, We can call the translate function only once and save the output policy/miniscript which possibly contains duplicate keys. Do the checks again on the translated miniscript/policy.
Am I missing something or are you looking for an efficient way to it while creating(one traversal) while aborting at the first duplicate?
Ah, certainly doing full checks after translating is the safest choice, but I think given that most functions are probably just getters around a map might make sense to do something just passing a map in. I'm for whatever works and closes the safety hole.
When you said 'retraverse' I thought you meant while translating in a manner that calls the function more than once per key. (Interestingly this sort of trick could be used to translate a duplicated-key script to non duplicated if it uses e.g. sequential HD derivation per call per key)
@sanket1729 reminder now that #493 is merged. I just experimented with this library and was quite confused why there was no error with duplicate keys present.
@benma. Are you facing the no error when translating keys using TranslatePk? This is fixed in #556. All regular methods from_str, parse, compile etc should currently be fail on duplicated keys.
Activity
sanket1729 commentedon Mar 5, 2021
A simpler but slightly inefficient solution might be to retraverse the tree again. I am not against doing this because we are already traversing the tree once when translating.
JeremyRubin commentedon Mar 5, 2021
@sanket1729 I advise caching because the function could have interior mutable state and lie to you...
sanket1729 commentedon Mar 6, 2021
@JeremyRubin, We can call the translate function only once and save the output policy/miniscript which possibly contains duplicate keys. Do the checks again on the translated miniscript/policy.
Am I missing something or are you looking for an efficient way to it while creating(one traversal) while aborting at the first duplicate?
JeremyRubin commentedon Mar 6, 2021
Ah, certainly doing full checks after translating is the safest choice, but I think given that most functions are probably just getters around a map might make sense to do something just passing a map in. I'm for whatever works and closes the safety hole.
When you said 'retraverse' I thought you meant while translating in a manner that calls the function more than once per key. (Interestingly this sort of trick could be used to translate a duplicated-key script to non duplicated if it uses e.g. sequential HD derivation per call per key)
sanket1729 commentedon Jan 17, 2023
Planning to cleanly address this after #493.
benma commentedon Jun 14, 2023
@sanket1729 reminder now that #493 is merged. I just experimented with this library and was quite confused why there was no error with duplicate keys present.
sanket1729 commentedon Jun 15, 2023
@benma. Are you facing the no error when translating keys using
TranslatePk? This is fixed in #556. All regular methodsfrom_str,parse,compileetc should currently be fail on duplicated keys.benma commentedon Jun 15, 2023
Yes exactly. Thanks for the fix.