Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* [3914](https://github.com/zeta-chain/node/pull/3914) - check tx result err in filter inbound events
* [3904](https://github.com/zeta-chain/node/pull/3904) - improve observer emissions distribution to maximise pool utilisation
* [3895](https://github.com/zeta-chain/node/pull/3895) - solana call required accounts number condition
* [3896](https://github.com/zeta-chain/node/pull/3896) - add sender to solana execute message hash

### Tests

Expand Down
Binary file modified contrib/localnet/solana/gateway.so
Binary file not shown.
12 changes: 12 additions & 0 deletions pkg/contracts/solana/gateway_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ func (msg *MsgExecute) Hash() [32]byte {

message = append(message, msg.to.Bytes()...)

if msg.executeType == ExecuteTypeCall {
message = append(message, common.HexToAddress(msg.sender).Bytes()...)
} else {
message = append(message, solana.MustPublicKeyFromBase58(msg.sender).Bytes()...)
}

message = append(message, msg.data...)

return crypto.Keccak256Hash(message)
Expand Down Expand Up @@ -648,6 +654,12 @@ func (msg *MsgExecuteSPL) Hash() [32]byte {

message = append(message, msg.recipientAta.Bytes()...)

if msg.executeType == ExecuteTypeCall {
message = append(message, common.HexToAddress(msg.sender).Bytes()...)
} else {
message = append(message, solana.MustPublicKeyFromBase58(msg.sender).Bytes()...)
}

message = append(message, msg.data...)

return crypto.Keccak256Hash(message)
Expand Down
16 changes: 8 additions & 8 deletions pkg/contracts/solana/gateway_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func Test_MsgExecuteHash(t *testing.T) {
to := solana.MustPublicKeyFromBase58("37yGiHAnLvWZUNVwu9esp74YQFqxU1qHCbABkDvRddUQ")
sender := common.HexToAddress("0x42bd6E2ce4CDb2F58Ed0A0E427F011A0645D5E33")

wantHash := "7391cf357fd80e7cb3d2a9758932fdea4988d03c87210a2632f03b467728d199"
wantHash := "ff0737262c010614dead18a4ed152ca38bd92aae694f08ba611cea307f3d92d9"
wantHashBytes := testutil.HexToBytes(t, wantHash)

// ACT
Expand All @@ -134,7 +134,7 @@ func Test_MsgExecuteSPLHash(t *testing.T) {
require.NoError(t, err)
sender := common.HexToAddress("0x42bd6E2ce4CDb2F58Ed0A0E427F011A0645D5E33")

wantHash := "d90f9640faecd76509b4e88fa7d18f130918130b8666179f1597f185a828d3a5"
wantHash := "8ed9d12294399703611bf6b4d131aa0cdd9b1c2ca7e2586238c47929766ed0b9"
wantHashBytes := testutil.HexToBytes(t, wantHash)

// ACT
Expand All @@ -155,14 +155,14 @@ func Test_MsgExecuteRevertHash(t *testing.T) {
nonce := uint64(0)
amount := uint64(1336000)
to := solana.MustPublicKeyFromBase58("37yGiHAnLvWZUNVwu9esp74YQFqxU1qHCbABkDvRddUQ")
sender := common.HexToAddress("0x42bd6E2ce4CDb2F58Ed0A0E427F011A0645D5E33")
sender := solana.MustPublicKeyFromBase58("CVoPuE3EMu6QptGHLx7mDGb2ZgASJRQ5BcTvmhZNJd8A")

wantHash := "A55A5E8E302D5BA9A4C2DCDE54225F45F5E20081873AA7F6A3A361DB20527E31"
wantHash := "8a84b88736c9b677b1d859b212bd07f9808f8ca07682b3585eb1b6c5f2f6f4dd"
wantHashBytes := testutil.HexToBytes(t, wantHash)

// ACT
// create new execute message
hash := contracts.NewMsgExecute(chainID, nonce, amount, to, sender.Hex(), []byte("hello"), contracts.ExecuteTypeRevert, []*solana.AccountMeta{}).
hash := contracts.NewMsgExecute(chainID, nonce, amount, to, sender.String(), []byte("hello"), contracts.ExecuteTypeRevert, []*solana.AccountMeta{}).
Hash()

// ASSERT
Expand All @@ -180,14 +180,14 @@ func Test_MsgExecuteSPLRevertHash(t *testing.T) {
to := solana.MustPublicKeyFromBase58("37yGiHAnLvWZUNVwu9esp74YQFqxU1qHCbABkDvRddUQ")
toAta, _, err := solana.FindAssociatedTokenAddress(to, mintAccount)
require.NoError(t, err)
sender := common.HexToAddress("0x42bd6E2ce4CDb2F58Ed0A0E427F011A0645D5E33")
sender := solana.MustPublicKeyFromBase58("CVoPuE3EMu6QptGHLx7mDGb2ZgASJRQ5BcTvmhZNJd8A")

wantHash := "C27871066FB9F28387E39281F267688FC54CE584F321891454503B17C3353B11"
wantHash := "147f471f794e0227653f69c40d9ac0ab278ac8549de41d9229e9b6ca14735c57"
wantHashBytes := testutil.HexToBytes(t, wantHash)

// ACT
// create new execute message
hash := contracts.NewMsgExecuteSPL(chainID, nonce, amount, 8, mintAccount, to, toAta, sender.Hex(), []byte("hello"), contracts.ExecuteTypeRevert, []*solana.AccountMeta{}).
hash := contracts.NewMsgExecuteSPL(chainID, nonce, amount, 8, mintAccount, to, toAta, sender.String(), []byte("hello"), contracts.ExecuteTypeRevert, []*solana.AccountMeta{}).
Hash()

// ASSERT
Expand Down
28 changes: 27 additions & 1 deletion zetaclient/chains/solana/signer/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"context"
"fmt"

"cosmossdk.io/errors"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -74,6 +75,12 @@
return nil, nil, errors.Wrapf(err, "cannot decode receiver address %s", params.Receiver)
}

// check sender based on execute type
sender, err := validateSender(cctx.InboundParams.Sender, executeType)
if err != nil {
return nil, nil, errors.Wrap(err, "cannot validate sender")
}

Check warning on line 82 in zetaclient/chains/solana/signer/execute.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/execute.go#L79-L82

Added lines #L79 - L82 were not covered by tests

remainingAccounts := []*solana.AccountMeta{}
for _, a := range msg.Accounts {
remainingAccounts = append(remainingAccounts, &solana.AccountMeta{
Expand All @@ -87,7 +94,7 @@
nonce,
amount,
to,
cctx.InboundParams.Sender,
sender,

Check warning on line 97 in zetaclient/chains/solana/signer/execute.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/execute.go#L97

Added line #L97 was not covered by tests
msg.Data,
executeType,
remainingAccounts,
Expand Down Expand Up @@ -158,3 +165,22 @@

return inst, nil
}

// validateSender validates and formats the sender address based on execute type
func validateSender(sender string, executeType contracts.ExecuteType) (string, error) {
if executeType == contracts.ExecuteTypeCall {
// for regular execute, sender should be an Ethereum address
senderEth := common.HexToAddress(sender)
if senderEth == (common.Address{}) {
return "", fmt.Errorf("invalid execute sender %s", sender)
}
return senderEth.Hex(), nil

Check warning on line 177 in zetaclient/chains/solana/signer/execute.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/execute.go#L170-L177

Added lines #L170 - L177 were not covered by tests
}

// for revert execute, sender should be a Solana address
senderSol, err := solana.PublicKeyFromBase58(sender)
if err != nil {
return "", errors.Wrapf(err, "invalid execute revert sender %s", sender)
}
return senderSol.String(), nil

Check warning on line 185 in zetaclient/chains/solana/signer/execute.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/execute.go#L181-L185

Added lines #L181 - L185 were not covered by tests
}
8 changes: 7 additions & 1 deletion zetaclient/chains/solana/signer/execute_spl.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
return nil, nil, errors.Wrapf(err, "cannot decode receiver address %s", params.Receiver)
}

// check sender based on execute type
sender, err := validateSender(cctx.InboundParams.Sender, executeType)
if err != nil {
return nil, nil, errors.Wrap(err, "cannot validate sender")
}

Check warning on line 87 in zetaclient/chains/solana/signer/execute_spl.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/execute_spl.go#L84-L87

Added lines #L84 - L87 were not covered by tests

// parse mint account
mintAccount, err := solana.PublicKeyFromBase58(cctx.InboundParams.Asset)
if err != nil {
Expand Down Expand Up @@ -119,7 +125,7 @@
mintAccount,
to,
destinationProgramPdaAta,
cctx.InboundParams.Sender,
sender,

Check warning on line 128 in zetaclient/chains/solana/signer/execute_spl.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/execute_spl.go#L128

Added line #L128 was not covered by tests
msg.Data,
executeType,
remainingAccounts,
Expand Down
7 changes: 6 additions & 1 deletion zetaclient/chains/solana/signer/withdraw_spl.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@
}

func (signer *Signer) decodeMintAccountDetails(ctx context.Context, asset string) (token.Mint, error) {
info, err := signer.client.GetAccountInfo(ctx, solana.MustPublicKeyFromBase58(asset))
mintPk, err := solana.PublicKeyFromBase58(asset)
if err != nil {
return token.Mint{}, err
}

Check warning on line 149 in zetaclient/chains/solana/signer/withdraw_spl.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/withdraw_spl.go#L146-L149

Added lines #L146 - L149 were not covered by tests

info, err := signer.client.GetAccountInfo(ctx, mintPk)

Check warning on line 151 in zetaclient/chains/solana/signer/withdraw_spl.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/withdraw_spl.go#L151

Added line #L151 was not covered by tests
if err != nil {
return token.Mint{}, err
}
Expand Down