Skip to content

Commit

Permalink
Merge pull request #101 from line/feature/signature_aggregation
Browse files Browse the repository at this point in the history
Introduce composite key to delegate features to each function key
  • Loading branch information
torao authored Aug 17, 2020
2 parents 9a75993 + c6e66bc commit 40a2944
Show file tree
Hide file tree
Showing 62 changed files with 991 additions and 194 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
name: run localnet and exit on failure
command: |
set -x
docker run --rm -v "$PWD":/go/src/github.com/tendermint/tendermint -w /go/src/github.com/tendermint/tendermint golang:1.14.1-alpine /bin/sh -c "apk add --update git make gcc libc-dev build-base && make build"
make build-linux
make localnet-start &
./scripts/localnet-blocks-test.sh 40 5 10 localhost
Expand Down Expand Up @@ -370,7 +370,7 @@ jobs:
./scripts/get_nodejs.sh
# build the binaries with a proper version of Go
# Build Tendermint
docker run --rm -v "$PWD":/go/src/github.com/tendermint/tendermint -w /go/src/github.com/tendermint/tendermint golang:1.14.1-alpine /bin/sh -c "apk add --update git make gcc libc-dev build-base && make build"
make build-linux
# Build contract-tests
docker run --rm -v "$PWD":/go/src/github.com/tendermint/tendermint -w /go/src/github.com/tendermint/tendermint ubuntu:20.10 ./scripts/prepare_dredd_test.sh
# This docker image works with go 1.7, we can install here the hook handler that contract-tests is going to use
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- uses: actions/cache@v1
with:
path: ~/go/bin
key: ${{ runner.os }}-go-tm-binary
key: ${{ runner.os }}-go-tm-binary-${{ hashFiles('**/*.go', '**/go.sum', 'Makefile') }}

test_abci_apps:
runs-on: ubuntu-latest
Expand All @@ -43,7 +43,7 @@ jobs:
- uses: actions/cache@v1
with:
path: ~/go/bin
key: ${{ runner.os }}-go-tm-binary
key: ${{ runner.os }}-go-tm-binary-${{ hashFiles('**/*.go', '**/go.sum', 'Makefile') }}
- name: test_abci_apps
run: abci/tests/test_app/test.sh
shell: bash
Expand All @@ -60,7 +60,7 @@ jobs:
- uses: actions/cache@v1
with:
path: ~/go/bin
key: ${{ runner.os }}-go-tm-binary
key: ${{ runner.os }}-go-tm-binary-${{ hashFiles('**/*.go', '**/go.sum', 'Makefile') }}
- run: abci/tests/test_cli/test.sh
shell: bash

Expand All @@ -76,7 +76,7 @@ jobs:
- uses: actions/cache@v1
with:
path: ~/go/bin
key: ${{ runner.os }}-go-tm-binary
key: ${{ runner.os }}-go-tm-binary-${{ hashFiles('**/*.go', '**/go.sum', 'Makefile') }}
- name: test_apps
run: test/app/test.sh
shell: bash
3 changes: 2 additions & 1 deletion CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
- Apps

- P2P Protocol

- Go API

