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

Thor chain #206

Closed
wants to merge 69 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
0629cff
style: make error handlings styke more consistent
0xmountaintop Nov 3, 2020
e0e4299
apply to eddsa
0xmountaintop Nov 3, 2020
94a2878
more consistent var name in mta.RangeProofAlice
0xmountaintop Nov 4, 2020
e033074
refactor crypto lib verification check
0xmountaintop Nov 4, 2020
fe3ce50
extra docs (#74)
notatestuser Nov 4, 2020
5e32707
Merge pull request #112 from HAOYUatHZ/patch-3
omershlo Nov 5, 2020
2f94201
Merge pull request #113 from HAOYUatHZ/ver
omershlo Nov 5, 2020
90dd2de
fix dlog proof potential security issue
ackratos Nov 7, 2020
9e4ab39
run go fmt check on push
ackratos Nov 7, 2020
92a2948
fix protect keygen/sign/reshare
ackratos Nov 10, 2020
cfed25c
fix test failure
ackratos Nov 13, 2020
0d6625b
tweak test timeout
ackratos Nov 13, 2020
a827813
Merge pull request #115 from binance-chain/dlog_smallgroup_8
omershlo Nov 13, 2020
b15a0cf
Merge remote-tracking branch 'upstream/master' into patch-2
0xmountaintop Nov 18, 2020
8060d05
fix typos (#119)
0xmountaintop Nov 19, 2020
e7030a5
S in eddsa signature is not encoded correctly
ackratos Dec 3, 2020
5de0327
Merge pull request #122 from binance-chain/eddsa_s
omershlo Dec 3, 2020
49366aa
fix R and S may not be 32 bytes (#130)
ackratos Apr 2, 2021
1aa0a75
cherry pick > curve as parameter (#137)
FitzLu Jul 6, 2021
1cfbd1c
gofmt
Aug 13, 2021
05b0624
Updated Google protobuf dependency and fixed type clash
PlamenHristov Aug 31, 2021
15e17db
Merge pull request #139 from binance-chain/curve_parameter
yycen Sep 9, 2021
38aea7a
Merge branch 'master' of github.com:binance-chain/tss-lib into bugfix…
PlamenHristov Sep 9, 2021
787c506
Merged from master and regenerated pb.go files
PlamenHristov Sep 9, 2021
7bba017
Fixed bad message naming.
PlamenHristov Sep 9, 2021
68de1bd
Last message name fix.
PlamenHristov Sep 9, 2021
dc233a9
Fixed bad signature.proto
PlamenHristov Sep 10, 2021
dda22a6
Merge pull request #141 from PlamenHristov/bugfix/protobuf-name-clash
yycen Sep 14, 2021
427dbfb
Check bitslen of NTildej
yycen Oct 14, 2021
de0b357
Merge branch 'binance-chain:master' into master
yycen Oct 14, 2021
76cfe7d
Check bitslen of received paillier key
yycen Oct 14, 2021
cf1d424
Merge branch 'master' of https://github.com/yycen/tss-lib
yycen Oct 15, 2021
27c1986
Add missing message source, and change error message
yycen Oct 18, 2021
73560da
Merge pull request #146 from yycen/master
yycen Oct 19, 2021
5371864
Bugfix for vss, check shareid when construct vss
yycen Oct 25, 2021
51e8026
Check duplicate of share_id in VSS
yycen Oct 26, 2021
d05815e
Fix format of feldman_vss.go with go fmt
yycen Oct 26, 2021
566d4c1
Update vss, checking duplicate of share_id
yycen Oct 26, 2021
c26beac
Merge pull request #149 from binance-chain/shareid-security
yycen Oct 27, 2021
a1dabf2
Check paillier ciphertext
yycen Nov 8, 2021
681ebad
Merge pull request #151 from binance-chain/paillier-check
yycen Nov 12, 2021
2718fca
Do not normalize IDs of Shamir's Secret Sharing
pdyraga Dec 8, 2021
cd95cee
Merge pull request #155 from keep-network/vss-normalize
yycen Dec 10, 2021
ec06b0a
Additional check when Ks mismatch in savedata and sortedID (#156)
yycen Dec 13, 2021
62459ad
Fix for ECDSA keygen test
yycen Dec 22, 2021
b5c733d
Fix ECDSA keygen round2 message store
yycen Dec 23, 2021
30c5ee4
Merge pull request #157 from binance-chain/ecdsa-key-test-fix
yycen Dec 29, 2021
c65c356
fix: rebrand (#173)
ackratos Apr 27, 2022
c0a1d4e
Add checks in dlnproof [TOB-BIN-8]
yycen May 17, 2022
d5a7e79
Merge pull request #180 from bnb-chain/dlnproof-check
yycen May 18, 2022
939df21
update README.md to match the new version
typestring Jun 8, 2022
a9f3554
Allow to stop pre-parameters generator with a context
pdyraga Aug 15, 2022
4f9f853
Increased duration delta to 1s in prepare_test.go
pdyraga Aug 15, 2022
2f5f2e4
Merge pull request #191 from keep-network/stop-now
yycen Aug 17, 2022
83efb63
Merge pull request #185 from typestring/update-readme
yycen Aug 17, 2022
bde1ac3
Add check in mta_proof (#205)
yycen Sep 1, 2022
cbfa6cf
Feature/hd cherry pick (#195)
plopezlpz Sep 9, 2022
14e70f2
Improve DLN proof verification performance for large signing groups (…
pdyraga Sep 23, 2022
bb6fb30
Fix Hash collision (#233)
yycen Mar 24, 2023
afbe264
Update SECURITY.md (#241)
ackratos May 10, 2023
3d95e54
ECDSA protocol security updates (#252)
yycen Aug 10, 2023
1a14f3a
Ecdsa proof session byte (#256)
ZhAnGeek Aug 23, 2023
ff989bf
Update tagged version hash encoding (#257)
yycen Aug 24, 2023
faf1884
Update module name to v2 (#262)
yycen Aug 26, 2023
fbb0ef7
use *common.SignatureData instead of common.SignatureData to fix issu…
asdfsx Sep 20, 2023
b8d526d
Update dependencies (#270)
yycen Sep 20, 2023
f3aad28
fixed nil pointer on String() method (#276)
olegfomenko Dec 3, 2023
409542e
Fix: update always round.ok (#282)
ZhAnGeek Dec 3, 2023
c76a1a5
Merge pull request #109 from HAOYUatHZ/patch-2
ZhAnGeek Jan 10, 2024
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
11 changes: 11 additions & 0 deletions .github/workflows/gofmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Go-fmt
on: push
jobs:
gofmt:
name: Go fmt project
runs-on: ubuntu-latest
steps:
- name: check out
uses: actions/checkout@v3
- name: go fmt project
uses: Jerome1337/[email protected]
30 changes: 16 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@ name: Go Test
on:
push:
branches:
- master
- release/*
- master
- release/*
pull_request:
branches:
- master
- master

jobs:
build:
name: Test
runs-on: macOS-latest
steps:

- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go
- name: Set up Go 1.20
uses: actions/setup-go@v3
with:
go-version: 1.20.3
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Get dependencies
run: go get -v -t -d ./...
- name: Clean dependencies
run: go clean --modcache

- name: Run Tests
run: make test_unit_race
- name: Get dependencies
run: go mod tidy

- name: Run Tests
run: make test_unit_race
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MODULE = github.com/binance-chain/tss-lib
MODULE = github.com/bnb-chain/tss-lib/v2
PACKAGES = $(shell go list ./... | grep -v '/vendor/')

all: protob test
Expand All @@ -8,7 +8,7 @@ all: protob test

protob:
@echo "--> Building Protocol Buffers"
@for protocol in message signature ecdsa-keygen ecdsa-signing ecdsa-resharing; do \
@for protocol in message signature ecdsa-keygen ecdsa-signing ecdsa-resharing eddsa-keygen eddsa-signing eddsa-resharing; do \
echo "Generating $$protocol.pb.go" ; \
protoc --go_out=. ./protob/$$protocol.proto ; \
done
Expand All @@ -22,12 +22,14 @@ build: protob
test_unit:
@echo "--> Running Unit Tests"
@echo "!!! WARNING: This will take a long time :)"
go test -timeout 20m $(PACKAGES)
go clean -testcache
go test -timeout 60m $(PACKAGES)

test_unit_race:
@echo "--> Running Unit Tests (with Race Detection)"
@echo "!!! WARNING: This will take a long time :)"
go test -timeout 30m -race $(PACKAGES)
go clean -testcache
go test -timeout 60m -race $(PACKAGES)

test:
make test_unit
Expand Down
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

[1]: https://img.shields.io/badge/license-MIT-blue.svg
[2]: LICENSE
[3]: https://godoc.org/github.com/binance-chain/tss-lib?status.svg
[4]: https://godoc.org/github.com/binance-chain/tss-lib
[5]: https://goreportcard.com/badge/github.com/binance-chain/tss-lib
[6]: https://goreportcard.com/report/github.com/binance-chain/tss-lib
[3]: https://godoc.org/github.com/bnb-chain/tss-lib?status.svg
[4]: https://godoc.org/github.com/bnb-chain/tss-lib
[5]: https://goreportcard.com/badge/github.com/bnb-chain/tss-lib
[6]: https://goreportcard.com/report/github.com/bnb-chain/tss-lib

Permissively MIT Licensed.

Expand Down Expand Up @@ -43,12 +43,6 @@ The `LocalParty` that you use should be from the `keygen`, `signing` or `reshari

### Setup
```go
// Set up elliptic curve
// use ECDSA, which is used by default
tss.SetCurve(s256k1.S256())
// or use EdDSA
// tss.SetCurve(edwards.Edwards())

// When using the keygen party it is recommended that you pre-compute the "safe primes" and Paillier secret beforehand because this can take some time.
// This code will generate those parameters using a concurrency limit equal to the number of available CPU cores.
preParams, _ := keygen.GeneratePreParams(1 * time.Minute)
Expand All @@ -62,7 +56,14 @@ parties := tss.SortPartyIDs(getParticipantPartyIDs())
// The `uniqueKey` is a unique identifying key for this peer (such as its p2p public key) as a big.Int.
thisParty := tss.NewPartyID(id, moniker, uniqueKey)
ctx := tss.NewPeerContext(parties)
params := tss.NewParameters(ctx, thisParty, len(parties), threshold)

// Select an elliptic curve
// use ECDSA
curve := tss.S256()
// or use EdDSA
// curve := tss.Edwards()

params := tss.NewParameters(curve, ctx, thisParty, len(parties), threshold)

// You should keep a local mapping of `id` strings to `*PartyID` instances so that an incoming message can have its origin party's `*PartyID` recovered for passing to `UpdateFromBytes` (see below)
partyIDMap := make(map[string]*PartyID)
Expand Down Expand Up @@ -135,6 +136,10 @@ In a typical use case, it is expected that a transport implementation will consu

This way there is no need to deal with Marshal/Unmarshalling Protocol Buffers to implement a transport.

## Changes of Preparams of ECDSA in v2.0

Two fields PaillierSK.P and PaillierSK.Q is added in version 2.0. They are used to generate Paillier key proofs. Key valuts generated from versions before 2.0 need to regenerate(resharing) the key valuts to update the praparams with the necessary fileds filled.

## How to use this securely

⚠️ This section is important. Be sure to read it!
Expand All @@ -150,7 +155,7 @@ Additionally, there should be a mechanism in your transport to allow for "reliab
Timeouts and errors should be handled by your application. The method `WaitingFor` may be called on a `Party` to get the set of other parties that it is still waiting for messages from. You may also get the set of culprit parties that caused an error from a `*tss.Error`.

## Security Audit
A full review of this library was carried out by Kudelski Security and their final report was made available in October, 2019. A copy of this report [`audit-binance-tss-lib-final-20191018.pdf`](https://github.com/binance-chain/tss-lib/releases/download/v1.0.0/audit-binance-tss-lib-final-20191018.pdf) may be found in the v1.0.0 release notes of this repository.
A full review of this library was carried out by Kudelski Security and their final report was made available in October, 2019. A copy of this report [`audit-binance-tss-lib-final-20191018.pdf`](https://github.com/bnb-chain/tss-lib/releases/download/v1.0.0/audit-binance-tss-lib-final-20191018.pdf) may be found in the v1.0.0 release notes of this repository.

## References
\[1\] https://eprint.iacr.org/2019/114.pdf
Expand Down
11 changes: 11 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Security Policy

## Reporting a Bug or Vulnerability

For non-security problems please open an issue in this GitHub repository.

If you find any security issues please send a report confidentially to https://bugcrowd.com/binance.

Please include notes about the impact of the issue and a walkthrough on how it can be exploited.

For severe security issues that completely breach the safety of the scheme or leak the secret shares we would be happy to reward you with a bounty based on the security impact and severity. Please include a link to this notice in your email.
60 changes: 58 additions & 2 deletions common/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ func SHA512_256(in ...[]byte) []byte {
for _, bz := range in {
bzSize += len(bz)
}
data = make([]byte, 0, len(inLenBz)+bzSize+inLen)
dataCap := len(inLenBz) + bzSize + inLen + (inLen * 8)
data = make([]byte, 0, dataCap)
data = append(data, inLenBz...)
for _, bz := range in {
data = append(data, bz...)
data = append(data, hashInputDelimiter) // safety delimiter
dataLen := make([]byte, 8) // 64-bits
binary.LittleEndian.PutUint64(dataLen, uint64(len(bz)))
data = append(data, dataLen...) // Security audit: length of each byte buffer should be added after
// each security delimiters in order to enforce proper domain separation
}
// n < len(data) or an error will never happen.
// see: https://golang.org/pkg/hash/#Hash and https://github.com/golang/go/wiki/Hashing#the-hashhash-interface
Expand Down Expand Up @@ -68,11 +73,16 @@ func SHA512_256i(in ...*big.Int) *big.Int {
ptrs[i] = n.Bytes()
bzSize += len(ptrs[i])
}
data = make([]byte, 0, len(inLenBz)+bzSize+inLen)
dataCap := len(inLenBz) + bzSize + inLen + (inLen * 8)
data = make([]byte, 0, dataCap)
data = append(data, inLenBz...)
for i := range in {
data = append(data, ptrs[i]...)
data = append(data, hashInputDelimiter) // safety delimiter
dataLen := make([]byte, 8) // 64-bits
binary.LittleEndian.PutUint64(dataLen, uint64(len(ptrs[i])))
data = append(data, dataLen...) // Security audit: length of each byte buffer should be added after
// each security delimiters in order to enforce proper domain separation
}
// n < len(data) or an error will never happen.
// see: https://golang.org/pkg/hash/#Hash and https://github.com/golang/go/wiki/Hashing#the-hashhash-interface
Expand All @@ -83,6 +93,52 @@ func SHA512_256i(in ...*big.Int) *big.Int {
return new(big.Int).SetBytes(state.Sum(nil))
}

// SHA512_256i_TAGGED tagged version of SHA512_256i
func SHA512_256i_TAGGED(tag []byte, in ...*big.Int) *big.Int {
tagBz := SHA512_256(tag)
var data []byte
state := crypto.SHA512_256.New()
state.Write(tagBz)
state.Write(tagBz)
inLen := len(in)
if inLen == 0 {
return nil
}
bzSize := 0
// prevent hash collisions with this prefix containing the block count
inLenBz := make([]byte, 64/8)
// converting between int and uint64 doesn't change the sign bit, but it may be interpreted as a larger value.
// this prefix is never read/interpreted, so that doesn't matter.
binary.LittleEndian.PutUint64(inLenBz, uint64(inLen))
ptrs := make([][]byte, inLen)
for i, n := range in {
if n == nil {
ptrs[i] = zero.Bytes()
} else {
ptrs[i] = n.Bytes()
}
bzSize += len(ptrs[i])
}
dataCap := len(inLenBz) + bzSize + inLen + (inLen * 8)
data = make([]byte, 0, dataCap)
data = append(data, inLenBz...)
for i := range in {
data = append(data, ptrs[i]...)
data = append(data, hashInputDelimiter) // safety delimiter
dataLen := make([]byte, 8) // 64-bits
binary.LittleEndian.PutUint64(dataLen, uint64(len(ptrs[i])))
data = append(data, dataLen...) // Security audit: length of each byte buffer should be added after
// each security delimiters in order to enforce proper domain separation
}
// n < len(data) or an error will never happen.
// see: https://golang.org/pkg/hash/#Hash and https://github.com/golang/go/wiki/Hashing#the-hashhash-interface
if _, err := state.Write(data); err != nil {
Logger.Error(err)
return nil
}
return new(big.Int).SetBytes(state.Sum(nil))
}

func SHA512_256iOne(in *big.Int) *big.Int {
var data []byte
state := crypto.SHA512_256.New()
Expand Down
2 changes: 1 addition & 1 deletion common/hash_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"reflect"
"testing"

"github.com/binance-chain/tss-lib/common"
"github.com/bnb-chain/tss-lib/v2/common"
)

func TestRejectionSample(t *testing.T) {
Expand Down
11 changes: 11 additions & 0 deletions common/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,14 @@ func (mi *modInt) ModInverse(g *big.Int) *big.Int {
func (mi *modInt) i() *big.Int {
return (*big.Int)(mi)
}

func IsInInterval(b *big.Int, bound *big.Int) bool {
return b.Cmp(bound) == -1 && b.Cmp(zero) >= 0
}

func AppendBigIntToBytesSlice(commonBytes []byte, appended *big.Int) []byte {
resultBytes := make([]byte, len(commonBytes), len(commonBytes)+len(appended.Bytes()))
copy(resultBytes, commonBytes)
resultBytes = append(resultBytes, appended.Bytes()...)
return resultBytes
}
31 changes: 29 additions & 2 deletions common/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,38 @@ func IsNumberInMultiplicativeGroup(n, v *big.Int) bool {
gcd.GCD(nil, nil, v, n).Cmp(one) == 0
}

// Return a random generator of RQn with high probability.
// THIS METHOD ONLY WORKS IF N IS THE PRODUCT OF TWO SAFE PRIMES!
// Return a random generator of RQn with high probability.
// THIS METHOD ONLY WORKS IF N IS THE PRODUCT OF TWO SAFE PRIMES!
//
// https://github.com/didiercrunch/paillier/blob/d03e8850a8e4c53d04e8016a2ce8762af3278b71/utils.go#L39
func GetRandomGeneratorOfTheQuadraticResidue(n *big.Int) *big.Int {
f := GetRandomPositiveRelativelyPrimeInt(n)
fSq := new(big.Int).Mul(f, f)
return fSq.Mod(fSq, n)
}

// GetRandomQuadraticNonResidue returns a quadratic non residue of odd n.
func GetRandomQuadraticNonResidue(n *big.Int) *big.Int {
for {
w := GetRandomPositiveInt(n)
if big.Jacobi(w, n) == -1 {
return w
}
}
}

// GetRandomBytes returns random bytes of length.
func GetRandomBytes(length int) ([]byte, error) {
// Per [BIP32], the seed must be in range [MinSeedBytes, MaxSeedBytes].
if length <= 0 {
return nil, errors.New("invalid length")
}

buf := make([]byte, length)
_, err := rand.Read(buf)
if err != nil {
return nil, err
}

return buf, nil
}
2 changes: 1 addition & 1 deletion common/random_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/binance-chain/tss-lib/common"
"github.com/bnb-chain/tss-lib/v2/common"
)

const (
Expand Down
Loading