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

Remove $GOPATH Caching #9

Merged
merged 62 commits into from
Aug 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
6799104
Remove $GOPATH Caching
jakesylvestre Feb 10, 2020
c01c981
Merge pull request #1537 from jakesyl/patch-1
jcvernaleo Mar 3, 2020
eed57cd
go fmt
jakesylvestre Jan 22, 2020
3eb4739
Fix minRelayTxFee name in comment
federicobond Jul 9, 2018
1639d6c
release: add missing back tick in build docs
Dec 26, 2019
8bbbe98
peer: fix small typo
gtank Oct 9, 2019
0c76fbd
Fix comment error
imnisen Mar 3, 2019
318c89d
fix comment of database.Tx to match code
yashbhutwala Jun 25, 2019
46461dc
btcjson, rpclient: Fix typo
Jul 5, 2019
ef4cecf
blockchain/indexers: Start a new line for long code
qshuai Jan 29, 2019
e2c08cc
docs/json_rpc_api: update go examples
mohanson Aug 27, 2018
06e5c43
Add note about using gencerts when listening on specific interfaces
kulpreet Jul 18, 2018
160c388
Refactor GetBlockCmd type and NewGetBlockCmd() function to follow the…
jalavosus Jan 31, 2020
468154a
Refactor GetBlockVerboseResult into two separate types: one type for …
jalavosus Jan 31, 2020
57cb8e4
Refactor FutureGetBlockVerboseResult into two types: FutureGetBlockVe…
jalavosus Jan 31, 2020
a310aa6
All tests pass
jalavosus Mar 5, 2020
e9f15ed
rpcclient: Add net params to Client (#1467)
jcvernaleo Mar 5, 2020
1d0bfca
fix error message
Jan 12, 2020
9e94ccb
server: Fix incorrect log message format
stevenroose Mar 16, 2018
96f3808
BUG:dynamicbanscore deadlock
lochjin Mar 6, 2020
fd0921b
btcjson: add RPC_IN_WARMUP error code
sangaman Feb 18, 2020
c4f3999
Refactor GetBlockVerboseTx to reflect correct getblock RPC call… (#1529)
jakesylvestre Mar 9, 2020
d9ce6b0
btcjson,rpcclient: use proper Deprecated comment format
quasilyte Sep 13, 2018
a8eadd2
update GetMempoolEntryResult to v0.19.0
jakesylvestre Jan 22, 2020
8b1be46
Add generatetoaddress and estimatesmartfee RPCs
torkelrogstad Nov 26, 2019
cfcf4fb
Implement 'getblockstats' JSON-RPC command
Jeiwan Nov 27, 2019
08b8751
cmd/btcctl: use regexp.MustCompile for constant patterns
quasilyte Sep 13, 2018
57d44d0
Try both TX serialization formats
torkelrogstad Dec 2, 2019
9f15a7e
Alphabetize --help output; add missing options to doc.go
murrayn Apr 14, 2020
8b54b0b
config.go: remove extra quotes
Rjected Apr 14, 2020
8512aff
readme: remove duplicate word
tpkeeper May 6, 2020
b298415
Improve error message about non-active segwit on simnet
darwin Mar 25, 2019
b470eee
btcctl: add regtest mode to btcctl
Rjected Apr 14, 2020
a505b99
build: replace travis-ci with github actions.
dajohi May 13, 2020
bc8d63b
build: update deps
dajohi May 13, 2020
f7399e6
build: clean linter warnings
dajohi May 13, 2020
d38279e
btcjson: change getblock default verbosity to 1
henryperson May 15, 2020
742935e
rpcclient: send legacy GetBlock request for backwards compatibility
wpaulino May 14, 2020
9a88e1d
Merge pull request #1575 from dajohi/clean
Roasbeef May 15, 2020
9f0179f
Merge pull request #1577 from wpaulino/getblock-compat
Roasbeef May 15, 2020
280845a
rpcclient: Add cookie auth
JeremyRand May 25, 2020
915788b
rpcclient: Refactor cookie caching
JeremyRand Oct 9, 2019
e6f163e
rpcclient: Try user+pass auth before cookie auth
JeremyRand Oct 9, 2019
6d521ff
rpcclient: Read first line of cookie instead of trimming space
JeremyRand Oct 10, 2019
714de3f
rpcclient: serialize nil inputs to empty list
torkelrogstad Apr 2, 2020
b11bf58
Improve chain state init efficiency
lindlof May 17, 2020
a383a71
Add blockchain.NewUtxoEntry() to directly create entries for UtxoView…
adiabat May 29, 2020
73d69f0
Add getchaintxstats JSON-RPC client command
lindlof May 11, 2020
e4f5902
Add fundrawtransaction RPC call
torkelrogstad Dec 2, 2019
7b2ff5d
Add getbalances RPC client command
federicobond Jun 18, 2020
e2d9cf4
rpcclient: Add GetTransactionWatchOnly method
onyb Jun 10, 2020
875b51c
peer: knownInventory, sentNonces - use generic lru
tuxcanfly Jul 3, 2020
d28c716
btcec: Avoid panic in fieldVal.SetByteSlice for large inputs
onyb Jul 9, 2020
c739023
config+service_windows: add flag to disable win service
guggero Jul 22, 2020
3c56a6b
updated docs for getblock-verbosity fixes
JettScythe Jul 21, 2020
69773a7
Update json_rpc_api.md
JettScythe Jul 21, 2020
24db7d7
netsync: handle notfound messages from peers
tuxcanfly Jul 10, 2020
1db1b6f
Merge pull request #1609 from guggero/disable-windows-service
Roasbeef Jul 30, 2020
4255e1e
release: update release script path
Rjected Jul 23, 2020
2a0d6fd
release: remove old scripts and update process doc
Rjected Jul 27, 2020
4527c56
Update CHANGES file for 0.21.0 release
onyb Aug 24, 2020
56cc42f
btcd: bump version to v0.21.0-beta
jcvernaleo Aug 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
btcec: Avoid panic in fieldVal.SetByteSlice for large inputs
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.
  • Loading branch information
onyb authored and jcvernaleo committed Jul 13, 2020
commit d28c7167a50d9224a53cae962f14ffa705554013
20 changes: 12 additions & 8 deletions btcec/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,24 @@ func (f *fieldVal) SetBytes(b *[32]byte) *fieldVal {
return f
}

// SetByteSlice packs the passed big-endian value into the internal field value
// representation. Only the first 32-bytes are used. As a result, it is up to
// the caller to ensure numbers of the appropriate size are used or the value
// will be truncated.
// SetByteSlice interprets the provided slice as a 256-bit big-endian unsigned
// integer (meaning it is truncated to the first 32 bytes), packs it into the
// internal field value representation, and returns the updated field value.
//
// Note that since passing a slice with more than 32 bytes is truncated, it is
// possible that the truncated value is less than the field prime. It is up to
// the caller to decide whether it needs to provide numbers of the appropriate
// size or if it is acceptable to use this function with the described
// truncation behavior.
//
// The field value is returned to support chaining. This enables syntax like:
// f := new(fieldVal).SetByteSlice(byteSlice)
func (f *fieldVal) SetByteSlice(b []byte) *fieldVal {
var b32 [32]byte
for i := 0; i < len(b); i++ {
if i < 32 {
b32[i+(32-len(b))] = b[i]
}
if len(b) > 32 {
b = b[:32]
}
copy(b32[32-len(b):], b)
return f.SetBytes(&b32)
}

Expand Down
154 changes: 154 additions & 0 deletions btcec/field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package btcec

import (
"crypto/rand"
"encoding/hex"
"fmt"
"reflect"
"testing"
Expand Down Expand Up @@ -965,3 +966,156 @@ func testSqrt(t *testing.T, test sqrtTest) {
}
}
}

// TestFieldSetBytes ensures that setting a field value to a 256-bit big-endian
// unsigned integer via both the slice and array methods works as expected for
// edge cases. Random cases are tested via the various other tests.
func TestFieldSetBytes(t *testing.T) {
tests := []struct {
name string // test description
in string // hex encoded test value
expected [10]uint32 // expected raw ints
}{{
name: "zero",
in: "00",
expected: [10]uint32{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}, {
name: "field prime",
in: "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
expected: [10]uint32{
0x03fffc2f, 0x03ffffbf, 0x03ffffff, 0x03ffffff, 0x03ffffff,
0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff, 0x003fffff,
},
}, {
name: "field prime - 1",
in: "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e",
expected: [10]uint32{
0x03fffc2e, 0x03ffffbf, 0x03ffffff, 0x03ffffff, 0x03ffffff,
0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff, 0x003fffff,
},
}, {
name: "field prime + 1 (overflow in word zero)",
in: "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30",
expected: [10]uint32{
0x03fffc30, 0x03ffffbf, 0x03ffffff, 0x03ffffff, 0x03ffffff,
0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff, 0x003fffff,
},
}, {
name: "field prime first 32 bits",
in: "fffffc2f",
expected: [10]uint32{
0x03fffc2f, 0x00000003f, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
},
}, {
name: "field prime word zero",
in: "03fffc2f",
expected: [10]uint32{
0x03fffc2f, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
},
}, {
name: "field prime first 64 bits",
in: "fffffffefffffc2f",
expected: [10]uint32{
0x03fffc2f, 0x03ffffbf, 0x00000fff, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
},
}, {
name: "field prime word zero and one",
in: "0ffffefffffc2f",
expected: [10]uint32{
0x03fffc2f, 0x03ffffbf, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
},
}, {
name: "field prime first 96 bits",
in: "fffffffffffffffefffffc2f",
expected: [10]uint32{
0x03fffc2f, 0x03ffffbf, 0x03ffffff, 0x0003ffff, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
},
}, {
name: "field prime word zero, one, and two",
in: "3ffffffffffefffffc2f",
expected: [10]uint32{
0x03fffc2f, 0x03ffffbf, 0x03ffffff, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
},
}, {
name: "overflow in word one (prime + 1<<26)",
in: "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff03fffc2f",
expected: [10]uint32{
0x03fffc2f, 0x03ffffc0, 0x03ffffff, 0x03ffffff, 0x03ffffff,
0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff, 0x003fffff,
},
}, {
name: "(field prime - 1) * 2 NOT mod P, truncated >32 bytes",
in: "01fffffffffffffffffffffffffffffffffffffffffffffffffffffffdfffff85c",
expected: [10]uint32{
0x01fffff8, 0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff,
0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff, 0x00007fff,
},
}, {
name: "2^256 - 1",
in: "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
expected: [10]uint32{
0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff,
0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff, 0x003fffff,
},
}, {
name: "alternating bits",
in: "a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5",
expected: [10]uint32{
0x01a5a5a5, 0x01696969, 0x025a5a5a, 0x02969696, 0x01a5a5a5,
0x01696969, 0x025a5a5a, 0x02969696, 0x01a5a5a5, 0x00296969,
},
}, {
name: "alternating bits 2",
in: "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a",
expected: [10]uint32{
0x025a5a5a, 0x02969696, 0x01a5a5a5, 0x01696969, 0x025a5a5a,
0x02969696, 0x01a5a5a5, 0x01696969, 0x025a5a5a, 0x00169696,
},
}}

for _, test := range tests {
inBytes := hexToBytes(test.in)

// Ensure setting the bytes via the slice method works as expected.
var f fieldVal
f.SetByteSlice(inBytes)
if !reflect.DeepEqual(f.n, test.expected) {
t.Errorf("%s: unexpected result\ngot: %x\nwant: %x", test.name, f.n,
test.expected)
continue
}

// Ensure setting the bytes via the array method works as expected.
var f2 fieldVal
var b32 [32]byte
truncatedInBytes := inBytes
if len(truncatedInBytes) > 32 {
truncatedInBytes = truncatedInBytes[:32]
}
copy(b32[32-len(truncatedInBytes):], truncatedInBytes)
f2.SetBytes(&b32)
if !reflect.DeepEqual(f2.n, test.expected) {
t.Errorf("%s: unexpected result\ngot: %x\nwant: %x", test.name,
f2.n, test.expected)
continue
}
}
}

// hexToBytes converts the passed hex string into bytes and will panic if there
// is an error. This is only provided for the hard-coded constants so errors in
// the source code can be detected. It will only (and must only) be called with
// hard-coded values.
func hexToBytes(s string) []byte {
b, err := hex.DecodeString(s)
if err != nil {
panic("invalid hex in source file: " + s)
}
return b
}