Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btcec: Avoid panic in fieldVal.SetByteSlice for large inputs #1602

Merged
merged 1 commit into from
Jul 13, 2020

Conversation

onyb
Copy link
Collaborator

@onyb onyb commented Jul 9, 2020

Summary

The implementation has been adapted from the dcrec module in dcrd. The bug was initially fixed in decred/dcrd@3d9cda1 while transitioning to a constant time algorithm. A large set of test vectors were subsequently added in decred/dcrd@8c6b52d.

The function signature has been preserved for backwards compatibility. This means that returning whether the value has overflowed, and the corresponding test vectors have not been backported.

This fixes #1170 and closes a previous attempt to fix the bug in #1178.

Benchmarks

With changes from #1178:

benchmark                              iter     time/iter
---------                              ----     ---------
BenchmarkFieldVal_SetByteSlice-8   27170966   40.60 ns/op

With this PR: (~2.8 times faster)

benchmark                              iter     time/iter
---------                              ----     ---------
BenchmarkFieldVal_SetByteSlice-8   72301308   14.60 ns/op

btcec/field.go Outdated Show resolved Hide resolved
btcec/field.go Outdated Show resolved Hide resolved
The implementation has been adapted from the dcrec module in dcrd. The
bug was initially fixed in decred/dcrd@3d9cda1 while transitioning to a
constant time algorithm. A large set of test vectors were subsequently
added in decred/dcrd@8c6b52d.

The function signature has been preserved for backwards compatibility.
This means that returning whether the value has overflowed, and the
corresponding test vectors have not been backported.

This fixes btcsuite#1170 and closes a previous attempt to fix the bug in btcsuite#1178.
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updates look good.

Copy link
Member

@jcvernaleo jcvernaleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@jcvernaleo jcvernaleo merged commit d28c716 into btcsuite:master Jul 13, 2020
@onyb onyb deleted the setbyteslice branch July 13, 2020 13:43
@onyb onyb mentioned this pull request Jul 22, 2020
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.

shall we restrict the size of input in btcec.FieldVal.SetByteSlice(b []byte)?
3 participants