Skip to content

Commit 3c64e6f

Browse files
authored
node: Make copy of message in msg_verifier (#4709)
1 parent 31027a0 commit 3c64e6f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

node/pkg/watchers/evm/msg_verifier.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ func verify(
3535
}
3636

3737
// Create a local copy of the MessagePublication.
38-
localMsg := msg
38+
localCopy := *msg
39+
localMsg := &localCopy
3940

4041
var newState common.VerificationState
4142

node/pkg/watchers/evm/watcher_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,30 @@ func (m *MockTransferVerifier[E, C]) Addrs() *txverifier.TVAddresses {
211211
}
212212
}
213213

214+
// TestVerifyDoesNotMutateOriginalMessage checks that verify() does not modify
215+
// the original MessagePublication passed to it.
216+
func TestVerifyDoesNotMutateOriginalMessage(t *testing.T) {
217+
tbAddr, err := vaa.BytesToAddress([]byte{0x01})
218+
require.NoError(t, err)
219+
220+
msg := &common.MessagePublication{
221+
EmitterAddress: tbAddr,
222+
}
223+
require.Equal(t, common.NotVerified.String(), msg.VerificationState().String())
224+
225+
successMock := &MockTransferVerifier[ethclient.Client, connectors.Connector]{true}
226+
ctx := context.TODO()
227+
228+
result, err := verify(ctx, msg, eth_common.Hash{}, &types.Receipt{}, successMock)
229+
require.NoError(t, err)
230+
231+
// The returned copy should have the updated verification state.
232+
require.Equal(t, common.Valid.String(), result.VerificationState().String())
233+
234+
// The original message must remain unmodified.
235+
require.Equal(t, common.NotVerified.String(), msg.VerificationState().String())
236+
}
237+
214238
func TestConsistencyLevelMatches(t *testing.T) {
215239
// Success cases.
216240
assert.True(t, consistencyLevelMatches(vaa.ConsistencyLevelPublishImmediately, vaa.ConsistencyLevelPublishImmediately))

0 commit comments

Comments
 (0)