@@ -67,7 +67,7 @@ func (k Keeper) verifySVMInteraction(ctx context.Context, ownerKey, txHash strin
6767
6868 programID := tx .Transaction .Message .AccountKeys [instruction .ProgramIDIndex ]
6969
70- if strings . EqualFold (programID , chainConfig .GatewayAddress ) {
70+ if compareSolanaAddresses (programID , chainConfig .GatewayAddress ) {
7171 foundGatewayCall = true
7272
7373 // Verify the instruction has the required accounts
@@ -102,8 +102,7 @@ func (k Keeper) verifySVMInteraction(ctx context.Context, ownerKey, txHash strin
102102 // Get the expected discriminator from chain config
103103 var expectedDiscriminator []byte
104104 for _ , method := range chainConfig .GatewayMethods {
105- if method .Name == "add_funds" {
106- // Convert hex string to bytes
105+ if method .Name == types .METHOD .SVM .AddFunds { // Convert hex string to bytes
107106 expectedDiscriminator , err = hex .DecodeString (method .Identifier )
108107 if err != nil {
109108 return fmt .Errorf ("invalid discriminator in chain config: %w" , err )
@@ -171,10 +170,25 @@ func (k Keeper) verifySVMAndGetFunds(ctx context.Context, ownerKey, txHash strin
171170 if len (tx .Transaction .Message .Instructions ) == 0 {
172171 return * big .NewInt (0 ), 0 , fmt .Errorf ("no instructions found in transaction" )
173172 }
174- programID := tx .Transaction .Message .AccountKeys [tx .Transaction .Message .Instructions [0 ].ProgramIDIndex ]
175173
176- if ! strings .EqualFold (programID , chainConfig .GatewayAddress ) {
177- return * big .NewInt (0 ), 0 , fmt .Errorf ("transaction program ID %s does not match gateway contract %s" , programID , chainConfig .GatewayAddress )
174+ // Check if any instruction calls the gateway contract
175+ foundGatewayCall := false
176+ for _ , instruction := range tx .Transaction .Message .Instructions {
177+ // Verify program ID index is valid
178+ if instruction .ProgramIDIndex < 0 || instruction .ProgramIDIndex >= len (tx .Transaction .Message .AccountKeys ) {
179+ return * big .NewInt (0 ), 0 , fmt .Errorf ("invalid program ID index: %d" , instruction .ProgramIDIndex )
180+ }
181+
182+ programID := tx .Transaction .Message .AccountKeys [instruction .ProgramIDIndex ]
183+
184+ if compareSolanaAddresses (programID , chainConfig .GatewayAddress ) {
185+ foundGatewayCall = true
186+ break
187+ }
188+ }
189+
190+ if ! foundGatewayCall {
191+ return * big .NewInt (0 ), 0 , fmt .Errorf ("no instruction found calling the gateway contract %s" , chainConfig .GatewayAddress )
178192 }
179193
180194 // Step 2: Verify confirmations
@@ -197,8 +211,7 @@ func (k Keeper) verifySVMAndGetFunds(ctx context.Context, ownerKey, txHash strin
197211 // Get the event discriminator from chain config
198212 var eventDiscriminator []byte
199213 for _ , method := range chainConfig .GatewayMethods {
200- if method .Name == "add_funds" {
201- // Convert hex string to bytes
214+ if method .Name == types .METHOD .SVM .AddFunds {
202215 eventDiscriminator , err = hex .DecodeString (method .EventIdentifier )
203216 if err != nil {
204217 return * big .NewInt (0 ), 0 , fmt .Errorf ("invalid event discriminator in chain config: %w" , err )
@@ -261,6 +274,13 @@ func (k Keeper) verifySVMAndGetFunds(ctx context.Context, ownerKey, txHash strin
261274 return * usdAmount , decimals , nil
262275}
263276
277+ // compareSolanaAddresses compares two Solana addresses by decoding them to raw bytes
278+ func compareSolanaAddresses (addr1 , addr2 string ) bool {
279+ bytes1 := base58 .Decode (addr1 )
280+ bytes2 := base58 .Decode (addr2 )
281+ return bytes1 != nil && bytes2 != nil && bytes .Equal (bytes1 , bytes2 )
282+ }
283+
264284// readI128LE decodes a little-endian i128 value from Anchor logs
265285func readI128LE (b []byte ) * big.Int {
266286 if len (b ) != 16 {
0 commit comments