Skip to content

Commit 7c3ac87

Browse files
mmsqeyihuang
andauthored
Problem: sender check for MsgStoreBlockList is not in CheckTx (#1613)
* Problem: no max length validation for blob msg * cleanup legacy msg related stuff * check from * doc * check for all * Revert "check for all" This reverts commit f7405ce. --------- Co-authored-by: yihuang <[email protected]>
1 parent 731c987 commit 7c3ac87

File tree

6 files changed

+93
-183
lines changed

6 files changed

+93
-183
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* [#1610](https://github.com/crypto-org-chain/cronos/pull/1610) Sync e2ee module with v1.3.x branch.
1616
* [#1612](https://github.com/crypto-org-chain/cronos/pull/1612) Support ibc channel upgrade related methods.
1717
* [#1614](https://github.com/crypto-org-chain/cronos/pull/1614) Bump cosmos-sdk to v0.50.10.
18+
* [#1613](https://github.com/crypto-org-chain/cronos/pull/1613) Check admin sender for MsgStoreBlockList in check tx.
1819

1920
### Bug Fixes
2021

app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ func (app *App) setAnteHandler(txConfig client.TxConfig, maxGasWanted uint64, bl
11061106

11071107
blockedMap[addr.String()] = struct{}{}
11081108
}
1109-
blockAddressDecorator := NewBlockAddressesDecorator(blockedMap)
1109+
blockAddressDecorator := NewBlockAddressesDecorator(blockedMap, app.CronosKeeper.GetParams)
11101110
options := evmante.HandlerOptions{
11111111
AccountKeeper: app.AccountKeeper,
11121112
BankKeeper: app.BankKeeper,

app/block_address.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@ package app
33
import (
44
"fmt"
55

6+
"cosmossdk.io/errors"
67
sdk "github.com/cosmos/cosmos-sdk/types"
8+
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
79
"github.com/cosmos/cosmos-sdk/x/auth/signing"
10+
"github.com/crypto-org-chain/cronos/v2/x/cronos/types"
811
)
912

1013
// BlockAddressesDecorator block addresses from sending transactions
1114
type BlockAddressesDecorator struct {
1215
blockedMap map[string]struct{}
16+
getParams func(ctx sdk.Context) types.Params
1317
}
1418

15-
func NewBlockAddressesDecorator(blacklist map[string]struct{}) BlockAddressesDecorator {
19+
func NewBlockAddressesDecorator(
20+
blacklist map[string]struct{},
21+
getParams func(ctx sdk.Context) types.Params,
22+
) BlockAddressesDecorator {
1623
return BlockAddressesDecorator{
1724
blockedMap: blacklist,
25+
getParams: getParams,
1826
}
1927
}
2028

@@ -31,6 +39,14 @@ func (bad BlockAddressesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
3139
}
3240
}
3341
}
42+
admin := bad.getParams(ctx).CronosAdmin
43+
for _, msg := range tx.GetMsgs() {
44+
if blocklistMsg, ok := msg.(*types.MsgStoreBlockList); ok {
45+
if admin != blocklistMsg.From {
46+
return ctx, errors.Wrap(sdkerrors.ErrUnauthorized, "msg sender is not authorized")
47+
}
48+
}
49+
}
3450
}
3551
return next(ctx, tx, simulate)
3652
}

x/cronos/types/messages.go

Lines changed: 3 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ import (
1212
"github.com/ethereum/go-ethereum/common"
1313
)
1414

15-
const (
16-
TypeMsgConvertVouchers = "ConvertVouchers"
17-
TypeMsgTransferTokens = "TransferTokens"
18-
TypeMsgUpdateTokenMapping = "UpdateTokenMapping"
19-
TypeMsgUpdateParams = "UpdateParams"
20-
TypeMsgTurnBridge = "TurnBridge"
21-
TypeMsgUpdatePermissions = "UpdatePermissions"
22-
TypeMsgStoreBlockList = "StoreBlockList"
23-
)
15+
const TypeMsgUpdateTokenMapping = "UpdateTokenMapping"
2416

2517
var (
2618
_ sdk.Msg = &MsgConvertVouchers{}
@@ -39,31 +31,6 @@ func NewMsgConvertVouchers(address string, coins sdk.Coins) *MsgConvertVouchers
3931
}
4032
}
4133

42-
// Route ...
43-
func (msg MsgConvertVouchers) Route() string {
44-
return RouterKey
45-
}
46-
47-
// Type ...
48-
func (msg MsgConvertVouchers) Type() string {
49-
return TypeMsgConvertVouchers
50-
}
51-
52-
// GetSigners ...
53-
func (msg *MsgConvertVouchers) GetSigners() []sdk.AccAddress {
54-
address, err := sdk.AccAddressFromBech32(msg.Address)
55-
if err != nil {
56-
panic(err)
57-
}
58-
return []sdk.AccAddress{address}
59-
}
60-
61-
// GetSignBytes ...
62-
func (msg *MsgConvertVouchers) GetSignBytes() []byte {
63-
bz := ModuleCdc.MustMarshalJSON(msg)
64-
return sdk.MustSortJSON(bz)
65-
}
66-
6734
// ValidateBasic ...
6835
func (msg *MsgConvertVouchers) ValidateBasic() error {
6936
_, err := sdk.AccAddressFromBech32(msg.Address)
@@ -90,31 +57,6 @@ func NewMsgTransferTokens(from string, to string, coins sdk.Coins) *MsgTransferT
9057
}
9158
}
9259

93-
// Route ...
94-
func (msg MsgTransferTokens) Route() string {
95-
return RouterKey
96-
}
97-
98-
// Type ...
99-
func (msg MsgTransferTokens) Type() string {
100-
return TypeMsgTransferTokens
101-
}
102-
103-
// GetSigners ...
104-
func (msg *MsgTransferTokens) GetSigners() []sdk.AccAddress {
105-
from, err := sdk.AccAddressFromBech32(msg.From)
106-
if err != nil {
107-
panic(err)
108-
}
109-
return []sdk.AccAddress{from}
110-
}
111-
112-
// GetSignBytes ...
113-
func (msg *MsgTransferTokens) GetSignBytes() []byte {
114-
bz := ModuleCdc.MustMarshalJSON(msg)
115-
return sdk.MustSortJSON(bz)
116-
}
117-
11860
// ValidateBasic ...
11961
func (msg *MsgTransferTokens) ValidateBasic() error {
12062
_, err := sdk.AccAddressFromBech32(msg.From)
@@ -174,22 +116,11 @@ func (msg *MsgUpdateTokenMapping) ValidateBasic() error {
174116
return nil
175117
}
176118

177-
// Route ...
178-
func (msg MsgUpdateTokenMapping) Route() string {
179-
return RouterKey
180-
}
181-
182119
// Type ...
183120
func (msg MsgUpdateTokenMapping) Type() string {
184121
return TypeMsgUpdateTokenMapping
185122
}
186123

187-
// GetSignBytes ...
188-
func (msg *MsgUpdateTokenMapping) GetSignBytes() []byte {
189-
bz := ModuleCdc.MustMarshalJSON(msg)
190-
return sdk.MustSortJSON(bz)
191-
}
192-
193124
// NewMsgTurnBridge ...
194125
func NewMsgTurnBridge(admin string, enable bool) *MsgTurnBridge {
195126
return &MsgTurnBridge{
@@ -198,15 +129,6 @@ func NewMsgTurnBridge(admin string, enable bool) *MsgTurnBridge {
198129
}
199130
}
200131

201-
// GetSigners ...
202-
func (msg *MsgTurnBridge) GetSigners() []sdk.AccAddress {
203-
sender, err := sdk.AccAddressFromBech32(msg.Sender)
204-
if err != nil {
205-
panic(err)
206-
}
207-
return []sdk.AccAddress{sender}
208-
}
209-
210132
// ValidateBasic ...
211133
func (msg *MsgTurnBridge) ValidateBasic() error {
212134
_, err := sdk.AccAddressFromBech32(msg.Sender)
@@ -217,38 +139,13 @@ func (msg *MsgTurnBridge) ValidateBasic() error {
217139
return nil
218140
}
219141

220-
// Route ...
221-
func (msg MsgTurnBridge) Route() string {
222-
return RouterKey
223-
}
224-
225-
// Type ...
226-
func (msg MsgTurnBridge) Type() string {
227-
return TypeMsgTurnBridge
228-
}
229-
230-
// GetSignBytes ...
231-
func (msg *MsgTurnBridge) GetSignBytes() []byte {
232-
bz := ModuleCdc.MustMarshalJSON(msg)
233-
return sdk.MustSortJSON(bz)
234-
}
235-
236142
func NewMsgUpdateParams(authority string, params Params) *MsgUpdateParams {
237143
return &MsgUpdateParams{
238144
Authority: authority,
239145
Params: params,
240146
}
241147
}
242148

243-
// GetSigners returns the expected signers for a MsgUpdateParams message.
244-
func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress {
245-
addr, err := sdk.AccAddressFromBech32(msg.Authority)
246-
if err != nil {
247-
panic(err)
248-
}
249-
return []sdk.AccAddress{addr}
250-
}
251-
252149
// ValidateBasic does a sanity check on the provided data.
253150
func (msg *MsgUpdateParams) ValidateBasic() error {
254151
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
@@ -262,22 +159,6 @@ func (msg *MsgUpdateParams) ValidateBasic() error {
262159
return nil
263160
}
264161

265-
// Route ...
266-
func (msg MsgUpdateParams) Route() string {
267-
return RouterKey
268-
}
269-
270-
// Type ...
271-
func (msg MsgUpdateParams) Type() string {
272-
return TypeMsgUpdateParams
273-
}
274-
275-
// GetSignBytes ...
276-
func (msg *MsgUpdateParams) GetSignBytes() []byte {
277-
bz := ModuleCdc.MustMarshalJSON(msg)
278-
return sdk.MustSortJSON(bz)
279-
}
280-
281162
// NewMsgUpdatePermissions ...
282163
func NewMsgUpdatePermissions(from string, address string, permissions uint64) *MsgUpdatePermissions {
283164
return &MsgUpdatePermissions{
@@ -287,15 +168,6 @@ func NewMsgUpdatePermissions(from string, address string, permissions uint64) *M
287168
}
288169
}
289170

290-
// GetSigners ...
291-
func (msg *MsgUpdatePermissions) GetSigners() []sdk.AccAddress {
292-
sender, err := sdk.AccAddressFromBech32(msg.From)
293-
if err != nil {
294-
panic(err)
295-
}
296-
return []sdk.AccAddress{sender}
297-
}
298-
299171
// ValidateBasic ...
300172
func (msg *MsgUpdatePermissions) ValidateBasic() error {
301173
_, err := sdk.AccAddressFromBech32(msg.From)
@@ -310,22 +182,6 @@ func (msg *MsgUpdatePermissions) ValidateBasic() error {
310182
return nil
311183
}
312184

313-
// Route ...
314-
func (msg MsgUpdatePermissions) Route() string {
315-
return RouterKey
316-
}
317-
318-
// Type ...
319-
func (msg MsgUpdatePermissions) Type() string {
320-
return TypeMsgUpdatePermissions
321-
}
322-
323-
// GetSignBytes ...
324-
func (msg *MsgUpdatePermissions) GetSignBytes() []byte {
325-
bz := ModuleCdc.MustMarshalJSON(msg)
326-
return sdk.MustSortJSON(bz)
327-
}
328-
329185
func NewMsgStoreBlockList(from string, blob []byte) *MsgStoreBlockList {
330186
return &MsgStoreBlockList{
331187
From: from,
@@ -346,35 +202,11 @@ func (msg *MsgStoreBlockList) ValidateBasic() error {
346202
if err != nil {
347203
return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err)
348204
}
349-
205+
// skip heavy operation in Decrypt by early return with errDummyIdentity in
206+
// https://github.com/FiloSottile/age/blob/v1.1.1/age.go#L197
350207
_, err = age.Decrypt(bytes.NewBuffer(msg.Blob), new(dummyIdentity))
351208
if err != nil && err != errDummyIdentity {
352209
return err
353210
}
354211
return nil
355212
}
356-
357-
func (msg *MsgStoreBlockList) GetSigners() []sdk.AccAddress {
358-
addr, err := sdk.AccAddressFromBech32(msg.From)
359-
if err != nil {
360-
panic(err)
361-
}
362-
363-
return []sdk.AccAddress{addr}
364-
}
365-
366-
// GetSignBytes ...
367-
func (msg *MsgStoreBlockList) GetSignBytes() []byte {
368-
bz := ModuleCdc.MustMarshalJSON(msg)
369-
return sdk.MustSortJSON(bz)
370-
}
371-
372-
// Route ...
373-
func (msg MsgStoreBlockList) Route() string {
374-
return RouterKey
375-
}
376-
377-
// Type ...
378-
func (msg MsgStoreBlockList) Type() string {
379-
return TypeMsgStoreBlockList
380-
}

0 commit comments

Comments
 (0)