forked from autonity/autonity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix genesis committee With more validators configured in the genesis file the resulting committee was inconsistent. Signed-off-by: Youssef Azzaoui <[email protected]> * Large scale internal testing Signed-off-by: Youssef Azzaoui <[email protected]> * Add concurrency when updating consensus enode * Fix potential panic in fault detector * Rework consensus message handling flow * Large network e2e tests improvements * Add verifypop command to ethkey * Review comments * AutInspect ethkey command --------- Signed-off-by: Youssef Azzaoui <[email protected]> Signed-off-by: Youssef Azzaoui <[email protected]>
- Loading branch information
Showing
19 changed files
with
1,053 additions
and
622 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
|
||
"gopkg.in/urfave/cli.v1" | ||
|
||
"github.com/autonity/autonity/cmd/utils" | ||
"github.com/autonity/autonity/common/hexutil" | ||
"github.com/autonity/autonity/crypto" | ||
) | ||
|
||
type outputAutInspect struct { | ||
NodePublicKey string | ||
NodeAddress string | ||
NodePrivateKey string `json:",omitempty"` | ||
ConsensusPublicKey string | ||
ConsensusPrivateKey string `json:",omitempty"` | ||
} | ||
|
||
var commandAutInspect = cli.Command{ | ||
Name: "autinspect", | ||
Usage: "inspect autonity keys file", | ||
ArgsUsage: "<keyfile>", | ||
Description: ` | ||
Print various information about the autonity keyfile. | ||
Private key information can be printed by using the --private flag; | ||
make sure to use this feature with great caution!`, | ||
Flags: []cli.Flag{ | ||
jsonFlag, | ||
cli.BoolFlag{ | ||
Name: "private", | ||
Usage: "include the private keys in the output", | ||
}, | ||
}, | ||
Action: func(ctx *cli.Context) error { | ||
if ctx.NArg() != 1 { | ||
fmt.Println("Incorrect number of arguments, 1 expected.") | ||
cli.ShowCommandHelpAndExit(ctx, "autinspect", 1) | ||
} | ||
nodeKey, consensusKey, err := crypto.LoadAutonityKeys(ctx.Args().Get(0)) | ||
if err != nil { | ||
utils.Fatalf("error opening key file %v", err) | ||
} | ||
out := outputAutInspect{ | ||
NodePublicKey: hexutil.Encode(crypto.FromECDSAPub(&nodeKey.PublicKey)[1:]), | ||
NodeAddress: crypto.PubkeyToAddress(nodeKey.PublicKey).String(), | ||
ConsensusPublicKey: consensusKey.PublicKey().Hex(), | ||
} | ||
showPrivate := ctx.Bool("private") | ||
if showPrivate { | ||
out.ConsensusPrivateKey = hex.EncodeToString(consensusKey.Marshal()) | ||
out.NodePrivateKey = hex.EncodeToString(crypto.FromECDSA(nodeKey)) | ||
} | ||
if ctx.Bool(jsonFlag.Name) { | ||
mustPrintJSON(out) | ||
} else { | ||
fmt.Println("Node Address: ", out.NodeAddress) | ||
fmt.Println("Node Public Key: ", out.NodePublicKey) | ||
fmt.Println("Consensus Public Key: ", out.ConsensusPublicKey) | ||
if showPrivate { | ||
fmt.Println("Consensus Private Key: ", out.ConsensusPrivateKey) | ||
fmt.Println("Node Private Key: ", out.NodePrivateKey) | ||
} | ||
} | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gopkg.in/urfave/cli.v1" | ||
|
||
"github.com/autonity/autonity/accounts" | ||
"github.com/autonity/autonity/cmd/utils" | ||
"github.com/autonity/autonity/common" | ||
"github.com/autonity/autonity/common/hexutil" | ||
"github.com/autonity/autonity/crypto" | ||
"github.com/autonity/autonity/crypto/blst" | ||
enodes "github.com/autonity/autonity/p2p/enode" | ||
) | ||
|
||
type outputVerifyPOP struct { | ||
NodeKeyPOP bool | ||
OracleKeyPOP bool | ||
ConsensusKeyPOP bool | ||
} | ||
|
||
var commandVerifyPOP = cli.Command{ | ||
Name: "verifypop", | ||
Usage: "verify proof of possessions", | ||
ArgsUsage: "<treasury> <enode> <oracle> <consensusKey> <proof>", | ||
Description: ` | ||
Print if the proof of possession for registering a validator is valid or not. Use --json for a json output.`, | ||
Flags: []cli.Flag{ | ||
jsonFlag, | ||
}, | ||
Action: func(ctx *cli.Context) error { | ||
// Checks arguments BEGIN | ||
if ctx.NArg() != 5 { | ||
fmt.Println("Incorrect number of arguments, 5 expected.") | ||
cli.ShowCommandHelpAndExit(ctx, "verifypop", 1) | ||
} | ||
treasuryArg := ctx.Args().Get(0) | ||
treasuryKey, err := hexutil.Decode(treasuryArg) | ||
if err != nil { | ||
utils.Fatalf("can't decode treasury key with error %v", err) | ||
} | ||
|
||
enodeArg := ctx.Args().Get(1) | ||
node, err := enodes.ParseV4NoResolve(enodeArg) | ||
if err != nil { | ||
utils.Fatalf("can't parse enode %v", err) | ||
} | ||
oracleArg := ctx.Args().Get(2) | ||
oracleKey, err := hexutil.Decode(oracleArg) | ||
if err != nil { | ||
utils.Fatalf("can't decode oracle key with error %v", err) | ||
} | ||
|
||
consensusKeyArg := ctx.Args().Get(3) | ||
consensusKey, err := hexutil.Decode(consensusKeyArg) | ||
if err != nil { | ||
utils.Fatalf("can't decode consensus key with error %v", err) | ||
} | ||
|
||
signaturesArg := ctx.Args().Get(4) | ||
signatures, err := hexutil.Decode(signaturesArg) | ||
if err != nil { | ||
utils.Fatalf("can't decode proof with error %v", err) | ||
} | ||
if len(signatures) != crypto.AutonityPOPLen { | ||
utils.Fatalf("invalid proof size") | ||
} | ||
// Checks arguments END | ||
out := outputVerifyPOP{ | ||
NodeKeyPOP: false, | ||
OracleKeyPOP: false, | ||
ConsensusKeyPOP: false, | ||
} | ||
// compute the hash (the signed message) | ||
hash, _ := accounts.TextAndHash(treasuryKey) | ||
// | ||
// Step 1: node key pop | ||
// | ||
recoveredNodeKey, err := crypto.SigToPub(hash, signatures[:crypto.SignatureLength]) | ||
if err != nil { | ||
utils.Fatalf("can't recover node key %v", err) | ||
} | ||
out.NodeKeyPOP = recoveredNodeKey.Equal(node.Pubkey()) | ||
// | ||
// Step 2: oracle key pop | ||
// | ||
recoveredOracleAddress, err := crypto.SigToAddr(hash, signatures[crypto.SignatureLength:2*crypto.SignatureLength]) | ||
if err != nil { | ||
utils.Fatalf("can't recover oracle key %v", err) | ||
} | ||
out.OracleKeyPOP = recoveredOracleAddress == common.BytesToAddress(oracleKey) | ||
|
||
// | ||
// Step 3: consensus\ key pop | ||
// | ||
key, err := blst.PublicKeyFromBytes(consensusKey) | ||
if err != nil { | ||
utils.Fatalf("invalid consensus key %v", err) | ||
} | ||
sig, err := blst.SignatureFromBytes(signatures[2*crypto.SignatureLength:]) | ||
if err != nil { | ||
utils.Fatalf("can't recover signature key %v", err) | ||
} | ||
if sig.IsZero() { | ||
utils.Fatalf("can't recover signature key %v", err) | ||
} | ||
err = crypto.BLSPOPVerify(key, sig, treasuryKey) | ||
if err == nil { | ||
out.ConsensusKeyPOP = true | ||
} | ||
|
||
if ctx.Bool(jsonFlag.Name) { | ||
mustPrintJSON(out) | ||
} else { | ||
fmt.Println("===== POP Validation Results =====") | ||
fmt.Println("Node Key: ", out.NodeKeyPOP) | ||
fmt.Println("Oracle Key: ", out.OracleKeyPOP) | ||
fmt.Println("Consensus Key: ", out.ConsensusKeyPOP) | ||
} | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.