- Blockchain Protocol
- [consensus] [\#101](https:/line/tendermint/pull/101) Introduce composite key to delegate features to each function key

### FEATURES:

Expand Down
35 changes: 34 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,42 @@ build-docker:
### Local testnet using docker ###
###############################################################################

DOCKER_HOME = /go/src/github.com/tendermint/tendermint
DOCKER_CMD = docker run --rm \
-v `pwd`:$(DOCKER_HOME) \
-w $(DOCKER_HOME)
DOCKER_IMG = golang:1.14.6-alpine3.12
BUILD_CMD = apk add --update --no-cache git make gcc libc-dev build-base curl jq file gmp-dev clang \
&& cd crypto/bls/internal/bls-eth-go-binary \
&& make CXX=clang++ \
&& cd $(DOCKER_HOME) \
&& go mod edit -replace github.com/herumi/bls-eth-go-binary=./crypto/bls/internal/bls-eth-go-binary \
&& make build \
&& go mod edit -dropreplace github.com/herumi/bls-eth-go-binary

# Login docker-container for confirmation building linux binary
build-shell:
$(DOCKER_CMD) -it --entrypoint '' ${DOCKER_IMG} /bin/sh
.PHONY: build-shell

# Build linux binary on other platforms

build-linux:
docker run --rm -v `pwd`:/go/src/github.com/tendermint/tendermint -w /go/src/github.com/tendermint/tendermint golang:1.14.1-alpine /bin/sh -c "apk add --update git make gcc libc-dev build-base && make build"
# Download, build and add the BSL local library to modules
if [ ! -d $(SRCPATH)/crypto/bls/internal/bls-eth-go-binary ]; then \
mkdir -p $(SRCPATH)/crypto/bls/internal && \
git clone https:/herumi/mcl $(SRCPATH)/crypto/bls/internal/mcl && \
git clone https:/herumi/bls $(SRCPATH)/crypto/bls/internal/bls && \
git clone https:/herumi/bls-eth-go-binary $(SRCPATH)/crypto/bls/internal/bls-eth-go-binary; \
fi

# Build Linux binary
$(DOCKER_CMD) ${DOCKER_IMG} /bin/sh -c "$(BUILD_CMD)"

# Remove the BLS local library from modules
rm -rf $(SRCPATH)/crypto/bls/internal/mcl
rm -rf $(SRCPATH)/crypto/bls/internal/bls
rm -rf $(SRCPATH)/crypto/bls/internal/bls-eth-go-binary
.PHONY: build-linux

build-docker-localnode:
Expand Down
13 changes: 11 additions & 2 deletions abci/example/kvstore/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ package kvstore

import (
"github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/composite"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmtypes "github.com/tendermint/tendermint/types"
)

// Generates a default private key for use in an example or test.
func GenDefaultPrivKey() crypto.PrivKey {
return composite.GenPrivKey()
}

// RandVal creates one random validator, with a key derived
// from the input value
func RandVal(i int) types.ValidatorUpdate {
pubkey := tmrand.Bytes(32)
pk := GenDefaultPrivKey().PubKey()
pubkey := tmtypes.TM2PB.PubKey(pk)
power := tmrand.Uint16() + 1
v := types.Ed25519ValidatorUpdate(pubkey, int64(power))
v := types.NewValidatorUpdate(tmtypes.ABCIPubKeyTypeComposite, pubkey.Data, int64(power))
return v
}

Expand Down
12 changes: 8 additions & 4 deletions abci/example/kvstore/persistent_kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/tendermint/tendermint/abci/example/code"
"github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/libs/log"
tmtypes "github.com/tendermint/tendermint/types"
)
Expand Down Expand Up @@ -205,15 +204,20 @@ func (app *PersistentKVStoreApplication) execValidatorTx(tx []byte) types.Respon
}

// update
return app.updateValidator(types.Ed25519ValidatorUpdate(pubkey, power))
// TODO The type of public key to be restored should be kept its original type.
return app.updateValidator(types.NewValidatorUpdate(tmtypes.ABCIPubKeyTypeComposite, pubkey, power))
}

