Skip to content

Commit

Permalink
fix operator addresses order validation
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Jun 17, 2024
1 parent 110c19e commit f6ead72
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion light-clients/lcp/types/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,15 @@ func (cs ClientState) Initialize(_ sdk.Context, cdc codec.BinaryCodec, clientSto
return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "`OperatorsThresholdNumerator` and `OperatorsThresholdDenominator` must be non-zero")
}
var zeroAddr common.Address
for _, op := range cs.GetOperators() {
operators := cs.GetOperators()
for i, op := range operators {
if op == zeroAddr {
return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "operator address cannot be empty")
}
// check if the operator is ordered correctly
if i > 0 && bytes.Compare(operators[i-1].Bytes(), op.Bytes()) > 0 {
return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "operator addresses must be ordered: %v > %v", operators[i-1].String(), op.String())
}
}
if cs.OperatorsThresholdNumerator > cs.OperatorsThresholdDenominator {
return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "`OperatorsThresholdNumerator` must be less than or equal to `OperatorsThresholdDenominator`")
Expand Down
10 changes: 10 additions & 0 deletions light-clients/lcp/types/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ func (cs ClientState) verifyUpdateOperators(ctx sdk.Context, store storetypes.KV
if err != nil {
return errorsmod.Wrapf(clienttypes.ErrInvalidHeader, "failed to get new operators: %v clientID=%v", err, clientID)
}
var zeroAddr common.Address
for i, op := range newOperators {
if op == zeroAddr {
return errorsmod.Wrapf(clienttypes.ErrInvalidHeader, "invalid operator: operator address must not be zero: clientID=%v", clientID)
}
// check if the operators are ordered
if i > 0 && bytes.Compare(newOperators[i-1].Bytes(), op.Bytes()) > 0 {
return errorsmod.Wrapf(clienttypes.ErrInvalidHeader, "operator addresses must be ordered: clientID=%v op0=%v op1=%v", clientID, newOperators[i-1].String(), op.String())
}
}
signBytes, err := ComputeEIP712UpdateOperators(
ctx.ChainID(),
[]byte(exported.StoreKey),
Expand Down

0 comments on commit f6ead72

Please sign in to comment.