Method and system for modifying program code

WO2025023855A1PCT designated stage expired Publication Date: 2025-01-30PUBLICHNOE AKTSIONERNOE OBSHCHESTVO SBERBANK ROSSII (PAO SBERBANK)
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
PCT/RU2023/000223
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-07-24
Filing Date
2023-07-24
Publication Date
2025-01-30

Smart Images

  • Figure RU2023000223_30012025_PF_FP_ABST
    Figure RU2023000223_30012025_PF_FP_ABST
Patent Text Reader

Abstract

The invention relates to modifying program code. The steps of the present method (100) include: obtaining data containing at least a block of source code (101); converting said source code into a program code graph in which the internal vertices are associated with programming language operators and the leaves are associated with corresponding operands (102); processing said graph using a machine learning (ML) coding model trained on graphs, and obtaining, in the process, a representation of the graph in the form of a latency matrix (103); additionally processing said latency matrix using an ML generative model trained on latency matrices of graphs of unmodified program code and graphs of modified code and the source codes thereof, and obtaining, in the process, a new program code graph that corresponds to a modified program code equivalent to the initial program code in terms of the functions performed (104); converting the graph obtained in the preceding step into a block of modified source code equivalent in terms of function to the initial block of source code (105). This increases program code modification speed by virtue of automating the process.
Need to check novelty before this filing date? Find Prior Art

Description

METHOD AND SYSTEM FOR MODIFYING PROGRAM CODE AREA OF TECHNOLOGY

[0001] The claimed technical solution generally relates to the field of computer technology, and in particular to an automated method and system for modifying program code using machine learning algorithms. LEVEL OF TECHNOLOGY

[0002] With the development of information technology, IT solutions (“Information technology” - information technologies) have begun to exert a significant influence on all spheres and branches of life. Currently, various companies and organizations are actively implementing and using GG solutions in their structure.

[0003] Developing software for large financial organizations (such as banks) is always labor-intensive and painstaking work. After the release of software, there is often a need to optimize the program code. Optimization allows you to speed up the software process, fix critical errors, and increase software performance many times over.

[0004] The prior art includes patent US 8234636 B2 “Source code modification technique”, patent holder: IBM, published: 29.05.2008. This solution describes the process of modifying (optimizing) code to improve software performance. The known solution provides a process of modifying source code to improve performance. Before applying a modification to the program code, the programmer checks the changes and confirms them.

[0005] The disadvantage of known solutions in this area of ​​technology is the lack of the ability to automatically modify the program code. DISCLOSURE OF INVENTION

[0006] The declared technical solution proposes a new approach to the process of modifying program code. This solution uses a machine learning algorithm that allows automating the process of modifying program code and significantly speed up the process of optimizing program code in software.

[0007] Thus, the technical problem of automated modification of program code is solved.

[0008] The technical result achieved by solving this problem is an increase in the speed of modification of program code due to automation of the process.

[0009] The specified technical result is achieved by implementing a computer-implemented method for modifying program code, executed using at least one processor and containing stages in which: - receive data containing at least a block of source code; - transform the source code into a program code graph in which the internal nodes are associated with programming language operators, and the leaves with the corresponding operands; - process the program code graph using a machine learning (ML) coding model trained on program code graphs, during which a representation of the program code graph is obtained in the form of a matrix of hidden states; - process the matrix of hidden states using a generative machine learning (ML) model trained on the matrices of hidden states of graphs of unmodified program code, graphs of modified code and their source codes, during which a new graph of program code is obtained that corresponds to the modified program code, equivalent to the source program code in terms of the functions performed; - translate the program code graph obtained at the previous stage into a block of modified source code, equivalent in functionality to the original block of source code.

[0010] In one particular embodiment of the method, the source code is converted into an abstract syntax tree (AST), in which the internal nodes are mapped to programming language operators, and the leaves to the corresponding operands. [OOP] In another particular embodiment of the method, the source code is transformed into a control flow graph (CFG), in which the internal nodes are associated with programming language operators, and the leaves with the corresponding operands.

[0012] In another particular embodiment of the method, the source code is transformed into a data dependency graph (DDG), in which the internal nodes are associated with programming language operators, and the leaves with the corresponding operands.

[0013] In another particular embodiment of the method, the source code is converted into a representation based on static single assignment (SSA).

