Skip to content

Winternitz Improvements in Generic Format - #127

Merged
lucidLuckylee merged 9 commits into
BitVM:mainfrom
chainwayxyz:generic-winternitz
Nov 11, 2024
Merged

lucidLuckylee merged 9 commits into
BitVM:mainfrom
chainwayxyz:generic-winternitz

Conversation

@just-erray

Copy link
Copy Markdown
Contributor

This PR optimizes the previous winternitz algorithms from winternitz.rs (ListpickVerifier) and winternitz_compact.rs (BruteforceVerifier), adds small improvements and fixes. Furthermore it adds two new algorithms (BinarysearchVerifier and HybridVerifier) for signature verification, as well as two new conversion algorithms (TabledConverter and StraightforwardConverter) from digit form to bytes, for the usage of various values of log_d. The table below shows each algorithms script size including signing in bytes for different message lengths, with the best suitable conversion algorithm.

20 bytes log_d=4 log_d=5 log_d=6 log_d=7 log_d=8
ListpickVerifier 4178 5133 6245 8801 11862
BruteforceVerifier 7654 11310 17507 28955 50978
BinarysearchVerifier 4706 5483 6125 7735 8964
HybridVerifier 4486 5343 6005 7631 8895
32 bytes log_d=4 log_d=5 log_d=6 log_d=7 log_d=8
ListpickVerifier 6458 8879 10125 13713 18031
BruteforceVerifier 11830 18766 27389 44719 77558
BinarysearchVerifier 7274 8804 9423 11981 13621
HybridVerifier 6934 8580 9239 11821 13516
128 bytes log_d=4 log_d=5 log_d=6 log_d=7 log_d=8
ListpickVerifier 24698 30972 36676 51312 67415
BruteforceVerifier 45238 67875 102345 168367 290198
BinarysearchVerifier 27818 33062 35976 45121 50909
HybridVerifier 26518 32226 35276 44517 50516
256 bytes log_d=4 log_d=5 log_d=6 log_d=7 log_d=8
ListpickVerifier Crashed 61407 72564 100852 133267
BruteforceVerifier 89957 134502 202411 331076 573719
BinarysearchVerifier Crashed 65547 71180 88675 100633
HybridVerifier Crashed 63891 69796 87487 99856

@sander2

sander2 commented Nov 6, 2024

Copy link
Copy Markdown
Contributor

This PR optimizes the previous winternitz algorithms from winternitz.rs (ListpickVerifier) and winternitz_compact.rs (BruteforceVerifier), adds small improvements and fixes.

Out of curiosity, could you expand on the improvements made compared to winternitz.rs / ListpickVerifier? As far as I can tell the script size remains unchanged, right?

Anyway, with this PR, would the two older files be completely redundant? If so, I'd be in favor of removing the old files

@just-erray

just-erray commented Nov 6, 2024 •

Copy link
Copy Markdown
Contributor Author

Out of curiosity, could you expand on the improvements made compared to winternitz.rs / ListpickVerifier? As far as I can tell the script size remains unchanged, right?

For log_d=4, Listpickverifier has the exact script size as the previous winternitz.rs. For larger log_d values, it can only save 1 or 2 opcodes per digit because it duplicates the number instead of pushing it twice. Other algorithms are useful when the message size is large where we would want to choose larger log_d values considering maximum stack depth.

Actually the binary search algorithm was sitting in our repository for some time now and I was considering merging the two algorithms for a more optimized one (making HybridVerifier, it uses binary search and listing-OP_PICK algorithms consequently) , but the real inspiration came when I saw your PR (it is now an optimized special case of the current Hybrid algorithm, where it uses only one step of binary search), so thank you very much for that.

Anyway, with this PR, would the two older files be completely redundant?

I believe so.

@lucidLuckylee

Copy link
Copy Markdown
Contributor

Anyway, with this PR, would the two older files be completely redundant? If so, I'd be in favor of removing the old files

Me too. Could you do that before we merge?

@just-erray

Copy link
Copy Markdown
Contributor Author

Me too. Could you do that before we merge?

I think, in that case, the old winternitz_hash.rs file stops working due to its dependencies on the winternitz.rs file. Should I edit winternitz_hash.rs to make it compatible with the generic version? Also doing these edits doesn't seem to cause any issues with the current chunker projects. Alpen's chunker uses a version of their own, and I believe this one doesn't have a winternitz implementation yet.

What should I name the new code file if I delete the two previous ones? Should it be just winternitz.rs or winternitz_generic.rs?"

@lucidLuckylee

lucidLuckylee commented Nov 10, 2024 •

Copy link
Copy Markdown
Contributor

Should I edit winternitz_hash.rs to make it compatible with the generic version?

That would be great.

Should it be just winternitz.rs or winternitz_generic.rs?

Just winternitz.rs seems good to me.

@lucidLuckylee

Copy link
Copy Markdown
Contributor

Thanks @just-erray! Great work!

@lucidLuckylee
lucidLuckylee merged commit 2f2d94e into BitVM:main Nov 11, 2024
@just-erray
just-erray deleted the generic-winternitz branch January 12, 2025 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants