diff --git a/changelog.md b/changelog.md index 7a58845753..bd207b53d6 100644 --- a/changelog.md +++ b/changelog.md @@ -15,6 +15,7 @@ * [3534] (https://github.com/zeta-chain/node/pull/3534) - Add Sui deposit & depositAndCall * [3541](https://github.com/zeta-chain/node/pull/3541) - implement `MsgUpdateZRC20Name` to update the name or symbol of a ZRC20 token * [3520](https://github.com/zeta-chain/node/pull/3520) - SPL withdraw and call integration +* [3439](https://github.com/zeta-chain/node/pull/3439) - use protocol contracts V2 with TON deposits * [3522](https://github.com/zeta-chain/node/pull/3522) - add `MsgDisableFastConfirmation` to disable fast confirmation. This message can be triggered by the emergency policy. ### Refactor diff --git a/e2e/runner/ton.go b/e2e/runner/ton.go index 369bfa0df3..97b0a6d472 100644 --- a/e2e/runner/ton.go +++ b/e2e/runner/ton.go @@ -113,12 +113,9 @@ func (r *E2ERunner) TONDepositAndCall( } filter := func(cctx *cctypes.CrossChainTx) bool { - memo := zevmRecipient.Bytes() - memo = append(memo, callData...) - return cctx.InboundParams.SenderChainId == chain.ChainId && cctx.InboundParams.Sender == sender.GetAddress().ToRaw() && - cctx.RelayedMessage == hex.EncodeToString(memo) + cctx.RelayedMessage == hex.EncodeToString(callData) } // Wait for cctx diff --git a/pkg/contracts/ton/gateway_msg.go b/pkg/contracts/ton/gateway_msg.go index 3a4716e0b4..fd68ca0eec 100644 --- a/pkg/contracts/ton/gateway_msg.go +++ b/pkg/contracts/ton/gateway_msg.go @@ -57,11 +57,6 @@ type Deposit struct { Recipient eth.Address } -// Memo casts deposit to memo bytes -func (d Deposit) Memo() []byte { - return d.Recipient.Bytes() -} - // AsBody casts struct as internal message body. func (d Deposit) AsBody() (*boc.Cell, error) { b := boc.NewCell() @@ -75,17 +70,6 @@ type DepositAndCall struct { CallData []byte } -// Memo casts deposit to call to memo bytes -func (d DepositAndCall) Memo() []byte { - recipient := d.Recipient.Bytes() - out := make([]byte, 0, len(recipient)+len(d.CallData)) - - out = append(out, recipient...) - out = append(out, d.CallData...) - - return out -} - // AsBody casts struct to internal message body. func (d DepositAndCall) AsBody() (*boc.Cell, error) { b := boc.NewCell() diff --git a/testutil/sample/ton_test.go b/testutil/sample/ton_test.go index 73474db0d4..48e45047ff 100644 --- a/testutil/sample/ton_test.go +++ b/testutil/sample/ton_test.go @@ -59,7 +59,6 @@ func TestTONSamples(t *testing.T) { require.Equal(t, int(d.Amount.Uint64()), int(d2.Amount.Uint64())) require.Equal(t, d.Sender.ToRaw(), d2.Sender.ToRaw()) require.Equal(t, d.Recipient.Hex(), d2.Recipient.Hex()) - require.Equal(t, d.Memo(), d2.Memo()) }) t.Run("Deposit and call", func(t *testing.T) { @@ -88,7 +87,6 @@ func TestTONSamples(t *testing.T) { require.Equal(t, d.Sender.ToRaw(), d2.Sender.ToRaw()) require.Equal(t, d.Recipient.Hex(), d2.Recipient.Hex()) require.Equal(t, d.CallData, d2.CallData) - require.Equal(t, d.Memo(), d2.Memo()) }) } diff --git a/zetaclient/chains/ton/observer/inbound.go b/zetaclient/chains/ton/observer/inbound.go index 2d4ecfb124..de0510dd18 100644 --- a/zetaclient/chains/ton/observer/inbound.go +++ b/zetaclient/chains/ton/observer/inbound.go @@ -177,6 +177,15 @@ func (ob *Observer) ProcessInboundTrackers(ctx context.Context) error { return nil } +// inboundData represents extract data from a TON inbound deposit +type inboundData struct { + sender string + amount math.Uint + receiver string + message []byte + isContractCall bool +} + // Sends PostVoteInbound to zetacore func (ob *Observer) voteInbound(ctx context.Context, tx *toncontracts.Transaction) (string, error) { // noop @@ -193,44 +202,52 @@ func (ob *Observer) voteInbound(ctx context.Context, tx *toncontracts.Transactio return "", errors.Wrapf(err, "unable to get block header %s", tx.BlockID.String()) } - sender, amount, memo, err := extractInboundData(tx) + inboundData, err := extractInboundData(tx) if err != nil { return "", err } seqno := blockHeader.MinRefMcSeqno - return ob.voteDeposit(ctx, tx, sender, amount, memo, seqno) + return ob.voteDeposit(ctx, tx, inboundData, seqno) } // extractInboundData parses Gateway tx into deposit (TON sender, amount, memo) -func extractInboundData(tx *toncontracts.Transaction) (string, math.Uint, []byte, error) { +func extractInboundData(tx *toncontracts.Transaction) (inboundData, error) { switch tx.Operation { case toncontracts.OpDeposit: d, err := tx.Deposit() if err != nil { - return "", math.NewUint(0), nil, err + return inboundData{}, err } - - return d.Sender.ToRaw(), d.Amount, d.Memo(), nil + return inboundData{ + sender: d.Sender.ToRaw(), + amount: d.Amount, + receiver: d.Recipient.Hex(), + message: []byte{}, + isContractCall: false, + }, nil case toncontracts.OpDepositAndCall: d, err := tx.DepositAndCall() if err != nil { - return "", math.NewUint(0), nil, err + return inboundData{}, err } - - return d.Sender.ToRaw(), d.Amount, d.Memo(), nil + return inboundData{ + sender: d.Sender.ToRaw(), + amount: d.Amount, + receiver: d.Recipient.Hex(), + message: d.CallData, + isContractCall: true, + }, nil default: - return "", math.NewUint(0), nil, fmt.Errorf("unknown operation %d", tx.Operation) + return inboundData{}, fmt.Errorf("unknown operation %d", tx.Operation) } } func (ob *Observer) voteDeposit( ctx context.Context, tx *toncontracts.Transaction, - sender string, - amount math.Uint, - memo []byte, + inboundData inboundData, seqno uint32, ) (string, error) { const ( @@ -246,25 +263,27 @@ func (ob *Observer) voteDeposit( inboundHash = liteapi.TransactionHashToString(tx.Lt, ton.Bits256(tx.Hash())) ) - // TODO: use protocol contract v2 for deposit - // https://github.com/zeta-chain/node/issues/2967 - - msg := zetacore.GetInboundVoteMessage( - sender, + // create the inbound message + msg := types.NewMsgVoteInbound( + operatorAddress.String(), + inboundData.sender, ob.Chain().ChainId, - sender, - sender, + inboundData.sender, + inboundData.receiver, ob.ZetacoreClient().Chain().ChainId, - amount, - hex.EncodeToString(memo), + inboundData.amount, + hex.EncodeToString(inboundData.message), inboundHash, uint64(seqno), gasLimit, coinType, asset, - operatorAddress.String(), eventIndex, + types.ProtocolContractVersion_V2, + false, // not used types.InboundStatus_SUCCESS, + types.ConfirmationMode_SAFE, + types.WithCrossChainCall(inboundData.isContractCall), ) return ob.PostVoteInbound(ctx, msg, retryGasLimit) diff --git a/zetaclient/chains/ton/observer/inbound_test.go b/zetaclient/chains/ton/observer/inbound_test.go index 10b6443fb3..ae46c07c22 100644 --- a/zetaclient/chains/ton/observer/inbound_test.go +++ b/zetaclient/chains/ton/observer/inbound_test.go @@ -2,7 +2,6 @@ package observer import ( "encoding/hex" - "fmt" "testing" "github.com/pkg/errors" @@ -163,7 +162,9 @@ func TestInbound(t *testing.T) { assert.Equal(t, "", cctx.Asset) assert.Equal(t, deposit.Amount.Uint64(), cctx.Amount.Uint64()) - assert.Equal(t, hex.EncodeToString(deposit.Recipient.Bytes()), cctx.Message) + assert.Equal(t, "", cctx.Message) + assert.Equal(t, deposit.Recipient.Hex(), cctx.Receiver) + assert.False(t, cctx.IsCrossChainCall) // Check hash & block height expectedHash := liteapi.TransactionHashToString(depositTX.Lt, txHash(depositTX)) @@ -225,13 +226,9 @@ func TestInbound(t *testing.T) { assert.Equal(t, "", cctx.Asset) assert.Equal(t, depositAndCall.Amount.Uint64(), cctx.Amount.Uint64()) - - expectedMessage := hex.EncodeToString(append( - depositAndCall.Recipient.Bytes(), - []byte(callData)..., - )) - - assert.Equal(t, expectedMessage, cctx.Message) + assert.Equal(t, hex.EncodeToString([]byte(callData)), cctx.Message) + assert.Equal(t, depositAndCall.Recipient.Hex(), cctx.Receiver) + assert.True(t, cctx.IsCrossChainCall) // Check hash & block height expectedHash := liteapi.TransactionHashToString(depositAndCallTX.Lt, txHash(depositAndCallTX)) @@ -436,9 +433,8 @@ func TestInboundTracker(t *testing.T) { vote := ts.votesBag[0] assert.Equal(t, deposit.Amount, vote.Amount) assert.Equal(t, deposit.Sender.ToRaw(), vote.Sender) - - // zevm recipient bytes == memo bytes - assert.Equal(t, fmt.Sprintf("%x", deposit.Recipient), vote.Message) + assert.Equal(t, "", vote.Message) + assert.Equal(t, deposit.Recipient.Hex(), vote.Receiver) } func txHash(tx ton.Transaction) ton.Bits256 {