[0014] In another particular embodiment of the method, the source code is converted into a code property graph (CPG).

[0015] In addition, the stated technical result is achieved through a system of modification of program code containing: - at least one processor; - at least one memory connected to the processor, which contains machine-readable instructions that, when executed by at least one processor, ensure the execution of the claimed method. BRIEF DESCRIPTION OF DRAWINGS

[0016] Fig. 1 illustrates a block diagram of the claimed method.

[0017] Fig. 2 illustrates an example of the general appearance of a computing system that ensures the implementation of the claimed solution. IMPLEMENTATION OF THE INVENTION

[0001] Below we will describe the concepts and terms necessary for understanding this technical solution.

[0002] A model in machine learning (ML) is a set of artificial intelligence methods whose characteristic feature is not a direct solution to a problem, but learning in the process of applying solutions to many similar problems.

[0003] Modification of program code (optimization of program code) - various methods of transforming code in order to improve its characteristics and increase efficiency. The goals of optimization (modification) are to reduce the amount of code, reduce the amount of RAM used by the program, speed up the program, and reduce the number of input-output operations.

[0004] Exploit - a computer program, fragment of program code, or sequence of commands that takes advantage of vulnerabilities in software and is used to carry out an attack on a computing system.

[0005] Exploitable vulnerability - A vulnerability in software for which an exploit can be created and applied.

[0006] AST - Abstract Syntax Tree. A finite labeled oriented tree in which internal nodes are mapped to programming language operators and leaves to corresponding operands.

[0007] The F-1 measure is a joint assessment of precision and recall.

[0008] ROC curve is a graphical characteristic of the quality of a binary classifier, reflecting the dependence of the proportion of true-positive classifications on the proportion of false-positive classifications when varying the threshold of the decision rule.

[0009] A confusion matrix is ​​a way to divide the objects being classified into four categories depending on the combination of the actual class and the classifier response.

[0010] Connectors are software components that collect data from information sources (Task Management System / Release Collaboration System / Version Management System / Project Management System / Enterprise Service Management System / etc.) and convert the data to the required structure and format. [OOP] Storage - a system for storing large volumes of data collected and processed by connectors, as well as data generated by other system components.

[0012] This technical solution can be implemented on a computer, in the form of an automated information system (AIS) or a machine-readable medium containing instructions for performing the above-mentioned method.

[0013] The technical solution can be implemented in the form of a distributed computer system.

[0014] In this solution, the term “system” refers to a computer system, a computer (electronic computer), a numerical control (CNC), a PLC (programmable logic controller), computerized control systems, and any other devices capable of performing a given, clearly defined sequence of computing operations (actions, instructions).

[0015] A command processing unit is an electronic unit or integrated circuit (microprocessor) that executes machine instructions (programs) /

[0016] The command processing unit reads and executes machine instructions (programs) from one or more data storage devices, such as random access memory (RAM) and / or read-only memory (ROM). ROM may include, but is not limited to, hard disk drives (HDD), flash memory, solid-state drives (SSD), optical storage media (CD, DVD, BD, MD, etc.), etc.

[0017] A program is a sequence of instructions intended for execution by a computer control device or a command processing device.

[0018] Types of optimization.

[0019] Code optimization can be performed either manually by a programmer or automatically. In the latter case, the optimizer can be either a separate software tool or built into the compiler (the so-called optimizing compiler). In addition, it should be noted that modern processors can optimize the order of execution of code instructions.

[0020] There are such concepts as high-level and low-level optimization. High-level optimizations are mostly carried out by a programmer who, operating with abstract entities (functions, procedures, classes, etc.) and imagining a general model of the solution to the problem, can optimize the design of the system. Optimizations at the level of elementary structural blocks of the source code (cycles, branches, etc.) are also usually classified as high-level. Low-level optimization is carried out at the stage of converting the source code into a set of machine commands, and it is often this stage that is automated.

[0021] This solution describes an automated process for high-level optimization of software code using machine learning models.

[0022] Preparing data for training.

[0023] The model was trained using historical data on software vulnerabilities, divided into 2 classes: - original (unmodified) code (class 1) - modified code (optimized code to improve software performance) (class 0)

[0024] The training of the ML model is performed on data in the form of a pair of source code and modified code.

