Skip to content

Commit

Permalink
fix: SetGatewayAddress might set invalid gateway address (#3030)
Browse files Browse the repository at this point in the history
* fix SetGatewayAddress

* add changelog entry

* fix gosec
  • Loading branch information
ws4charlie authored Oct 22, 2024
1 parent 0f8a4c2 commit 93ebef4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* [2925](https://github.com/zeta-chain/node/pull/2925) - add recover to init chainer to diplay informative message when starting a node from block 1
* [2909](https://github.com/zeta-chain/node/pull/2909) - add legacy messages back to codec for querier backward compatibility
* [3018](https://github.com/zeta-chain/node/pull/3018) - support `DepositAndCall` and `WithdrawAndCall` with empty payload
* [3030](https://github.com/zeta-chain/node/pull/3030) - Avoid storing invalid Solana gateway address in the `SetGatewayAddress`

## v20.0.0

Expand Down
2 changes: 1 addition & 1 deletion tests/simulation/sim/sim_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func AppStateFromGenesisFileFn(
cdc codec.JSONCodec,
genesisFile string,
) (tmtypes.GenesisDoc, []simtypes.Account, error) {
bytes, err := os.ReadFile(genesisFile)
bytes, err := os.ReadFile(genesisFile) // #nosec G304 -- genesisFile value is controlled
if err != nil {
panic(err)
}
Expand Down
3 changes: 2 additions & 1 deletion zetaclient/chains/solana/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ func (signer *Signer) SetGatewayAddress(address string) {
// parse gateway ID and PDA
gatewayID, pda, err := contracts.ParseGatewayIDAndPda(address)
if err != nil {
signer.Logger().Std.Error().Err(err).Msgf("cannot parse gateway address %s", address)
signer.Logger().Std.Error().Err(err).Msgf("cannot parse gateway address: %s", address)
return
}

// update gateway ID and PDA
Expand Down
42 changes: 42 additions & 0 deletions zetaclient/chains/solana/signer/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,48 @@ func Test_NewSigner(t *testing.T) {
}
}

func Test_SetGatewayAddress(t *testing.T) {
// test parameters
chain := chains.SolanaDevnet
chainParams := sample.ChainParams(chain.ChainId)
chainParams.GatewayAddress = testutils.GatewayAddresses[chain.ChainId]

// helper functor to create signer
signerCreator := func() *signer.Signer {
s, err := signer.NewSigner(chain, *chainParams, nil, nil, nil, nil, base.DefaultLogger())
require.NoError(t, err)
return s
}

// test cases
tests := []struct {
name string
signer *signer.Signer
newAddress string
expected string
}{
{
name: "should set new gateway address",
signer: signerCreator(),
newAddress: "9Z5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d",
expected: "9Z5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d",
},
{
name: "should not set invalid gateway address",
signer: signerCreator(),
newAddress: "invalid",
expected: chainParams.GatewayAddress,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.signer.SetGatewayAddress(tt.newAddress)
require.Equal(t, tt.expected, tt.signer.GetGatewayAddress())
})
}
}

func Test_SetRelayerBalanceMetrics(t *testing.T) {
// test parameters
chain := chains.SolanaDevnet
Expand Down

0 comments on commit 93ebef4

Please sign in to comment.