Skip to content

Commit

Permalink
Revert "feat(evm)!: confirm general message destinate to cosmos chains (
Browse files Browse the repository at this point in the history
#1863)" (#1875)

This reverts commit c06075c.
  • Loading branch information
milapsheth authored Jan 23, 2023
1 parent ba693df commit 6d58c07
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 1,123 deletions.
37 changes: 0 additions & 37 deletions docs/proto/proto-docs.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 0 additions & 20 deletions proto/axelar/nexus/exported/v1beta1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,3 @@ enum TransferDirection {
TRANSFER_DIRECTION_OUTGOING = 2
[ (gogoproto.enumvalue_customname) = "Outgoing" ];
}

message GeneralMessage {
enum Status {
option (gogoproto.goproto_enum_prefix) = false;
option (gogoproto.goproto_enum_stringer) = true;

STATUS_UNSPECIFIED = 0 [ (gogoproto.enumvalue_customname) = "NonExistent" ];
STATUS_APPROVED = 1 [ (gogoproto.enumvalue_customname) = "Approved" ];
STATUS_EXECUTED = 2 [ (gogoproto.enumvalue_customname) = "Executed" ];
}

string id = 1 [ (gogoproto.customname) = "ID" ];
string source_chain = 2 [ (gogoproto.casttype) = "ChainName" ];
string sender = 3;
string destination_chain = 4 [ (gogoproto.casttype) = "ChainName" ];
string receiver = 5;
bytes payload_hash = 6;
Status status = 7;
cosmos.base.v1beta1.Coin asset = 8;
}
24 changes: 0 additions & 24 deletions third_party/proto/google/protobuf/descriptor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -518,18 +518,6 @@ message MessageOptions {
reserved 8; // javalite_serializable
reserved 9; // javanano_as_lite

// Enable the legacy handling of JSON field name conflicts. This lowercases
// and strips underscored from the fields before comparison in proto3 only.
// The new behavior takes `json_name` into account and applies to proto2 as
// well.
//
// This should only be used as a temporary measure against broken builds due
// to the change in behavior for JSON field name conflicts.
//
// TODO(b/261750190) This is legacy behavior we plan to remove once downstream
// teams have had time to migrate.
optional bool deprecated_legacy_json_field_conflicts = 11 [deprecated = true];

// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;

Expand Down Expand Up @@ -627,10 +615,6 @@ message FieldOptions {
// For Google-internal migration only. Do not use.
optional bool weak = 10 [default = false];

// Indicate that the field value should not be printed out when using debug
// formats, e.g. when the field contains sensitive credentials.
optional bool debug_redact = 16 [default = false];

// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;

Expand Down Expand Up @@ -662,14 +646,6 @@ message EnumOptions {

reserved 5; // javanano_as_lite

// Enable the legacy handling of JSON field name conflicts. This lowercases
// and strips underscored from the fields before comparison in proto3 only.
// The new behavior takes `json_name` into account and applies to proto2 as
// well.
// TODO(b/261750190) Remove this legacy behavior once downstream teams have
// had time to migrate.
optional bool deprecated_legacy_json_field_conflicts = 6 [deprecated = true];

// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;

Expand Down
6 changes: 1 addition & 5 deletions x/axelarnet/exported/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ import (
var (
// NativeAsset is the native asset on Axelarnet
NativeAsset = "uaxl"

// ModuleName exposes axelarnet module name
ModuleName = "axelarnet"

// Axelarnet defines properties of the Axelar chain
Axelarnet = exported.Chain{
Name: "Axelarnet",
SupportsForeignAssets: true,
KeyType: tss.None,
Module: ModuleName,
Module: "axelarnet", // cannot use constant due to import cycle
}
)
119 changes: 23 additions & 96 deletions x/evm/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,40 +65,25 @@ func handleTokenSent(ctx sdk.Context, event types.Event, bk types.BaseKeeper, n
}

func handleContractCall(ctx sdk.Context, event types.Event, bk types.BaseKeeper, n types.Nexus, multisig types.MultisigKeeper) error {
e := event.GetContractCall()
e := event.GetEvent().(*types.Event_ContractCall).ContractCall
if e == nil {
panic(fmt.Errorf("event is nil"))
}

destinationChain := funcs.MustOk(n.GetChain(ctx, e.DestinationChain))
switch destinationChain.Module {
case types.ModuleName:
handleContractCallToEVM(ctx, bk, multisig, n, destinationChain.Name, event)
return nil
default:
// set as general message in nexus, so the dest module can handle the message
return setMessageToNexus(ctx, n, event, nil)
}
}
destinationCk := funcs.Must(bk.ForChain(ctx, destinationChain.Name))

func handleContractCallToEVM(ctx sdk.Context, bk types.BaseKeeper, multisig types.MultisigKeeper, n types.Nexus, destinationChain nexus.ChainName, event types.Event) {
e := event.GetContractCall()
if e == nil {
panic(fmt.Errorf("event is nil"))
}

destinationCk := funcs.Must(bk.ForChain(ctx, destinationChain))
cmd := types.NewApproveContractCallCommand(
funcs.MustOk(destinationCk.GetChainID(ctx)),
funcs.MustOk(multisig.GetCurrentKeyID(ctx, destinationChain)),
funcs.MustOk(multisig.GetCurrentKeyID(ctx, destinationChain.Name)),
funcs.MustOk(n.GetChain(ctx, event.Chain)).Name,
event.TxID,
event.Index,
*e,
)
funcs.MustNoErr(destinationCk.EnqueueCommand(ctx, cmd))
bk.Logger(ctx).Debug(fmt.Sprintf("created %s command for event", cmd.Type),
"chain", destinationChain,
"chain", destinationChain.Name,
"eventID", event.GetID(),
"commandID", cmd.ID.Hex(),
)
Expand All @@ -112,50 +97,27 @@ func handleContractCallToEVM(ctx sdk.Context, bk types.BaseKeeper, multisig type
ContractAddress: e.ContractAddress,
PayloadHash: e.PayloadHash,
})

return nil
}

func handleContractCallWithToken(ctx sdk.Context, event types.Event, bk types.BaseKeeper, n types.Nexus, multisig types.MultisigKeeper) error {
e := event.GetContractCallWithToken()
e := event.GetEvent().(*types.Event_ContractCallWithToken).ContractCallWithToken
if e == nil {
panic(fmt.Errorf("event is nil"))
}

sourceChain := funcs.MustOk(n.GetChain(ctx, event.Chain))
destinationChain := funcs.MustOk(n.GetChain(ctx, e.DestinationChain))

sourceCk := funcs.Must(bk.ForChain(ctx, sourceChain.Name))
destinationCk := funcs.Must(bk.ForChain(ctx, destinationChain.Name))

token := sourceCk.GetERC20TokenBySymbol(ctx, e.Symbol)
if !token.Is(types.Confirmed) {
return fmt.Errorf("token with symbol %s not confirmed on source chain", e.Symbol)
}
asset := token.GetAsset()

if err := n.RateLimitTransfer(ctx, sourceChain.Name, sdk.NewCoin(asset, sdk.Int(e.Amount)), nexus.Incoming); err != nil {
return err
}

if err := n.RateLimitTransfer(ctx, destinationChain.Name, sdk.NewCoin(asset, sdk.Int(e.Amount)), nexus.Outgoing); err != nil {
return err
}

switch destinationChain.Module {
case types.ModuleName:
return handleContractCallWithTokenToEVM(ctx, event, bk, multisig, sourceChain.Name, destinationChain.Name, asset)
default:
coin := sdk.NewCoin(asset, sdk.Int(e.Amount))
// set as general message in nexus, so the dest module can handle the message
return setMessageToNexus(ctx, n, event, &coin)
}
}

func handleContractCallWithTokenToEVM(ctx sdk.Context, event types.Event, bk types.BaseKeeper, multisig types.MultisigKeeper, sourceChain, destinationChain nexus.ChainName, asset string) error {
e := event.GetContractCallWithToken()
if e == nil {
panic(fmt.Errorf("event is nil"))
}

destinationCk := funcs.Must(bk.ForChain(ctx, destinationChain))

asset := token.GetAsset()
destinationToken := destinationCk.GetERC20TokenByAsset(ctx, asset)
if !destinationToken.Is(types.Confirmed) {
return fmt.Errorf("token with asset %s not confirmed on destination chain", e.Symbol)
Expand All @@ -165,10 +127,18 @@ func handleContractCallWithTokenToEVM(ctx sdk.Context, event types.Event, bk typ
return fmt.Errorf("invalid contract address %s", e.ContractAddress)
}

if err := n.RateLimitTransfer(ctx, sourceChain.Name, sdk.NewCoin(asset, sdk.Int(e.Amount)), nexus.Incoming); err != nil {
return err
}

if err := n.RateLimitTransfer(ctx, destinationChain.Name, sdk.NewCoin(asset, sdk.Int(e.Amount)), nexus.Outgoing); err != nil {
return err
}

cmd := types.NewApproveContractCallWithMintCommand(
funcs.MustOk(destinationCk.GetChainID(ctx)),
funcs.MustOk(multisig.GetCurrentKeyID(ctx, destinationChain)),
sourceChain,
funcs.MustOk(multisig.GetCurrentKeyID(ctx, destinationChain.Name)),
sourceChain.Name,
event.TxID,
event.Index,
*e,
Expand All @@ -177,7 +147,7 @@ func handleContractCallWithTokenToEVM(ctx sdk.Context, event types.Event, bk typ
)
funcs.MustNoErr(destinationCk.EnqueueCommand(ctx, cmd))
bk.Logger(ctx).Debug(fmt.Sprintf("created %s command for event", cmd.Type),
"chain", destinationChain,
"chain", destinationChain.Name,
"eventID", event.GetID(),
"commandID", cmd.ID.Hex(),
)
Expand All @@ -196,42 +166,6 @@ func handleContractCallWithTokenToEVM(ctx sdk.Context, event types.Event, bk typ
return nil
}

func setMessageToNexus(ctx sdk.Context, n types.Nexus, event types.Event, asset *sdk.Coin) error {
var message nexus.GeneralMessage
switch e := event.GetEvent().(type) {
case *types.Event_ContractCall:
message = nexus.NewGeneralMessage(
string(event.GetID()),
event.Chain,
e.ContractCall.Sender.Hex(),
e.ContractCall.DestinationChain,
e.ContractCall.ContractAddress,
e.ContractCall.PayloadHash.Bytes(),
nexus.Approved,
nil,
)

case *types.Event_ContractCallWithToken:
if asset == nil {
return fmt.Errorf("expect asset for ContractCallWithToken")
}
message = nexus.NewGeneralMessage(
string(event.GetID()),
event.Chain,
e.ContractCallWithToken.Sender.Hex(),
e.ContractCallWithToken.DestinationChain,
e.ContractCallWithToken.ContractAddress,
e.ContractCallWithToken.PayloadHash.Bytes(),
nexus.Approved,
asset,
)
default:
return fmt.Errorf("unsupported event type %T", event)
}

return n.SetNewMessage(ctx, message)
}

func handleConfirmDeposit(ctx sdk.Context, event types.Event, bk types.BaseKeeper, n types.Nexus) error {
e := event.GetEvent().(*types.Event_Transfer).Transfer
if e == nil {
Expand Down Expand Up @@ -423,14 +357,11 @@ func handleMultisigTransferKey(ctx sdk.Context, event types.Event, bk types.Base

func validateEvent(ctx sdk.Context, event types.Event, bk types.BaseKeeper, n types.Nexus) error {
var destinationChainName nexus.ChainName
var contractAddress string
switch event := event.GetEvent().(type) {
case *types.Event_ContractCall:
destinationChainName = event.ContractCall.DestinationChain
contractAddress = event.ContractCall.ContractAddress
case *types.Event_ContractCallWithToken:
destinationChainName = event.ContractCallWithToken.DestinationChain
contractAddress = event.ContractCallWithToken.ContractAddress
case *types.Event_TokenSent:
destinationChainName = event.TokenSent.DestinationChain
case *types.Event_Transfer, *types.Event_TokenDeployed,
Expand All @@ -452,15 +383,11 @@ func validateEvent(ctx sdk.Context, event types.Event, bk types.BaseKeeper, n ty
return fmt.Errorf("destination chain de-activated")
}

// skip further destination chain keeper checks if it is not an evm chain
if !destinationChain.IsFrom(types.ModuleName) {
if event.GetTokenSent() != nil && !types.IsEVMChain(destinationChain) {
return nil
}

if len(contractAddress) != 0 && !common.IsHexAddress(contractAddress) {
return fmt.Errorf("invalid contract address")
}

// skip further checks and handle event if destination is not an evm chain
destinationCk, err := bk.ForChain(ctx, destinationChainName)
if err != nil {
return fmt.Errorf("destination chain not EVM-compatible")
Expand Down
Loading

0 comments on commit 6d58c07

Please sign in to comment.