friedger / clarity-bitcoin

Clarity library for parsing Bitcoin transactions and verifying Merkle proofs
GNU Affero General Public License v3.0
18 stars 9 forks source link

[2.1] Remove `inner-buff32-permutation` #5

Closed jcnelson closed 1 year ago

jcnelson commented 1 year ago

Hey @friedger, great work on porting this library to Clarity 2!

I just wanted to let you know that the function inner-buff32-permutation can be removed, and replaced with a series of element-at? and replace-at? calls in reverse-buff32. This would remove the need to run 32 calls to concat. This should save you a lot of runtime, because concat-ing two sequences of lengths m and n has runtime complexity O(m + n), whereas element-at? is O(1) and replace-at? is O(s) where s is the size of one item in the sequence (for buff, s = 1).

friedger commented 1 year ago

Thank you for the suggestion @jcnelson. Implemented in #6 We see a reduction in runtime costs from 0.08% to 0.02%