Skip to content

Commit

Permalink
CollectStdTxs() must check DelegatorAddr against accounts
Browse files Browse the repository at this point in the history
Closes: #3003
  • Loading branch information
Alessio Treglia committed Dec 5, 2018
1 parent 6395e2a commit 805a710
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ BUG FIXES
* [\#2921](https://github.com/cosmos/cosmos-sdk/issues/2921) Fix `keys delete` inability to delete offline and ledger keys.

* Gaia
* [\#3003](https://github.com/cosmos/cosmos-sdk/issues/3003) CollectStdTxs() must validate DelegatorAddr against genesis accounts.

* SDK
* \#2967 Change ordering of `mint.BeginBlocker` and `distr.BeginBlocker`, recalculate inflation each block
Expand Down
24 changes: 17 additions & 7 deletions cmd/gaia/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,30 @@ func CollectStdTxs(cdc *codec.Codec, moniker string, genTxsDir string, genDoc tm
"each genesis transaction must provide a single genesis message")
}

// validate the validator address and funds against the accounts in the state
msg := msgs[0].(stake.MsgCreateValidator)
addr := string(sdk.AccAddress(msg.ValidatorAddr))
acc, ok := addrMap[addr]
// validate delegator and validator addresses and funds against the accounts in the state
delAddr := string(msg.DelegatorAddr)
valAddr := string(sdk.AccAddress(msg.ValidatorAddr))

if !ok {
delAcc, delOk := addrMap[delAddr]
_, valOk := addrMap[valAddr]

accsNotInGenesis := []string{}
if !delOk {
accsNotInGenesis = append(accsNotInGenesis, fmt.Sprintf("%v", delAddr))
}
if !valOk {
accsNotInGenesis = append(accsNotInGenesis, fmt.Sprintf("%v", valAddr))
}
if len(accsNotInGenesis) != 0 {
return appGenTxs, persistentPeers, fmt.Errorf(
"account %v not in genesis.json: %+v", addr, addrMap)
"account(s) %v not in genesis.json: %+v", strings.Join(accsNotInGenesis, " "), addrMap)
}

if acc.Coins.AmountOf(msg.Delegation.Denom).LT(msg.Delegation.Amount) {
if delAcc.Coins.AmountOf(msg.Delegation.Denom).LT(msg.Delegation.Amount) {
return appGenTxs, persistentPeers, fmt.Errorf(
"insufficient fund for delegation %v: %v < %v",
acc.Address, acc.Coins.AmountOf(msg.Delegation.Denom), msg.Delegation.Amount,
delAcc.Address, delAcc.Coins.AmountOf(msg.Delegation.Denom), msg.Delegation.Amount,
)
}

Expand Down

0 comments on commit 805a710

Please sign in to comment.