Large model generation code traceability method, system and device based on reversible watermark and medium
Through reversible semantics and BCH encoding error correction technology, the problem of relying on prior knowledge in the traceability of large-scale model generation code is solved, and efficient and reliable watermark embedding and extraction is realized. It is suitable for a variety of programming languages, is aggressive and can accurately trace the source of the code.
Patent Information
- Application Number
- CN202510463284.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-14
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2045-04-14
AI Technical Summary
The existing technology relies on prior knowledge in the traceability of code generated by large-models. The watermark extraction error rate is high and cannot be effectively traced. It is impossible to effectively distinguish the source of code in actual applications. Especially when the code generated by large-models is mixed with human-written code, it is impossible to effectively trace the source.
Reversible semantics maintain conversion applicability analysis and BCH encoding error correction technology are adopted to embed and extract watermarks through equivalent transformation, and watermarks are embedded and extracted in the large-model generation code using reversible semantics maintain conversion rules. Combining salt value hashing strategy and BCH error correction code, watermark embed and extracted with zero prior knowledge is realized, which is suitable for a variety of programming languages.
On the premise of maintaining the code function, the watermark embedding and extraction with zero prior knowledge is realized, which is resistant to attacks and can effectively trace the source of the code, is suitable for complex code structures, and bit errors are corrected through BCH error correction codes, improving the reliability and attack resistance of the watermark.
Smart Images