[0025] To assess the quality of the model, the data set was divided into 2 parts: training and validation samples. The division was random in the ratio of 70% to the training sample and 30% to the validation sample.

[0026] The accuracy of program code generation in terms of the number of completely correctly generated code is about 0.9.

[0027] As shown in Fig. 1, the computer-implemented method for modifying program code (100) consists of several stages performed by at least one processor.

[0028] At step (101), data containing at least a block of source code is obtained.

[0029] Next, at step (102), the source code is transformed into a program code graph in which the internal vertices are associated with programming language operators, and the leaves with the corresponding operands.

[0030] At this stage, syntactic analysis (parsing) of the source code contained in the file obtained at Stage (101) and written in any programming language (Java, C#, ASP, Visual Basic, C, C++, PHP, Apex, Ruby, JavaScript, VBScript, Perl, Swift, Python, Groovy, Scala, etc.) is performed, the result of which is a parse tree, or an abstract syntax tree, or any other representation of the code in the form of a tree or graph, displaying the dependencies between all elements of the source code.

[0031] This representation may contain information about their positions in the source code (line number of the element start, column number of the element start, number element end lines, element end column number), their classes, such as expressions, statements, declarations, etc., their class types, their names, their parent and descendant elements, comments on them, etc.

[0032] In one particular embodiment of the method, the source code is converted into an abstract syntax tree (AST), in which the internal nodes are mapped to programming language operators, and the leaves to the corresponding operands.

[0033] In another particular embodiment of the method, the source code is transformed into a control flow graph (CFG), in which the internal vertices are associated with programming language operators, and the leaves with the corresponding operands.

[0034] In another particular embodiment of the method, the source code is transformed into a data dependency graph (DDG), in which the internal nodes are associated with programming language operators, and the leaves with the corresponding operands.

[0035] In another particular embodiment of the method, the source code is converted into a representation based on static single assignment (SSA).

[0036] In another particular embodiment of the method, the source code is converted into a code property graph (CPG).

[0037] Next, at step (103), the program code graph is processed using a machine learning (ML) coding model trained on program code graphs, during which a representation of the program code graph is obtained in the form of a matrix of hidden states.

[0038] At this stage, the unmodified code graph is fed to the input of the coding machine learning model. A dictionary of all possible types of classes (types) of graph vertices obtained at stage (102) is formed. This dictionary is used to obtain a vector representation in the ML of the types of classes (types) of graph vertices. Using these vector representations, we obtain matrices of hidden states of the program code graph.

[0039] To obtain the matrix of hidden states of a graph, technologies such as neural networks can be used: Fully connected, Recurrent, Convolutional, Transformers.

[0040] In one particular embodiment of the invention, neural networks such as GNN (Graph Neural Network), DeepWalk, Line, Node2vec, Hope, a neural network with a graph attention mechanism (GAT - Graph ATtention), an inductive learning model (GraphSAGE), RGCN (Relational Graph Convolutional Networks), GCN (Graph Convolutional Networks) or networks inherited from them are used to obtain a matrix of hidden states of a graph.

[0041] Next, at step (104), the matrix of hidden states is processed using a generative machine learning (ML) model trained on the matrices of hidden states of graphs of unmodified program code, graphs of modified code and their source codes, during which a new graph of program code is obtained, corresponding to the modified program code, equivalent to the source program code in terms of the functions performed.

[0042] Next, at stage (105), the program code graph obtained at the previous stage is translated into a block of modified source code, equivalent in functionality to the original block of source code.

[0043] Training a Machine Learning Model To obtain the matrix of hidden states of the graph, the encoder (coding) block of the generative machine learning model is used. This block can contain an Embedding layer, randomly trained or initialized.

[0044] Further, there may be neural networks: Fully connected, Recurrent, Convolutional, Transformers. In one of the particular embodiments of the invention, the encoder block is at least one layer of neural networks of the following types: Recurrent neural networks (RNN), Long short term memory (LSTM), Gated recurrent units (GRU), Neural Turing machines (NMT), Bidirectional RNN, LSTM and GRU (BiRNN, BiLSTM and BiGRU), Deep residual networks (DRN), Echo state networks (ESN), Liquid state machines (LSM), Kohonen self-organizing map (KN, or organizing (feature) map, SOM, SOFM).

[0045] The training occurs as follows: operations are performed on two groups of program code blocks, where the first program code blocks are the original (unmodified) code, and the second program code blocks are modified code. These blocks are translated into a graph in accordance with the stages (101) - (102).

[0046] In this way, we obtain a graph of the original code - A, and the corresponding graph of the modified code - B. The obtained graph A is fed to the encoder (coding) block of the generative machine learning model. We obtain a matrix of hidden states (step 103). This matrix of hidden states is fed to the generator (decoder) block of the generative machine learning model (step 104). We obtain a new (restored) graph - B. This graph (B) is compared with the graph of the modified code B. The obtained discrepancies are recalculated into a quantitative characteristic according to the selected loss function. This quantitative characteristic is used to train the neural network according to the selected training algorithm.

[0047] In one particular embodiment of the invention, at least one of the loss functions is used: KLD (Calculates the Kulbeck-Leibler divergence loss between the true value and the predicted value), MAE (Calculates the mean absolute error between labels and predictions), MAPE (Calculates the mean absolute percentage error between the true value and the predicted value), MSE (Calculates the mean squared error between labels and predictions), MSLE (Calculates the mean squared logarithmic error between the true value and the predicted value), binary_crossentropy (Calculates the binary crossentropy loss), binary_focal_crossentropy (Calculates the binary focal crossentropy loss), categorical_crossentropy (Calculates the categorical crossentropy loss), categorical_hinge (Calculates the categorical lasso loss between the true value and predicted value), cosine_similarity (Calculates the cosine similarity between labels and predictions),hinge (Computes the hinge loss between the true value and the predicted value), huber (Computes the Huber loss), kl_divergence (Computes the Kullback-Leibler divergence loss between the true value and the predicted value), kullback_leibler_divergence (Computes the Kullback-Leibler divergence loss between the true value and the predicted value), log_cosh (Logarithm of the hyperbolic cosine of the prediction error), logcosh (Logarithm of the hyperbolic cosine of the prediction error), mean_absolute_error (Computes the mean absolute error between labels and predictions), mean_absolute_percentage_error (Computes the mean absolute percentage error between the true value and the predicted value), mean_squared_error (Computes the mean squared error between labels and, predictions), mean squared logarithmic error (Calculates the mean squared logarithmic error between the true value and the predicted value), poisson (Calculates the Poisson loss between the true value and the predicted value), sparse_categorical_crossentropy (Calculates the sparse categorical crossentropy loss), squared_hinge (Calculates the squared lasso loss between the true value and the predicted value).

[0048] These loss functions often have the following notations: binary_cross_entropy, binary cross entropy with logits, poisson_nll_loss, cosine embedding loss, cross entropy, ctc_loss, gaussian_nll_loss, hinge_embedding_loss, kl_div, ll_loss, mse_loss, margin_ranking_loss, multilabel_margin_loss, multilabel_soft_margin_loss, multi_margin_loss, nll loss, huber loss, smooth_ll_loss, soft_margin_loss, triplet margin loss, triplet_margin_with_distance_loss.

[0049] In one particular embodiment of the invention, at least one of the following learning algorithms is used: Adadelta, Adagrad, Adam, AdamW, SparseAdam, Adamax, ASGD, LBFGS, NAdam, RAdam, RMSprop, Rprop, FTRL, SGD, FastSGD, SGD-Nesterov, SAGA, SAGA+.

[0050] As a result, this approach allows automating the process of code optimization, reducing the time of checking the program code and its modification. The resulting optimization allows achieving acceleration of software operation, correction of software errors, increase of software performance, improves code characteristics, increases its efficiency, reduces the amount of code, the amount of RAM used by the program, accelerates the operation and performance of software, reduces the number of input-output operations.

[0051] Fig. 2 shows an example of a general view of a computing system (300) that ensures the implementation of the claimed method or is part of a computer system, for example, a server, a personal computer, part of a computing cluster, processing the necessary data for implementing the claimed technical solution.

[0052] In general, the system (300) comprises one or more processors (301), memory means such as RAM (302) and ROM (303), input / output interfaces (304), input / output devices (305), and a device for network interaction (306), united by a common information exchange bus.

[0053] The processor (301) (or several processors, a multi-core processor, etc.) can be selected from a range of devices that are widely used at present, for example, from such manufacturers as: Intel™, AMD™, Apple™, Samsung Exynos™, MediaTEK™, Qualcomm Snapdragon™, etc. The processor or one of the processors used in the system (300) must also include a graphics processor, for example, an NVIDIA or Graphcore GPU, the type of which is also suitable for the full or partial implementation of the method, and can also be used for training and applying machine learning models in various information systems.

[0054] RAM (302) is a random access memory and is intended for storing machine-readable instructions executed by the processor (301) for performing the necessary operations for logical data processing. RAM (302), as a rule, contains executable instructions of the operating system and the corresponding software components (applications, software modules, etc.). In this case, the available memory capacity of the graphic card or graphic processor can act as RAM (302).

[0055] ROM (303) is one or more permanent data storage devices, such as a hard disk drive (HDD), a solid-state drive (SSD), flash memory (EEPROM, NAND, etc.), optical storage media (CD-R / RW, DVD-R / RW, BlueRay Disc, MD), etc.

[0056] To organize the operation of system components (300) and to organize the operation of external connected devices, various types of I / O interfaces (304) are used. The choice of the corresponding interfaces depends on the specific design of the computing device, which may include, but are not limited to: PCI, AGP, PS / 2, IrDa, FireWire, LPT, COM, SATA, IDE, Lightning, USB (2.0, 3.0, 3.1, micro, mini, type C), TRS / Audio jack (2.5, 3.5, 6.35), HDMI, DVI, VGA, Display Port, RJ45, RS232, etc.

[0057] To ensure user interaction with the computing system (300), various means (305) of I / O information are used, for example, a keyboard, a display (monitor), a touch display, a touchpad, a joystick, a mouse, a light pen, a stylus, a touch panel, a trackball, speakers, a microphone, augmented reality means, optical sensors, a tablet, light indicators, a projector, a camera, biometric identification means (a retina scanner, a fingerprint scanner, a voice recognition module), etc.

[0058] The network interaction means (306) ensures data transmission via an internal or external computer network, such as Intranet, Internet, LAN, etc. One or more means (306) may be, but are not limited to: an Ethernet card, GSM modem, GPRS modem, LTE modem, 5G modem, satellite communication module, NFC module, Bluetooth and / or BLE module, Wi-Fi module, etc.

[0059] The submitted application materials disclose preferred examples of the implementation of the technical solution and should not be interpreted as limiting other, particular examples of its implementation that do not go beyond the scope of the requested legal protection, which are obvious to specialists in the relevant field of technology.

Claims

FORMULA 1. A computer-implemented method for modifying software code, performed using at least one processor and comprising the steps of: - receive data containing at least a block of source code; - transform the source code into a program code graph in which the internal nodes are associated with programming language operators, and the leaves with the corresponding operands; - process the program code graph using a machine learning (ML) coding model trained on program code graphs, during which a representation of the program code graph is obtained in the form of a matrix of hidden states; - process the matrix of hidden states using a generative machine learning (ML) model trained on the matrices of hidden states of graphs of unmodified program code, graphs of modified code and their source codes, during which a new graph of program code is obtained that corresponds to the modified program code, equivalent to the source program code in terms of the functions performed; - translate the program code graph obtained in the previous stage into a block of modified source code, equivalent in functionality to the original block of source code. 2 The method according to paragraph 1, characterized in that the source code is converted into an abstract syntax tree (AST), in which the internal nodes are associated with programming language operators, and the leaves with the corresponding operands. 3 The method according to paragraph 1, characterized in that the source code is converted into a control flow graph (CFG), in which the internal nodes are associated with programming language operators, and the leaves with the corresponding operands. 4 The method according to claim 1, characterized in that the source code is converted into a data dependency graph (DDG), in which the internal The nodes are associated with programming language operators, and the leaves with the corresponding operands.

5. The method according to paragraph 1, characterized in that the source code is converted into a representation based on static single assignment (SSA).

6. The method according to paragraph 1, characterized in that the source code is converted into a code property graph (CPG).

7. A system for modifying program code, comprising at least one processor and a memory storing machine-readable instructions that, when executed by the processor, implement the method according to any one of paragraphs 1-6.

Citation Information

Patent Citations

  • Techniques for transforming serial program code into kernels for execution on a parallel processor

    US20190278574A1

  • Persistent annotation of syntax graphs for code optimization

    US20200364036A1

  • Optimizing API implementer programs using fine-grained code analysis

    US9904527B1