// add, update, or remove a validator
func (app *PersistentKVStoreApplication) updateValidator(v types.ValidatorUpdate) types.ResponseDeliverTx {
key := []byte("val:" + string(v.PubKey.Data))

pubkey := ed25519.PubKeyEd25519{}
copy(pubkey[:], v.PubKey.Data)
pubkey, err := tmtypes.PB2TM.PubKey(v.PubKey)
if err != nil {
return types.ResponseDeliverTx{
Code: code.CodeTypeEncodingError,
Log: fmt.Sprintf("Error encoding validator: %v", err)}
}

if v.Power == 0 {
// remove validator
Expand Down
7 changes: 5 additions & 2 deletions abci/tests/server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import (
"fmt"

abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/example/kvstore"
"github.com/tendermint/tendermint/abci/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmtypes "github.com/tendermint/tendermint/types"
)

func InitChain(client abcicli.Client) error {
total := 10
vals := make([]types.ValidatorUpdate, total)
for i := 0; i < total; i++ {
pubkey := tmrand.Bytes(33)
pk := kvstore.GenDefaultPrivKey().PubKey()
pubkey := tmtypes.TM2PB.PubKey(pk).Data
power := tmrand.Int()
vals[i] = types.Ed25519ValidatorUpdate(pubkey, int64(power))
vals[i] = types.NewValidatorUpdate(tmtypes.ABCIPubKeyTypeComposite, pubkey, int64(power))
}
_, err := client.InitChainSync(types.RequestInitChain{
Validators: vals,
Expand Down
8 changes: 6 additions & 2 deletions abci/types/pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ const (
PubKeyEd25519 = "ed25519"
)

func Ed25519ValidatorUpdate(pubkey []byte, power int64) ValidatorUpdate {
func NewValidatorUpdate(keyType string, pubkey []byte, power int64) ValidatorUpdate {
return ValidatorUpdate{
// Address:
PubKey: PubKey{
Type: PubKeyEd25519,
Type: keyType,
Data: pubkey,
},
Power: power,
}
}

func Ed25519ValidatorUpdate(pubkey []byte, power int64) ValidatorUpdate {
return NewValidatorUpdate(PubKeyEd25519, pubkey, power)
}
4 changes: 2 additions & 2 deletions cmd/contract_tests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"strings"

"github.com/tendermint/tendermint/cmd/contract_tests/unmarshaler"

"github.com/snikch/goodman/hooks"
"github.com/snikch/goodman/transaction"

"github.com/tendermint/tendermint/cmd/contract_tests/unmarshaler"
)

func main() {
Expand Down
5 changes: 3 additions & 2 deletions consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/go-kit/kit/log/term"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"

dbm "github.com/tendermint/tm-db"

abcicli "github.com/tendermint/tendermint/abci/client"
Expand All @@ -27,7 +28,6 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
cfg "github.com/tendermint/tendermint/config"
cstypes "github.com/tendermint/tendermint/consensus/types"
"github.com/tendermint/tendermint/crypto/vrf"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
Expand Down Expand Up @@ -495,7 +495,8 @@ func forceProposer(cs *State, vals []*validatorStub, index []int, height []int64
if j+1 < len(height) && height[j+1] > height[j] {
message := types.MakeRoundHash(currentHash, height[j]-1, round[j])
proof, _ := curVal.PrivValidator.GenerateVRFProof(message)
currentHash, _ = vrf.ProofToHash(proof)
pubKey, _ := curVal.PrivValidator.GetPubKey()
currentHash, _ = pubKey.VRFVerify(proof, message)
}
}
if allMatch {
Expand Down
25 changes: 23 additions & 2 deletions crypto/bls/bls.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ func GenPrivKey() PrivKeyBLS12 {
sigKey := bls.SecretKey{}
sigKey.SetByCSPRNG()
sigKeyBinary := PrivKeyBLS12{}
copy(sigKeyBinary[:], sigKey.Serialize())
binary := sigKey.Serialize()
if len(binary) != PrivKeyBLS12Size {
panic(fmt.Sprintf("unexpected BLS private key size: %d != %d", len(binary), PrivKeyBLS12Size))
}
copy(sigKeyBinary[:], binary)
return sigKeyBinary
}

Expand All @@ -62,6 +66,9 @@ func (privKey PrivKeyBLS12) Bytes() []byte {

// Sign produces a signature on the provided message.
func (privKey PrivKeyBLS12) Sign(msg []byte) ([]byte, error) {
if msg == nil {
panic(fmt.Sprintf("Nil specified as the message"))
}
blsKey := bls.SecretKey{}
err := blsKey.Deserialize(privKey[:])
if err != nil {
Expand All @@ -71,6 +78,11 @@ func (privKey PrivKeyBLS12) Sign(msg []byte) ([]byte, error) {
return sign.Serialize(), nil
}

// VRFProve is not supported in BLS12.
func (privKey PrivKeyBLS12) VRFProve(seed []byte) (crypto.Proof, error) {
return nil, fmt.Errorf("VRF prove is not supported by the BLS12")
}

// PubKey gets the corresponding public key from the private key.
func (privKey PrivKeyBLS12) PubKey() crypto.PubKey {
blsKey := bls.SecretKey{}
Expand All @@ -80,7 +92,11 @@ func (privKey PrivKeyBLS12) PubKey() crypto.PubKey {
}
pubKey := blsKey.GetPublicKey()
pubKeyBinary := PubKeyBLS12{}
copy(pubKeyBinary[:], pubKey.Serialize())
binary := pubKey.Serialize()
if len(binary) != PubKeyBLS12Size {
panic(fmt.Sprintf("unexpected BLS public key size: %d != %d", len(binary), PubKeyBLS12Size))
}
copy(pubKeyBinary[:], binary)
return pubKeyBinary
}

Expand Down Expand Up @@ -130,6 +146,11 @@ func (pubKey PubKeyBLS12) VerifyBytes(msg []byte, sig []byte) bool {
return blsSign.VerifyByte(&blsPubKey, msg)
}

// VRFVerify is not supported in BLS12.
func (pubKey PubKeyBLS12) VRFVerify(proof crypto.Proof, seed []byte) (crypto.Output, error) {
return nil, fmt.Errorf("VRF verify is not supported by the BLS12")
}

func (pubKey PubKeyBLS12) String() string {
return fmt.Sprintf("PubKeyBLS12{%X}", pubKey[:])
}
Expand Down
Loading

0 comments on commit 40a2944

Please sign in to comment.