Repository: shardeum/shardeum
File: src/setup/validateTxnFields.ts (TypeScript)

Code before:
          }
        } else {
          try {
            success = crypto.verifyObj(internalTX)
          } catch (e) {
            reason = 'Invalid signature for internal tx'
          }
        }
        if (ShardeumFlags.VerboseLogs) console.log('validateTxsField', success, reason)
        return {
          success,
          reason,
          txnTimestamp: txnTimestamp,
        }
      }

      // Validate EVM tx fields
      let success = false
      let reason = 'Invalid EVM transaction fields'

      try {
        const transaction = getTransactionObj(tx)
        const isSigned = transaction.isSigned()
        const {
          address: senderAddress,
          isValid: isAddressValid,
          gasValid,
        } = getTxSenderAddress(transaction, txId) // ensures that tx is valid
        if (ShardeumFlags.VerboseLogs) console.log('validate evm tx', isSigned, isAddressValid)

        //const txId = '0x' + crypto.hashObj(timestampedTx.tx)
        const txHash = bytesToHex(transaction.hash())

        //limit debug app data size.  (a queue would be nicer, but this is very simple)
        if (debugAppdata.size > 1000) {
          debugAppdata.clear()
        }
        debugAppdata.set(txHash, appData)

        if (!gasValid) {
          nestedCountersInstance.countEvent('shardeum', 'validate - insufficient gas')
          return {
            success: false,
            reason: 'Not enough gas to execute transaction',
            txnTimestamp,
          }
        } else if (!isSigned) {
          nestedCountersInstance.countEvent('shardeum', 'validate - sign missing')
          return {
            success: false,
            reason: 'Transaction is not signed',

Review comment (bug):
this could be the signature or the address that are invalid. The name doesn't match the counter or the fail reason
`nestedCountersInstance.countEvent('shardeum', 'validate - sign failed')`
`reason: 'Transaction signature is invalid',`

Code after:
          }
        } else {
          try {
            success = crypto.verifyObj(internalTX)
          } catch (e) {
            reason = 'Invalid signature for internal tx'
          }
        }
        if (ShardeumFlags.VerboseLogs) console.log('validateTxsField', success, reason)
        return {
          success,
          reason,
          txnTimestamp: txnTimestamp,
        }
      }

      // Validate EVM tx fields
      let success = false
      let reason = 'Invalid EVM transaction fields'

      try {
        const transaction = getTransactionObj(tx)
        const isSigned = transaction.isSigned()
        const {
          address: senderAddress,
          isValid: isSignatureValid,
          gasValid,
        } = getTxSenderAddress(transaction, txId) // ensures that tx is valid
        if (ShardeumFlags.VerboseLogs) console.log('validate evm tx', isSigned, isSignatureValid)

        //const txId = '0x' + crypto.hashObj(timestampedTx.tx)
        const txHash = bytesToHex(transaction.hash())

        //limit debug app data size.  (a queue would be nicer, but this is very simple)
        if (debugAppdata.size > 1000) {
          debugAppdata.clear()
        }
        debugAppdata.set(txHash, appData)

        if (!gasValid) {
          nestedCountersInstance.countEvent('shardeum', 'validate - insufficient gas')
          return {
            success: false,
            reason: 'Not enough gas to execute transaction',
            txnTimestamp,
          }
        } else if (!isSigned) {
          nestedCountersInstance.countEvent('shardeum', 'validate - sign missing')
          return {
            success: false,
            reason: 'Transaction is not signed',