Figure CN120449134A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer software technology, and in particular relates to a large model-generated code tracing method, system, device and medium based on reversible watermarking. Background Art
[0002] Large language models (LLMs) have made significant progress in the field of code generation. By automatically generating code snippets, optimizing algorithm implementations, and assisting debugging, they have significantly shortened the software development cycle and improved programmer efficiency. However, with the widespread application of large models in code generation, their potential security and ethical risks have gradually become apparent. For example, the generated code may be used for academic misconduct, such as code plagiarism in student papers or unauthorized code reuse. In addition, malicious users may exploit large models to generate code with security vulnerabilities or malicious functionality, posing a threat to the software ecosystem.
[0003] To address these challenges, developing effective methods to verify code authorship—code traceability—is crucial. This technology aims to track and identify whether a given code was generated by a specific large model, thereby ensuring its legitimacy and security. To achieve this, watermarking technology is widely used for traceability tasks in various media, including images and text. For code-related tasks, watermarking techniques are primarily categorized into methods based on model modification and methods based on code transformation.
[0004] The main methods based on modifying the model are:
[0005] (1) Lee T, Hong S, Ahn J, et al. Who Wrote this Code? Watermarking for Code Generation [C] / / Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics. 2024: 4890-4911. This method divides tokens into “green” and “red” words, always selects “green” tokens to embed watermarks during text generation, and detects the presence of watermarks by identifying green tokens.
[0006] (2) Guan B, Wan Y, Bi Z, et al. CodeIP: AGrammar-Guided Multi-Bit Watermark for Large Language Models of Code[C] / / Findings of the Association for Computational Linguistics: EMNLP 2024.2024:9243-9258. This work introduces code syntax information into the watermark insertion process by training a type predictor to predict the grammatical type of the next token (keyword, identifier, etc.).
[0007] (3) Ning K, Chen J, Zhong Q, et al. Mcgmark: An encodable and robust online watermark for llm-generated malicious code[J].arXiv preprint arXiv:2408.01354, 2024. This work embeds encodable information by controlling the choice of vocabulary. The watermark embedding process takes into account the structural characteristics of the malicious code and further optimizes the output quality through probabilistic outliers.
[0008] The main methods based on code conversion are:
[0009] (4)Li B, Zhang M, Zhang P, et al. ACW: Enhancing Traceability of AI-Generated Codes Based on Watermarking[J]. arXiv preprint arXiv: 2402.07518, 2024. This work proposes a method for watermark embedding based on semantically preserved code transformation, which identifies watermarks by detecting the presence of code patterns and identifies the author model of the code based on the extracted watermark bits.
[0010] (5)Li Z,Wang C,Wang S,et al.Protecting intellectual property of large language model-based code generation apis via watermarks[C] / / Proceedings of the 2023ACM SIGSAC Conference on Computer and Communications Security.2023:2336-2350.This work embeds watermarks based on token distribution by replacing code tokens in large model output with synonymous tokens, which has great potential in preventing remote imitation attacks.
[0011] (6)Sun Z,Du X,Song F,et al.Codemark:Imperceptible watermarking forcode datasets against neural code completion models[C] / / Proceedings ofthe31stACM Joint European Software Engineering Conference and Symposium on theFoundations ofSoftware Engineering.2023:1561-1572.This work focuses on tracking code datasets in model training, and changes the distribution of code snippets by applying code transformations, thereby forming specific patterns in specific datasets as code watermarks.
[0012] The main defects of the above-mentioned method based on the generative model are: the prompt words or model parameters need to be modified when embedding the watermark, which is difficult to achieve in practical applications; watermark extraction requires re-implementation of code generation, resulting in a large amount of time overhead; watermark extraction requires the original generation prompt to reproduce the token selection, which conflicts with the conditions for extracting watermarks in practical applications because the original generation prompt words are usually not available.
[0013] Among the above code transformation-based methods, method (4) requires prior knowledge of which candidate transformations have been applied to a given code, but this information is usually not available in practical applications; methods (5) and (6) were not designed directly to meet the needs of large model code traceability. When faced with a mixture of generated code and human-written code, they cannot effectively distinguish the source of the code, and are therefore not suitable for traceability tasks related to large models. Summary of the Invention
[0014] The purpose of the present invention is to propose a large-scale model-generated code tracing method, system, device and medium based on reversible watermarks, which overcomes the technical limitations of the existing technology of relying on prior knowledge, high error rate of watermark extraction and inability to effectively trace the generated code model, and provides higher security and traceability guarantees for the code generation field.
[0015] The purpose of the present invention is achieved through the following technical solutions:
[0016] A large model generation code traceability method based on reversible watermarking, the specific steps are as follows:
[0017] Step 1: Analyze the applicability of reversible semantics-preserving transformations for a given code C and generate a set of applicable transformation rules T applicable ;
[0018] Step 2: Set a specific salt value for the large model and T applicable Each rule T in i , calculation rule name The hash value after string concatenation with salt, sort all hash values from large to small to generate an ordered sequence of transformation rules T sorted ;
[0019] Step 3: Set the corresponding watermark information w for the large model and generate the encoded watermark information w through BCH encoded , and according to w encoded The corresponding bit value selects the corresponding reversible semantic conversion sub-rule T i,0 or T i,1 ;
[0020] Step 4: Apply the selected transformation sub-rules in order to the given code C according to step 2 to generate the watermarked code C. w ;
[0021] Step 5: Embed the watermarked code C w or code of unknown origin C # Perform applicability analysis of reversible semantics-preserving transformations to generate a set of applicable transformation rules for the extraction phase
[0022] Step 6: Salt the specific salt value of the large model according to the extraction stage * ,right Each rule in Calculation rule name with salt * Take the hash value after string concatenation, sort all the hash values from large to small, and generate an ordered sequence of conversion rules
[0023] Step 7: Expected watermark information w e Perform BCH encoding to generate the expected watermark information after encoding
[0024] Step 8: According to step 6, each rule in the selected transformation sub-rule sequence Check that code C is applying the rules and After the state, determine the bit value expressed by the corresponding rule;
[0025] Step 9: Sequentially check the ordered transformation rule sequence T sorted Each rule within From C w Extract watermark information w ex ;
[0026] Step 10: Use the BCH decoding algorithm to decode w ex Decode and try to restore the original watermark information ω' ex ;
[0027] Step 11: By comparing the original watermark information ω' ex and expected watermark information w e , to determine the generated code and trace the generated model, and then determine the source of the code.
[0028] Furthermore, the reversible semantics preserving transformation applicability analysis RSPT is specifically as follows:
[0029] Let T be an equivalent semantic transformation rule i :E - →E + , where E - and E + are two abstract code patterns; in the traditional equivalent semantic conversion paradigm, E - →E + As a complete equivalent semantic transformation rule, in RSPT, an RSPT transformation rule consists of two symmetrical equivalent semantic transformation rules. An RSPT rule is denoted as T i :[E - →E + , E + →E - ],T i,0 and T i,1 Corresponding to T i Thus, an RSPT rule states that for any code segment C, there is any code segment c - ∈E - ,c + ∈E+ , then:
[0030] Interchangeability: T i,0 (c - )=c + ,T i,1 (c + )=c -
[0031] Idempotence: T i,0 (T i,0 (c - ))=c + ,T i,1 (T i,1 (c + ))=c -
[0032] Exchangeability: T i,m (T j,n (C))=T j,n (T i,m (C)
[0033] Under the RSPT paradigm, all E in a code - and E + are completely convertible to each other, so whether the code form E in the original code C is naturally equivalent to E - or E + , or both exist at the same time, can be converted into a single fixed form E - or E + .
[0034] Furthermore, the reversible semantics preservation conversion applicability analysis is performed in the following specific process:
[0035] (1) The applicability analysis algorithm parses the code C into a concrete syntax tree Tree;
[0036] (2) The applicability analysis algorithm checks the applicability of the rule by searching the syntax tree nodes on the Tree. If the rule T i Sub-rule T i,0 or T i,1 There are any number of nodes corresponding to it on the Tree, then T i is deemed applicable to C;
[0037]
[0038] Among them, T i →C represents T i For C, n and m are nodes on the concrete syntax tree Tree. Indicates that there are n nodes and Ti,0 The adapted node set is associated.
[0039] (3) Apply the transformation rule T in step (2) to code C i Add to the set of transformation rules T applicable to the current code applicable middle.
[0040] Furthermore, the step 2 is based on T applicable Sort the rules by hash values from large to small to get T sorted ,
[0041]
[0042] Among them, sort represents the basic numerical sorting function, Indicates the result of hash value calculation after string concatenation.
[0043] Furthermore, the watermark information w encoded in step 3 encoded ,
[0044] w encoded (x) = v(x) + r(x)
[0045] v(x)=(w0+w1x+w2x 2 +…+w k-1 x k-1 )x n-k
[0046] r(x)=v(x)mod g(x)
[0047] Where w is the watermark information; mod g(x) maps the original information polynomial v(x) to a specific coding space by taking the modulus of the generating polynomial g(x) to obtain the final codeword sequence that satisfies the coding constraints; x is the formal variable in the polynomial, which represents the expanded form of the watermark information in the polynomial domain.
[0048] Furthermore, the step 4 converts the transformation rule set T sorted in step 2 into sorted The first l rules in , for each rule T i From the encoded watermark w encoded Extract the corresponding bit, bit is 0 or 1, and convert the conversion rule T according to the value of the bit. i,0 or T i,1 Applied to code C, the above process is iterated to obtain the watermarked code C w ,
[0049] T i =T sorted [i],ifi <l
[0050]
[0051] Furthermore, the step 9 is specifically as follows:
[0052] For the expected watermark information after encoding and from Sequentially take out the conversion rule numbered i and in The corresponding bit information of the label is 1 or 0. Assume that the kth rule as well as If it exists, first perform positive verification on this bit of information, namely:
[0053]
[0054] Among them, Tags positive Is the Boolean value obtained by positive verification;
[0055] Then reverse verify this information, because Therefore, this bit is inverted, that is, the value of 0 is used for reverse verification, that is:
[0056]
[0057] Among them, Tags negative It is the Boolean value obtained by reverse verification;
[0058] Finally, according to Tag positive 、Tag negative And the expected value of the k-th information bit, the extracted bit value for this bit is obtained, that is:
[0059]
[0060] Among them, ω ex [k] refers to ω ex The value of the kth information bit, yes If none of the above conditions are met, the code is not embedded with a watermark, otherwise it is embedded with a watermark.
[0061] Furthermore, the step 10 is specifically as follows:
[0062] ω ex Expressed as a polynomial:
[0063] r(x)=r0+r1x+r2x 2 +…+r n-1 x n-1
[0064] By generating the roots of the polynomial, calculate the comprehensive value S of the check code word i :
[0065] S i =r(α i ),i=1,2,…,2t
[0066] Where α is a finite field GF(2 m )'s original elements;
[0067] The error localization polynomial σ(x) is calculated using the Pelikan–Messy algorithm:
[0068] σ(x)=1+σ1x+σ2x 2 +…+σ t x t
[0069] Flip the bits corresponding to the identified error positions to obtain the corrected codeword r'(x); remove the check bits from r'(x) and extract the first k bits as the decoded watermark information ω' ex .
[0070] A computer device / equipment / system includes a memory, a processor, and a computer program stored in the memory. The processor executes the computer program to implement the steps of a code tracing method based on a large model of reversible watermarks.
[0071] A computer program product includes a computer program / instruction, which, when executed by a processor, implements the steps of a large model-generated code tracing method based on a reversible watermark.
[0072] A computer-readable storage medium stores a computer program / instruction, which, when executed by a processor, implements the steps of a method for tracing the source of a large model-generated code based on a reversible watermark.
[0073] The beneficial effects of the present invention are:
[0074] With the widespread application of large language models (LLMs) in code generation tasks, the issues of code authenticity and author traceability have become increasingly prominent. However, existing code watermark traceability methods often rely on unavailable prior knowledge when extracting watermarks, such as prompt information during code generation. This limits their practical application and has many shortcomings and limitations in terms of anti-attack resistance.
[0075] To address these issues, the present invention embeds and extracts watermarks by equivalently transforming the original syntax and structural semantics while preserving code functionality. This approach enables zero-a priori knowledge watermark embedding and extraction and is applicable to a variety of programming languages, including grammatically strict C and C++. Code transformation is implemented through a concrete syntax tree, ensuring support for complex code structures and minimizing code modifications for watermarking.
[0076] Furthermore, the design of this invention possesses a certain degree of attack resistance. First, by employing a salted hashing strategy to sort applicable rules and calculating salted hash values for all candidate rules and their sub-rules, the watermark is pseudo-random, effectively preventing potential rainbow table attacks based on pre-computed hash tables. Second, by introducing BCH error-correcting codes, the watermark can automatically correct bit errors caused by accidental modification or malicious destruction during the extraction process, improving its attack resistance and reliability. BRIEF DESCRIPTION OF THE DRAWINGS
[0077] Figure 1 Flowchart of the method of the present invention. DETAILED DESCRIPTION
[0078] The present invention will be further described below with reference to the accompanying drawings.
[0079] according to Figure 1 A flow chart of a method for tracing the provenance of large-scale model-generated code based on reversible watermarking. During the watermark embedding phase, a suitability analyzer is first used to verify the suitability of code transformations for a given code to identify applicable code transformations. The sequence of applicable transformations is then reordered based on a given salt value, and these transformations are selectively applied to systematically embed the watermark in the generated code. During the provenance phase, given a section of code to be verified, this method systematically identifies and verifies the applied transformations through a combination of bidirectional state verification and error correction decoding. The watermark information is then extracted and error correction is performed. Ultimately, the provenance of the generated model is traced based on the extracted watermark.
[0080] In the analysis of reversible semantic preservation conversion applicability and watermark extraction in the present invention, the code C mentioned refers to all possible codes compatible with the method. In the watermark embedding method, the code C mentioned only refers to the generated code generated by the large language model M by inputting the prompt word.
[0081] C=M(P)
[0082] Among them, M is a large language model; P is a predefined prompt word.
[0083] The present invention uses the Reversible Equivalent Semantic Transformation Paradigm (RSPT) as the necessary foundation for the method of the present invention. The Reversible Equivalent Semantic Transformation Paradigm (RSPT) is specifically:
[0084] Let T be an equivalent semantic transformation rule i :E - →E + , where E - and E + are two abstract code patterns. In the traditional equivalent semantic transformation paradigm, E - →E + As a complete equivalent semantic transformation rule, in RSPT, an RSPT transformation rule consists of two symmetrical equivalent semantic transformation rules. An RSPT rule is denoted as T i :[E - →E + , E + →E - ],T i,0 and T i,1 Corresponding to T i Therefore, an RSPT rule states that for any code segment C, there is any code segment c - ∈E - ,c + ∈E + , then:
[0085] (1) Interchangeability: T i,0 (c - )=c + ,T i,1 (c + )=c -
[0086] (2) Idempotence: T i,0 (T i,0 (c - ))=c + ,T i,1 (T i,1 (c + ))=c -
[0087] (3) Exchangeability: T i,m (T j,n (C))=T j,n (T i,m (C)
[0088] Under the RSPT paradigm, all E in a code - and E + Therefore, whether the code form E in the original code C is naturally equivalent to E - or E + , or both exist at the same time, can be converted into a single fixed form E -or E + .
[0089] The present invention provides a large model-generated code tracing method based on reversible watermarking, and the specific steps are as follows:
[0090] Step 1: Analyze the applicability of reversible semantics-preserving transformations for a given code C and generate a set of applicable transformation rules T aplicable ;
[0091] For a given code C and a set of reversible equivalent semantic transformation rules T, the reversible semantics-preserving transformation applicability analysis algorithm is as follows:
[0092] (1) The applicability analysis algorithm parses the code C into a specific syntax tree Tree and passes it to the next step for processing.
[0093] (2): The applicability analysis algorithm checks the applicability of the rule by searching the syntax tree nodes on the Tree. If the rule T i Sub-rule T i,0 or T i,1 There are any number of nodes corresponding to it on the Tree, then T i Considered applicable to C.
[0094]
[0095] (3) Apply the transformation rule T in step (2) to code C i Add to the set of transformation rules T applicable to the current code applicable middle.
[0096] Step 2: Watermark Embedding
[0097] Step 2.1: Set a specific salt value for the large model and T applicable Each rule T in i , calculation rule name The hash value after string concatenation with salt, sort all hash values from large to small to generate an ordered sequence of transformation rules T sorted ;
[0098] T sorted =sort(T applicable ,key=hash(t,salt))
[0099] Among them, sort represents the basic numerical sorting function, Indicates the result of hash value calculation after string concatenation.
[0100] Step 2.2: Set the corresponding watermark information w for the large model and generate the encoded watermark information w through BCHencoded ,
[0101] w encoded (x) = v(x) + r(x)
[0102] v(x)=(w0+w1x+w2x 2 +…+w k-1 x k-1 )x n-k
[0103] r(x)=v(x)mod g(x)
[0104] Where w is the watermark information; mod g(x) maps the original information polynomial v(x) to a specific coding space by taking the modulus of the generating polynomial g(x) to obtain the final codeword sequence that satisfies the coding constraints; x is the formal variable in the polynomial, which represents the expansion form of the watermark information in the polynomial domain;
[0105] According to w encoded The corresponding bit value selects the corresponding reversible semantic conversion sub-rule T i,0 or T i,1 ;
[0106] Step 2.3: The sorted transformation rule set T obtained in step 2.1 sorted The first l rules in , for each rule T i From the encoded watermark w encoded Extract the corresponding bit (0 or 1) and convert the conversion rule T according to the value of the bit i,0 or T i,1 Applied to code C, the above process is iterated to obtain the watermarked code C w .
[0107] T i =T sorted [i],ifi <l
[0108]
[0109] Step 3: Watermark extraction and tracing
[0110] Step 3.1: Embed the watermarked code C w or code of unknown origin C # Perform applicability analysis of reversible semantics-preserving transformations to generate a set of applicable transformation rules for the extraction phase
[0111] Step 3.2: Salt the specific salt value according to the extraction stage * ,right Each rule in Calculation rule name with salt * Take the hash value after string concatenation, sort all the hash values from large to small, and generate an ordered sequence of conversion rules
[0112]
[0113] Step 3.3: For the expected watermark information w e Perform BCH encoding to generate the expected watermark information after encoding
[0114] Step 3.4: Based on step 3.2, the watermark extraction algorithm traverses the sorted set of applicable transformation rules The first l rules in , for each rule By checking code C in applying the rules and After the state is determined, the extracted watermark information is determined, and the bit value expressed by the corresponding rule is determined.
[0115] Step 3.5: Sequentially check the ordered sequence of transformation rules T sorted Each rule within From C w Extract watermark information w ex ;
[0116] For the expected watermark information after encoding and from Sequentially take out the conversion rule numbered i and in The corresponding bit information of the label is 1 or 0. Assume that the kth rule as well as If it exists, first perform positive verification on this bit of information, namely:
[0117]
[0118] Among them, Tags positive Is the Boolean value obtained by positive verification;
[0119] Then reverse verify this information, because Therefore, this bit is inverted, that is, the value of 0 is used for reverse verification, that is:
[0120]
[0121] Among them, Tags negative It is the Boolean value obtained by reverse verification;
[0122] Finally, according to Tagpositive 、Tag negative And the expected value of the k-th information bit, the extracted bit value for this bit is obtained, that is:
[0123]
[0124] Among them, ω ex [k] refers to ω ex The value of the kth information bit, yes The flip value of the bit information bit.
[0125] If none of the above conditions are met, the code is not embedded with a watermark, otherwise it is embedded with a watermark.
[0126] Step 3.6: Use the BCH decoding algorithm to decode w ex Decode and try to restore the original watermark information ω' ex ;
[0127] ω ex Expressed as a polynomial:
[0128] r(x)=r0+r1x+r2x 2 +…+r n-1 x n-1
[0129] By generating the roots of the polynomial, calculate the comprehensive value S of the check code word i :
[0130] S i =r(α i ),i=1,2,…,2t
[0131] Where α is a finite field GF(2 m )'s original elements;
[0132] The error localization polynomial σ(x) is calculated using the Pelikan–Messy algorithm:
[0133] σ(x)=1+σ1x+σ2x 2 +…+σ t x t
[0134] Flip the bits corresponding to the identified error positions to obtain the corrected codeword r'(x); remove the check bits from r'(x) and extract the first k bits as the decoded watermark information ω' ex .
[0135] Step 3.7: By comparing the original watermark information ω' ex and expected watermark information w e, to determine the generated code and trace the generated model, and then determine the source of the code.
[0136] Example 1:
[0137] The present invention verifies a large model-generated code tracing method based on reversible watermarks through two aspects, including watermark extraction capability and anti-attack capability.
[0138] (1) Watermark extraction capability:
[0139] Table 1 shows the evaluation results of the present invention in the watermark extraction task. The experimental dataset is based on the cross-language project-level code generated by the large model ChatGPT-4o and the intelligent agent ChatDev, including the MsgACC results before and after the application of BCH coding error correction (all 4-bit codes are correctly recognized and counted as correctly recognized samples). The experimental results are shown in Table 1, where the watermark coding part shows the watermark information before BCH encoding. . Next, the experimental results are analyzed. First, on the datasets of the three languages, for each watermark information sequence, the present method shows almost perfect MsgACC. For example, on the datasets of C and Python languages, the MsgACC of each watermark information extracted before and after correction is 100%, demonstrating the accuracy and stability of the watermark information extraction of this method. The lowest MsgACC obtained on the C++ language dataset also reached 99.60%. In summary, the present method has excellent watermark extraction accuracy.
[0140] Table 1 Watermark extraction ability evaluation results
[0141]
[0142] (2) Anti-attack:
[0143] Table 2 presents the evaluation results of the watermark extraction capability of the present invention under a destructive attack scenario. The experiment assumes that the attacker knows the technical details of watermark embedding and extraction but cannot obtain full information about the rule ordering. The simulated attacker corrupts the watermark encoding by randomly selecting a single transition from the rule set. The attacker may flip certain bits or disrupt the encoding sequence. Analysis of the experimental results shows that the pre-correction MsgACC decreases by approximately 20% compared to the normal state, indicating that this attack would severely compromise the integrity of the watermark information without an error-correcting code. However, a comparison of the post-correction MsgACC with the normal state shows that the BCH error correction algorithm recovers nearly all of the corrupted watermark information. For example, in a C language dataset embedded with the watermark 0101, the attack reduces the pre-correction MsgACC from 100% to 78.83%, but after correction, the MsgACC returns to the same 100% as the normal state. For all datasets, the maximum post-correction MsgACC decreases by only 0.2% under this attack.
[0144] Table 2 Anti-attack experimental results
[0145]
[0146] All relevant contents of the steps involved in the aforementioned embodiment of the large-scale model-based reversible watermark-based code tracing method can be referred to the functional description of the functional modules corresponding to the deep fake detection interpretable system based on causal analysis in the embodiment of the present invention, and will not be repeated here.
[0147] The module division in the embodiments of the present invention is illustrative and represents only one logical functional division. In actual implementation, other division methods may be used. Furthermore, the functional modules in various embodiments of the present invention may be integrated into a single processor, exist physically as separate modules, or two or more modules may be integrated into a single module. The integrated modules may be implemented in either hardware or software functional modules.
[0148] In another embodiment of the present invention, a computer device is provided, comprising a processor and a memory, wherein the memory is configured to store a computer program, wherein the computer program includes program instructions, and the processor is configured to execute the program instructions stored in the computer storage medium. The processor may be a central processing unit (CPU), or may be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing core and control core of the terminal, and is suitable for implementing one or more instructions, specifically for loading and executing one or more instructions in the computer storage medium to implement the corresponding method flow or corresponding function. The processor described in the embodiment of the present invention can be used for the operation of the code traceability method based on the large model of reversible watermarking.
[0149] In another embodiment of the present invention, a storage medium is provided, specifically a computer-readable storage medium (Memory). The computer-readable storage medium is a memory device in a computer device, used to store programs and data. It is understood that the computer-readable storage medium herein may include both built-in storage media in the computer device and, of course, extended storage media supported by the computer device. The computer-readable storage medium provides storage space, which stores the terminal's operating system. Furthermore, the storage space also stores one or more instructions suitable for being loaded and executed by a processor. These instructions may be one or more computer programs (including program code). It should be noted that the computer-readable storage medium herein may be a high-speed RAM memory or a non-volatile memory, such as at least one disk storage device. The processor may load and execute the one or more instructions stored in the computer-readable storage medium to implement the corresponding steps of the code traceability method for generating a large model based on a reversible watermark in the above-mentioned embodiment.
[0150] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0151] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0152] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0153] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0154] The above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit the same. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be included in the scope of protection of the claims of the present invention.
Claims
1. A large model-generated code tracing method based on reversible watermarking, characterized by: Step 1: Analyze the applicability of reversible semantics-preserving transformations for a given code C and generate a set of applicable transformation rules T applicable ; Step 2: Set a specific salt value for the large model and T applicable Each rule T in i , calculation rule name The hash value after string concatenation with salt, sort all hash values from large to small to generate an ordered sequence of transformation rules T sorted ; Step 3: Set the corresponding watermark information w for the large model and generate the encoded watermark information w through BCH encoded , and according to w encoded The corresponding bit value selects the corresponding reversible semantic conversion sub-rule T i,0 or T i,1 ; Step 4: Apply the selected transformation sub-rules in order to the given code C according to step 2 to generate the watermarked code C. w ; Step 5: Embed the watermarked code C w or code of unknown origin C # Perform applicability analysis of reversible semantics-preserving transformations to generate a set of applicable transformation rules for the extraction phase Step 6: Salt the specific salt value of the large model according to the extraction stage * ,right Each rule in Calculation rule name with salt * Take the hash value after string concatenation, sort all the hash values from large to small, and generate an ordered sequence of conversion rules Step 7: Expected watermark information w e Perform BCH encoding to generate the expected watermark information after encoding Step 8: According to step 6, each rule in the selected transformation sub-rule sequence Check that code C is applying the rules and After the state, determine the bit value expressed by the corresponding rule; Step 9: Sequentially check the ordered transformation rule sequence T sorted Each rule within From C w Extract watermark information w ex ; Step 10: Use the BCH decoding algorithm to decode w ex Decode and try to restore the original watermark information ω' ex ; Step 11: By comparing the original watermark information ω' ex and expected watermark information w e , to determine the generated code and trace the generated model, and then determine the source of the code.
2. The method for tracing the source of large-scale model-generated code based on reversible watermarking according to claim 1 is characterized by: The reversible semantics preserving transformation applicability analysis RSPT is specifically as follows: Let T be an equivalent semantic transformation rule i :E - →E + , where E - and E + are two abstract code patterns; in the traditional equivalent semantic conversion paradigm, E - →E + As a complete equivalent semantic transformation rule, in RSPT, an RSPT transformation rule consists of two symmetrical equivalent semantic transformation rules. An RSPT rule is denoted as T i :[E - →E + , E + →E - ],T i,0 and T i,1 Corresponding to T i Thus, an RSPT rule states that for any code segment C, there is any code segment c - ∈E - ,c + ∈E + , then: Interchangeability: T i,0 (c - )=c + ,T i,1 (c + )=c - Idempotence: T i,0 (T i,0 (c - ))=c + ,T i,1 (T i,1 (c + ))=c - Exchangeability: T i,m (T j,n (C))=T j,n (T i,m (C) Under the RSPT paradigm, all E in a code - and E + are completely convertible to each other, so whether the code form E in the original code C is naturally equivalent to E - or E + , or both exist at the same time, can be converted into a single fixed form E - or E + .
3. The method for tracing the source of large-scale model-generated code based on reversible watermarking according to claim 1 is characterized by: The specific process of the applicability analysis of the reversible semantics-preserving transformation is as follows: (1) The applicability analysis algorithm parses the code C into a concrete syntax tree Tree; (2) The applicability analysis algorithm checks the applicability of the rule by searching the syntax tree nodes on the Tree. If the rule T i Sub-rule T i,0 or T i,1 There are any number of nodes corresponding to it on the Tree, then T i is deemed applicable to C; Among them, T i →C represents T i Applicable to C, n and m are nodes located on the concrete syntax tree Tree, n|=T i,0 Indicates that there are n nodes and T i,0 The adapted node set is associated. (3) Apply the transformation rule T in step (2) to code C i Add to the set of transformation rules T applicable to the current code applicable middle.
4. The method for tracing the source of large-scale model-generated code based on reversible watermarking according to claim 1 is characterized by: Step 2 is based on T applicable Sort the rules by their hash values from large to small to get T sorted , Among them, sort represents the basic numerical sorting function, Indicates the result of hash value calculation after string concatenation.
5. The method for tracing the source of large-scale model-generated code based on reversible watermarking according to claim 1 is characterized by: The watermark information w encoded in step 3 encoded , w encoded (x)=v(x)+r(x) v(x)=(w0+w1x+w2x 2 +…+w k-1 x k-1 )x n-k r(x)=v(x)mod g(x) Where w is the watermark information; mod g(x) maps the original information polynomial v(x) to a specific coding space by taking the modulus of the generating polynomial g(x) to obtain the final codeword sequence that satisfies the coding constraints; x is the formal variable in the polynomial, which represents the expanded form of the watermark information in the polynomial domain.
6. The method for tracing the source of large-scale model-generated code based on reversible watermarking according to claim 1 is characterized by: Step 4 converts the transformation rule set T sorted in step 2 into sorted The first l rules in , for each rule T i From the encoded watermark w encoded Extract the corresponding bit, bit is 0 or 1, and convert the conversion rule T according to the value of the bit. i,0 or T i,1 Applied to code C, the above process is iterated to obtain the watermarked code C w , T i =T sorted [i],ifi<l 7. The method for tracing the source of large-scale model-generated code based on reversible watermarking according to claim 1 is characterized by: The step 9 is specifically as follows: For the expected watermark information after encoding and from Sequentially take out the conversion rule numbered i and in The corresponding bit information of the label is 1 or 0. Assume that the kth rule as well as If it exists, first perform positive verification on this bit of information, namely: Among them, Tags positive Is the Boolean value obtained by positive verification; Then reverse verify this information, because Therefore, this bit is inverted, that is, the value of 0 is used for reverse verification, that is: Among them, Tags negative It is the Boolean value obtained by reverse verification; Finally, according to Tag positive 、Tag negitive And the expected value of the k-th information bit, the extracted bit value for this bit is obtained, that is: Among them, ω ex [k] refers to ω ex The value of the h-th information bit, yes The flip value of the bit information bit. If none of the above conditions are met, the code is not embedded with a watermark, otherwise it is embedded with a watermark.
8. The method for tracing the source of large-scale model-generated code based on reversible watermarking according to claim 1 is characterized by: The step 10 is specifically as follows: ω ex Expressed as a polynomial: r(x)=r0+r1x+r2x 2 +…+r n-1 x n-1 By generating the roots of the polynomial, calculate the comprehensive value S of the check code word i : S i =r(α i ),i=1,2,…,2t Where α is a finite field GF(2 m )'s original elements; The error localization polynomial σ(x) is calculated using the Pelikan–Messy algorithm: σ(x)=1+σ1x+σ2x 2 +…+s t x t Flip the bits corresponding to the identified error positions to obtain the corrected codeword r'(x); remove the check bits from r'(x) and extract the first k bits as the decoded watermark information ω' ex .
9. A computer device / apparatus / system comprising a memory, a processor, and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Program watermark embedding and extracting method and system for code tracing
CN116861378A
Text watermark embedding and detecting method based on model context learning
CN118349970A
Multi-detector watermark detection method and device, equipment, storage medium and product
CN118821087A
Big language model dual watermark embedding method
CN119357929A
Large model generation code watermark method based on equivalent semantic transformation, program, equipment and storage medium
CN119783070A
Cited By
A code watermark generation method and device based on syntax structure perception and a medium
CN122528122A