Skip to content

Commit

Permalink
Remove threshold check
Browse files Browse the repository at this point in the history
  • Loading branch information
abread committed Sep 26, 2022
1 parent 78dd9ca commit f74809f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
7 changes: 2 additions & 5 deletions pkg/threshcrypto/pseudo.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func pseudorandomStream(seed int64) cipher.Stream {
// Intended for testing purposes and assuming a static membership known to all nodes,
// NodePseudo can be invoked by each Node independently (specifying the same seed, e.g. DefaultPseudoSeed)
// and generates the same set of keys for the whole system at each node, obviating the exchange of public keys.
func TBLSPseudo(nodes []t.NodeID, nByz, threshold int, ownID t.NodeID, seed int64) (ThreshCrypto, error) {
func TBLSPseudo(nodes []t.NodeID, threshold int, ownID t.NodeID, seed int64) (ThreshCrypto, error) {
// Create a new pseudorandom source from the given seed.
randomness := pseudorandomStream(seed)

Expand All @@ -38,10 +38,7 @@ func TBLSPseudo(nodes []t.NodeID, nByz, threshold int, ownID t.NodeID, seed int6
return nil, fmt.Errorf("own node ID not in node list")
}

tcInstances, err := TBLS12381Keygen(nByz, threshold, nodes, randomness)
if err != nil {
return nil, err
}
tcInstances := TBLS12381Keygen(threshold, nodes, randomness)

return tcInstances[idx], nil
}
7 changes: 2 additions & 5 deletions pkg/threshcrypto/tbls.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ func tbls12381Scheme() (pairing.Suite, sign.ThresholdScheme, kyber.Group, kyber.
// TBLS12381Keygen constructs a set TBLSInst for a given set of member nodes and threshold T
// with nByz byzantine nodes, using the BLS12-381 pairing, with signatures being points on curve G1,
// and keys points on curve G2.
func TBLS12381Keygen(nByz, T int, members []t.NodeID, randSource cipher.Stream) ([]*TBLSInst, error) {
func TBLS12381Keygen(T int, members []t.NodeID, randSource cipher.Stream) []*TBLSInst {
N := len(members)
if !(nByz < (N+1)/2 && nByz >= 0 && T > nByz) {
return nil, fmt.Errorf("(T, N)-threshold BLS requires 0 <= nByz < N/2, and T > nByz, where nByz is the number of byzantine participants")
}

pairing, scheme, sigGroup, keyGroup := tbls12381Scheme()

Expand All @@ -74,7 +71,7 @@ func TBLS12381Keygen(nByz, T int, members []t.NodeID, randSource cipher.Stream)
}
}

return instances, nil
return instances
}

// MarshalTo writes the properties of a TBLSInst to an io.Writer.
Expand Down
15 changes: 6 additions & 9 deletions pkg/threshcrypto/tbls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ func TestTBLSHappySmoke(t *testing.T) {
N := 5
T := 3

keys, err := keygen(T-1, T, N)
assert.NoError(t, err)
keys := keygen(T-1, T, N)

data := [][]byte{{1, 2, 3, 4, 5}, {4, 2}}

Expand Down Expand Up @@ -52,8 +51,7 @@ func TestTBLSSadSmoke(t *testing.T) {
N := 5
T := 3

keys, err := keygen(T-1, T, N)
require.NoError(t, err)
keys := keygen(T-1, T, N)

data := [][]byte{{1, 2, 3, 4, 5}, {4, 2}}

Expand All @@ -66,7 +64,7 @@ func TestTBLSSadSmoke(t *testing.T) {
}

// all of the same share is no good
_, err = keys[0].Recover(data, [][]byte{shares[0], shares[0], shares[0]})
_, err := keys[0].Recover(data, [][]byte{shares[0], shares[0], shares[0]})
assert.Error(t, err)

// too little shares is no good
Expand All @@ -87,8 +85,7 @@ func TestTBLSMarshalling(t *testing.T) {
T := N
nByz := (N+1)/2 - 1

keys, err := keygen(nByz, T, N)
require.NoError(t, err)
keys := keygen(nByz, T, N)

keys2 := marshalUnmarshalKeys(t, keys)

Expand Down Expand Up @@ -118,14 +115,14 @@ func TestTBLSMarshalling(t *testing.T) {
}
}

func keygen(nByz, T, N int) ([]*TBLSInst, error) {
func keygen(nByz, T, N int) []*TBLSInst {
members := make([]types.NodeID, N)
for i := range members {
members[i] = types.NewNodeIDFromInt(i)
}

rand := pseudorandomStream(DefaultPseudoSeed)
return TBLS12381Keygen(nByz, T, members, rand)
return TBLS12381Keygen(T, members, rand)
}

func marshalUnmarshalKeys(t *testing.T, src []*TBLSInst) []*TBLSInst {
Expand Down

0 comments on commit f74809f

Please sign in to comment.