Skip to content

Commit

Permalink
chore: update bls generate-proof cmd (#2215)
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 authored Feb 16, 2024
1 parent 9e4d15b commit a2ddb75
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
25 changes: 15 additions & 10 deletions cmd/geth/blsaccountcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,19 +633,24 @@ func blsAccountDelete(ctx *cli.Context) error {

// blsAccountGenerateProof generate ownership proof for a selected BLS account.
func blsAccountGenerateProof(ctx *cli.Context) error {
pubkeyString := ctx.Args().First()
if pubkeyString == "" {
utils.Fatalf("BLS account must be given as argument.")
addrString := ctx.Args().First()
if addrString == "" {
utils.Fatalf("Operator account must be given as argument.")
}
pubkeyBz, err := hex.DecodeString(strings.TrimPrefix(pubkeyString, "0x"))
addr := common.HexToAddress(addrString)

blsPubkeyString := ctx.Args().Get(1)
if blsPubkeyString == "" {
utils.Fatalf("BLS pubkey must be given as argument.")
}
blsPubkeyBz, err := hex.DecodeString(strings.TrimPrefix(blsPubkeyString, "0x"))
if err != nil {
utils.Fatalf("Could not decode string %s as hex.", pubkeyString)
utils.Fatalf("Could not decode string %s as hex.", blsPubkeyString)
}
blsPublicKey, err := bls.PublicKeyFromBytes(pubkeyBz)
blsPublicKey, err := bls.PublicKeyFromBytes(blsPubkeyBz)
if err != nil {
utils.Fatalf("%#x is not a valid BLS public key.", pubkeyBz)
utils.Fatalf("%#x is not a valid BLS public key.", blsPubkeyBz)
}
blsPublicKeyBz := blsPublicKey.Marshal()

cfg := gethConfig{Node: defaultNodeConfig()}
// Load config file.
Expand Down Expand Up @@ -682,10 +687,10 @@ func blsAccountGenerateProof(ctx *cli.Context) error {
chainId := new(big.Int).SetInt64(chainIdInt64)
paddedChainIdBytes := make([]byte, 32)
copy(paddedChainIdBytes[32-len(chainId.Bytes()):], chainId.Bytes())
msgHash := crypto.Keccak256(append(blsPublicKeyBz, paddedChainIdBytes...))
msgHash := crypto.Keccak256(append(addr.Bytes(), append(blsPublicKey.Marshal(), paddedChainIdBytes...)...))

req := &validatorpb.SignRequest{
PublicKey: blsPublicKeyBz,
PublicKey: blsPublicKey.Marshal(),
SigningRoot: msgHash,
}
sig, err := km.Sign(context.Background(), req)
Expand Down
4 changes: 2 additions & 2 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,7 @@ func (p *Parlia) getCurrentValidators(blockHash common.Hash, blockNum *big.Int)
return valSet, voteAddrMap, nil
}

// slash spoiled validators
// distributeIncoming distributes system incoming of the block
func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, header *types.Header, chain core.ChainContext,
txs *[]*types.Transaction, receipts *[]*types.Receipt, receivedTxs *[]*types.Transaction, usedGas *uint64, mining bool) error {
coinbase := header.Coinbase
Expand Down Expand Up @@ -1719,7 +1719,7 @@ func (p *Parlia) distributeToSystem(amount *big.Int, state *state.StateDB, heade
return p.applyTransaction(msg, state, header, chain, txs, receipts, receivedTxs, usedGas, mining)
}

// slash spoiled validators
// distributeToValidator deposits validator reward to validator contract
func (p *Parlia) distributeToValidator(amount *big.Int, validator common.Address,
state *state.StateDB, header *types.Header, chain core.ChainContext,
txs *[]*types.Transaction, receipts *[]*types.Receipt, receivedTxs *[]*types.Transaction, usedGas *uint64, mining bool) error {
Expand Down

0 comments on commit a2ddb75

Please sign in to comment.