-
Notifications
You must be signed in to change notification settings - Fork 4
/
msgs.go
750 lines (635 loc) · 24.9 KB
/
msgs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
package types
import (
"encoding/hex"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/tendermint/tendermint/crypto/tmhash"
)
// nolint: exhaustruct
var (
_ sdk.Msg = &MsgSetOrchestratorAddress{}
_ sdk.Msg = &MsgValsetConfirm{}
_ sdk.Msg = &MsgSendToEth{}
_ sdk.Msg = &MsgCancelSendToEth{}
_ sdk.Msg = &MsgRequestBatch{}
_ sdk.Msg = &MsgConfirmBatch{}
_ sdk.Msg = &MsgERC20DeployedClaim{}
_ sdk.Msg = &MsgConfirmLogicCall{}
_ sdk.Msg = &MsgLogicCallExecutedClaim{}
_ sdk.Msg = &MsgSendToCosmosClaim{}
_ sdk.Msg = &MsgExecuteIbcAutoForwards{}
_ sdk.Msg = &MsgBatchSendToEthClaim{}
_ sdk.Msg = &MsgValsetUpdatedClaim{}
_ sdk.Msg = &MsgSubmitBadSignatureEvidence{}
)
// NewMsgSetOrchestratorAddress returns a new msgSetOrchestratorAddress
func NewMsgSetOrchestratorAddress(val sdk.ValAddress, oper sdk.AccAddress, eth EthAddress) *MsgSetOrchestratorAddress {
return &MsgSetOrchestratorAddress{
Validator: val.String(),
Orchestrator: oper.String(),
EthAddress: eth.GetAddress().Hex(),
}
}
// Route should return the name of the module
func (msg *MsgSetOrchestratorAddress) Route() string { return RouterKey }
// Type should return the action
func (msg *MsgSetOrchestratorAddress) Type() string { return "set_operator_address" }
// ValidateBasic performs stateless checks
func (msg *MsgSetOrchestratorAddress) ValidateBasic() (err error) {
if _, err = sdk.ValAddressFromBech32(msg.Validator); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Validator)
}
if _, err = sdk.AccAddressFromBech32(msg.Orchestrator); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Orchestrator)
}
if err := ValidateEthAddress(msg.EthAddress); err != nil {
return sdkerrors.Wrap(err, "ethereum address")
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg *MsgSetOrchestratorAddress) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg *MsgSetOrchestratorAddress) GetSigners() []sdk.AccAddress {
acc, err := sdk.ValAddressFromBech32(msg.Validator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sdk.AccAddress(acc)}
}
// NewMsgValsetConfirm returns a new msgValsetConfirm
func NewMsgValsetConfirm(
nonce uint64,
ethAddress EthAddress,
validator sdk.AccAddress,
signature string,
) *MsgValsetConfirm {
return &MsgValsetConfirm{
Nonce: nonce,
Orchestrator: validator.String(),
EthAddress: ethAddress.GetAddress().Hex(),
Signature: signature,
}
}
// Route should return the name of the module
func (msg *MsgValsetConfirm) Route() string { return RouterKey }
// Type should return the action
func (msg *MsgValsetConfirm) Type() string { return "valset_confirm" }
// ValidateBasic performs stateless checks
func (msg *MsgValsetConfirm) ValidateBasic() (err error) {
if _, err = sdk.AccAddressFromBech32(msg.Orchestrator); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Orchestrator)
}
if err := ValidateEthAddress(msg.EthAddress); err != nil {
return sdkerrors.Wrap(err, "ethereum address")
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg *MsgValsetConfirm) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg *MsgValsetConfirm) GetSigners() []sdk.AccAddress {
// TODO: figure out how to convert between AccAddress and ValAddress properly
acc, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
}
// NewMsgSendToEth returns a new msgSendToEth
func NewMsgSendToEth(sender sdk.AccAddress, destAddress EthAddress, send sdk.Coin, bridgeFee sdk.Coin) *MsgSendToEth {
return &MsgSendToEth{
Sender: sender.String(),
EthDest: destAddress.GetAddress().Hex(),
Amount: send,
BridgeFee: bridgeFee,
}
}
// Route should return the name of the module
func (msg MsgSendToEth) Route() string { return RouterKey }
// Type should return the action
func (msg MsgSendToEth) Type() string { return "send_to_eth" }
// ValidateBasic runs stateless checks on the message
// Checks if the Eth address is valid
func (msg MsgSendToEth) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Sender)
}
// fee and send must be of the same denom
if msg.Amount.Denom != msg.BridgeFee.Denom {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins,
fmt.Sprintf("fee and amount must be the same type %s != %s", msg.Amount.Denom, msg.BridgeFee.Denom))
}
if !msg.Amount.IsValid() || msg.Amount.IsZero() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "amount")
}
if !msg.BridgeFee.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "fee")
}
if err := ValidateEthAddress(msg.EthDest); err != nil {
return sdkerrors.Wrap(err, "ethereum address")
}
// TODO validate fee is sufficient, fixed fee to start
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgSendToEth) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg MsgSendToEth) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
}
// NewMsgRequestBatch returns a new msgRequestBatch
func NewMsgRequestBatch(orchestrator sdk.AccAddress) *MsgRequestBatch {
return &MsgRequestBatch{
Sender: orchestrator.String(),
Denom: "",
}
}
// Route should return the name of the module
func (msg MsgRequestBatch) Route() string { return RouterKey }
// Type should return the action
func (msg MsgRequestBatch) Type() string { return "request_batch" }
// ValidateBasic performs stateless checks
func (msg MsgRequestBatch) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Sender)
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgRequestBatch) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg MsgRequestBatch) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
}
// Route should return the name of the module
func (msg MsgConfirmBatch) Route() string { return RouterKey }
// Type should return the action
func (msg MsgConfirmBatch) Type() string { return "confirm_batch" }
// ValidateBasic performs stateless checks
func (msg MsgConfirmBatch) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Orchestrator); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Orchestrator)
}
if err := ValidateEthAddress(msg.EthSigner); err != nil {
return sdkerrors.Wrap(err, "eth signer")
}
if err := ValidateEthAddress(msg.TokenContract); err != nil {
return sdkerrors.Wrap(err, "token contract")
}
_, err := hex.DecodeString(msg.Signature)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Could not decode hex string %s", msg.Signature)
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgConfirmBatch) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg MsgConfirmBatch) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
}
// Route should return the name of the module
func (msg MsgConfirmLogicCall) Route() string { return RouterKey }
// Type should return the action
func (msg MsgConfirmLogicCall) Type() string { return "confirm_logic" }
// ValidateBasic performs stateless checks
func (msg MsgConfirmLogicCall) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Orchestrator); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Orchestrator)
}
if err := ValidateEthAddress(msg.EthSigner); err != nil {
return sdkerrors.Wrap(err, "eth signer")
}
_, err := hex.DecodeString(msg.Signature)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Could not decode hex string %s", msg.Signature)
}
_, err = hex.DecodeString(msg.InvalidationId)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Could not decode hex string %s", msg.InvalidationId)
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgConfirmLogicCall) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg MsgConfirmLogicCall) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
}
// EthereumClaim represents a claim on ethereum state
type EthereumClaim interface {
// All Ethereum claims that we relay from the Gravity contract and into the module
// have a nonce that is monotonically increasing and unique, since this nonce is
// issued by the Ethereum contract it is immutable and must be agreed on by all validators
// any disagreement on what claim goes to what nonce means someone is lying.
GetEventNonce() uint64
// The block height that the claimed event occurred on. This EventNonce provides sufficient
// ordering for the execution of all claims. The block height is used only for batchTimeouts + logicTimeouts
// when we go to create a new batch we set the timeout some number of batches out from the last
// known height plus projected block progress since then.
GetEthBlockHeight() uint64
// the delegate address of the claimer, for MsgDepositClaim and MsgWithdrawClaim
// this is sent in as the sdk.AccAddress of the delegated key. it is up to the user
// to disambiguate this into a sdk.ValAddress
GetClaimer() sdk.AccAddress
// Which type of claim this is
GetType() ClaimType
ValidateBasic() error
// The claim hash of this claim. This is used to store these claims and also used to check if two different
// validators claims agree. Therefore it's extremely important that this include all elements of the claim
// with the exception of the orchestrator who sent it in, which will be used as a different part of the index
ClaimHash() ([]byte, error)
}
// nolint: exhaustruct
var (
_ EthereumClaim = &MsgSendToCosmosClaim{}
_ EthereumClaim = &MsgBatchSendToEthClaim{}
_ EthereumClaim = &MsgERC20DeployedClaim{}
_ EthereumClaim = &MsgLogicCallExecutedClaim{}
)
// GetType returns the type of the claim
func (msg *MsgSendToCosmosClaim) GetType() ClaimType {
return CLAIM_TYPE_SEND_TO_COSMOS
}
// ValidateBasic performs stateless checks
func (msg *MsgSendToCosmosClaim) ValidateBasic() error {
if err := ValidateEthAddress(msg.EthereumSender); err != nil {
return sdkerrors.Wrap(err, "eth sender")
}
if err := ValidateEthAddress(msg.TokenContract); err != nil {
return sdkerrors.Wrap(err, "erc20 token")
}
if _, err := sdk.AccAddressFromBech32(msg.Orchestrator); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "orchestrator")
}
// note the destination address is intentionally not validated here, since
// MsgSendToEth has it's destination as a string many invalid inputs are possible
// the orchestrator will convert these invalid deposits to simply the string invalid'
// this is done because the oracle requires an event be processed on Cosmos for each event
// nonce on the Ethereum side, otherwise (A) the oracle will never proceed and (B) the funds
// sent with the invalid deposit will forever be lost, with no representation minted anywhere
// on cosmos. The attestation handler deals with this by managing invalid deposits and placing
// them into the community pool
if msg.EventNonce == 0 {
return fmt.Errorf("nonce == 0")
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgSendToCosmosClaim) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
func (msg MsgSendToCosmosClaim) GetClaimer() sdk.AccAddress {
err := msg.ValidateBasic()
if err != nil {
panic("MsgSendToCosmosClaim failed ValidateBasic! Should have been handled earlier")
}
val, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(err)
}
return val
}
// GetSigners defines whose signature is required
func (msg MsgSendToCosmosClaim) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
}
// Type should return the action
func (msg MsgSendToCosmosClaim) Type() string { return "send_to_cosmos_claim" }
// Route should return the name of the module
func (msg MsgSendToCosmosClaim) Route() string { return RouterKey }
const (
TypeMsgSendToCosmosClaim = "send_to_cosmos_claim"
)
// Hash implements BridgeDeposit.Hash
// modify this with care as it is security sensitive. If an element of the claim is not in this hash a single hostile validator
// could engineer a hash collision and execute a version of the claim with any unhashed data changed to benefit them.
// note that the Orchestrator is the only field excluded from this hash, this is because that value is used higher up in the store
// structure for who has made what claim and is verified by the msg ante-handler for signatures
func (msg *MsgSendToCosmosClaim) ClaimHash() ([]byte, error) {
path := fmt.Sprintf("%d/%d/%s/%s/%s/%s", msg.EventNonce, msg.EthBlockHeight, msg.TokenContract, msg.Amount.String(), msg.EthereumSender, msg.CosmosReceiver)
return tmhash.Sum([]byte(path)), nil
}
func (msg *MsgExecuteIbcAutoForwards) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Executor); err != nil {
return sdkerrors.Wrap(err, "Unable to parse executor as a valid bech32 address")
}
return nil
}
func (msg *MsgExecuteIbcAutoForwards) GetSigners() []sdk.AccAddress {
msg.ProtoMessage()
acc, err := sdk.AccAddressFromBech32(msg.Executor)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
}
// GetType returns the claim type
func (msg *MsgBatchSendToEthClaim) GetType() ClaimType {
return CLAIM_TYPE_BATCH_SEND_TO_ETH
}
// ValidateBasic performs stateless checks
func (e *MsgBatchSendToEthClaim) ValidateBasic() error {
if e.EventNonce == 0 {
return fmt.Errorf("event_nonce == 0")
}
if e.BatchNonce == 0 {
return fmt.Errorf("batch_nonce == 0")
}
if err := ValidateEthAddress(e.TokenContract); err != nil {
return sdkerrors.Wrap(err, "erc20 token")
}
if _, err := sdk.AccAddressFromBech32(e.Orchestrator); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, e.Orchestrator)
}
return nil
}
// Hash implements WithdrawBatch.Hash
func (msg *MsgBatchSendToEthClaim) ClaimHash() ([]byte, error) {
path := fmt.Sprintf("%d/%d/%d/%s", msg.EventNonce, msg.EthBlockHeight, msg.BatchNonce, msg.TokenContract)
return tmhash.Sum([]byte(path)), nil
}
// GetSignBytes encodes the message for signing
func (msg MsgBatchSendToEthClaim) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
func (msg MsgBatchSendToEthClaim) GetClaimer() sdk.AccAddress {
err := msg.ValidateBasic()
if err != nil {
panic("MsgBatchSendToEthClaim failed ValidateBasic! Should have been handled earlier")
}
val, _ := sdk.AccAddressFromBech32(msg.Orchestrator)
return val
}
// GetSigners defines whose signature is required
func (msg MsgBatchSendToEthClaim) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
}
// Route should return the name of the module
func (msg MsgBatchSendToEthClaim) Route() string { return RouterKey }
// Type should return the action
func (msg MsgBatchSendToEthClaim) Type() string { return "batch_send_to_eth_claim" }
const (
TypeMsgBatchSendToEthClaim = "batch_send_to_eth_claim"
)
// EthereumClaim implementation for MsgERC20DeployedClaim
// ======================================================
// GetType returns the type of the claim
func (e *MsgERC20DeployedClaim) GetType() ClaimType {
return CLAIM_TYPE_ERC20_DEPLOYED
}
// ValidateBasic performs stateless checks
func (e *MsgERC20DeployedClaim) ValidateBasic() error {
if err := ValidateEthAddress(e.TokenContract); err != nil {
return sdkerrors.Wrap(err, "erc20 token")
}
if _, err := sdk.AccAddressFromBech32(e.Orchestrator); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, e.Orchestrator)
}
if e.EventNonce == 0 {
return fmt.Errorf("nonce == 0")
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgERC20DeployedClaim) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
func (msg MsgERC20DeployedClaim) GetClaimer() sdk.AccAddress {
err := msg.ValidateBasic()
if err != nil {
panic("MsgERC20DeployedClaim failed ValidateBasic! Should have been handled earlier")
}
val, _ := sdk.AccAddressFromBech32(msg.Orchestrator)
return val
}
// GetSigners defines whose signature is required
func (msg MsgERC20DeployedClaim) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
}
// Type should return the action
func (msg MsgERC20DeployedClaim) Type() string { return "ERC20_deployed_claim" }
// Route should return the name of the module
func (msg MsgERC20DeployedClaim) Route() string { return RouterKey }
// Hash implements BridgeDeposit.Hash
// modify this with care as it is security sensitive. If an element of the claim is not in this hash a single hostile validator
// could engineer a hash collision and execute a version of the claim with any unhashed data changed to benefit them.
// note that the Orchestrator is the only field excluded from this hash, this is because that value is used higher up in the store
// structure for who has made what claim and is verified by the msg ante-handler for signatures
func (b *MsgERC20DeployedClaim) ClaimHash() ([]byte, error) {
path := fmt.Sprintf("%d/%d/%s/%s/%s/%s/%d", b.EventNonce, b.EthBlockHeight, b.CosmosDenom, b.TokenContract, b.Name, b.Symbol, b.Decimals)
return tmhash.Sum([]byte(path)), nil
}
// EthereumClaim implementation for MsgLogicCallExecutedClaim
// ======================================================
// GetType returns the type of the claim
func (e *MsgLogicCallExecutedClaim) GetType() ClaimType {
return CLAIM_TYPE_LOGIC_CALL_EXECUTED
}
// ValidateBasic performs stateless checks
func (e *MsgLogicCallExecutedClaim) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(e.Orchestrator); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, e.Orchestrator)
}
if e.EventNonce == 0 {
return fmt.Errorf("nonce == 0")
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgLogicCallExecutedClaim) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
func (msg MsgLogicCallExecutedClaim) GetClaimer() sdk.AccAddress {
err := msg.ValidateBasic()
if err != nil {
panic("MsgERC20DeployedClaim failed ValidateBasic! Should have been handled earlier")
}
val, _ := sdk.AccAddressFromBech32(msg.Orchestrator)
return val
}
// GetSigners defines whose signature is required
func (msg MsgLogicCallExecutedClaim) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
}
// Type should return the action
func (msg MsgLogicCallExecutedClaim) Type() string { return "Logic_Call_Executed_Claim" }
// Route should return the name of the module
func (msg MsgLogicCallExecutedClaim) Route() string { return RouterKey }
// Hash implements BridgeDeposit.Hash
// modify this with care as it is security sensitive. If an element of the claim is not in this hash a single hostile validator
// could engineer a hash collision and execute a version of the claim with any unhashed data changed to benefit them.
// note that the Orchestrator is the only field excluded from this hash, this is because that value is used higher up in the store
// structure for who has made what claim and is verified by the msg ante-handler for signatures
func (b *MsgLogicCallExecutedClaim) ClaimHash() ([]byte, error) {
path := fmt.Sprintf("%d,%d,%s/%d/", b.EventNonce, b.EthBlockHeight, b.InvalidationId, b.InvalidationNonce)
return tmhash.Sum([]byte(path)), nil
}
// EthereumClaim implementation for MsgValsetUpdatedClaim
// ======================================================
// GetType returns the type of the claim
func (e *MsgValsetUpdatedClaim) GetType() ClaimType {
return CLAIM_TYPE_VALSET_UPDATED
}
// ValidateBasic performs stateless checks
func (e *MsgValsetUpdatedClaim) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(e.Orchestrator); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, e.Orchestrator)
}
if e.EventNonce == 0 {
return fmt.Errorf("nonce == 0")
}
err := ValidateEthAddress(e.RewardToken)
if err != nil {
return err
}
for _, member := range e.Members {
err := ValidateEthAddress(member.EthereumAddress)
if err != nil {
return err
}
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgValsetUpdatedClaim) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
func (msg MsgValsetUpdatedClaim) GetClaimer() sdk.AccAddress {
err := msg.ValidateBasic()
if err != nil {
panic("MsgERC20DeployedClaim failed ValidateBasic! Should have been handled earlier")
}
val, _ := sdk.AccAddressFromBech32(msg.Orchestrator)
return val
}
// GetSigners defines whose signature is required
func (msg MsgValsetUpdatedClaim) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
}
// Type should return the action
func (msg MsgValsetUpdatedClaim) Type() string { return "Valset_Updated_Claim" }
// Route should return the name of the module
func (msg MsgValsetUpdatedClaim) Route() string { return RouterKey }
// Hash implements BridgeDeposit.Hash
// modify this with care as it is security sensitive. If an element of the claim is not in this hash a single hostile validator
// could engineer a hash collision and execute a version of the claim with any unhashed data changed to benefit them.
// note that the Orchestrator is the only field excluded from this hash, this is because that value is used higher up in the store
// structure for who has made what claim and is verified by the msg ante-handler for signatures
func (b *MsgValsetUpdatedClaim) ClaimHash() ([]byte, error) {
var members BridgeValidators = b.Members
internalMembers, err := members.ToInternal()
if err != nil {
return nil, sdkerrors.Wrap(err, "invalid members")
}
internalMembers.Sort()
path := fmt.Sprintf("%d/%d/%d/%x/%s/%s", b.EventNonce, b.ValsetNonce, b.EthBlockHeight, internalMembers.ToExternal(), b.RewardAmount.String(), b.RewardToken)
return tmhash.Sum([]byte(path)), nil
}
// NewMsgCancelSendToEth returns a new msgSetOrchestratorAddress
func NewMsgCancelSendToEth(user sdk.AccAddress, id uint64) *MsgCancelSendToEth {
return &MsgCancelSendToEth{
Sender: user.String(),
TransactionId: id,
}
}
// Route should return the name of the module
func (msg *MsgCancelSendToEth) Route() string { return RouterKey }
// Type should return the action
func (msg *MsgCancelSendToEth) Type() string { return "cancel_send_to_eth" }
// ValidateBasic performs stateless checks
func (msg *MsgCancelSendToEth) ValidateBasic() (err error) {
_, err = sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return err
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg *MsgCancelSendToEth) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg *MsgCancelSendToEth) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
}
// MsgSubmitBadSignatureEvidence
// ======================================================
// ValidateBasic performs stateless checks
func (e *MsgSubmitBadSignatureEvidence) ValidateBasic() (err error) {
_, err = sdk.AccAddressFromBech32(e.Sender)
if err != nil {
return err
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgSubmitBadSignatureEvidence) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg MsgSubmitBadSignatureEvidence) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic("Invalid signer for MsgSubmitBadSignatureEvidence")
}
return []sdk.AccAddress{acc}
}
// Type should return the action
func (msg MsgSubmitBadSignatureEvidence) Type() string { return "Submit_Bad_Signature_Evidence" }
// Route should return the name of the module
func (msg MsgSubmitBadSignatureEvidence) Route() string { return RouterKey }