A large model generation code traceability method, system, device and medium based on reversible watermarking
By employing reversible semantic preservation transformation and BCH encoding error correction techniques, the problem of relying on prior knowledge in the source code tracing of large model generation is solved. This achieves efficient and reliable watermark embedding and extraction, is applicable to multiple programming languages, has anti-attack capabilities, and provides an accurate source code tracing generation model.
Patent Information
- Application Number
- CN202510463284.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-14
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2045-04-14
AI Technical Summary
Existing methods for tracing the source of large-scale generated code rely on prior knowledge, have a high error rate when extracting watermarks, cannot effectively trace the source of generated code models, and cannot distinguish the source when faced with mixed code.
Employing reversible semantic preservation transformation applicability analysis and BCH encoding error correction technology, watermarks are embedded and extracted through equivalent transformation. Utilizing salt value hash sorting and syntax tree structure, watermark embedding and extraction with zero prior knowledge are achieved. This method is applicable to multiple programming languages and possesses anti-attack capabilities.
While maintaining code functionality, it achieves efficient watermark embedding and extraction, is applicable to multiple programming languages, has anti-attack capabilities and high reliability, and can accurately trace the generation model of source code.
Smart Images

Figure CN120449134B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of computer software, and particularly relates to a large model code generation code traceability method and system based on reversible watermarking, a device and a medium. BACKGROUND
[0002] Large language models have made significant progress in the field of code generation. They can automatically generate code snippets, optimize algorithms, and assist in debugging, significantly reducing software development cycles and improving programmer efficiency. However, as large models are widely used in code generation, their potential security and ethical risks have gradually emerged. For example, generated code may be used for academic misconduct, such as code plagiarism in student papers or unauthorized code reuse. In addition, malicious users may use large models to generate code with security vulnerabilities or malicious functions, posing a threat to the software ecosystem.
[0003] To address these challenges, it is particularly important to develop effective methods to verify the authorship of code, i.e., code traceability technology. Traceability technology aims to track and identify whether a given code is generated by a specific large model, thereby providing protection for the legality and security of the code. To achieve this purpose, watermarking technology is widely used in image, text, and other types of media traceability tasks. In the code task, watermarking technology is mainly divided into methods based on modified models and methods based on code conversion.
[0004] Methods based on modified models mainly include:
[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, and 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: A Grammar-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 grammar information into the watermark insertion process by training a type predictor to predict the grammar type (keyword, identifier, etc.) of the next token.
[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 selection of vocabulary. The watermark embedding process takes into account the structural features of malicious code and further optimizes the output quality through probability outliers.
[0008] Code conversion-based methods mainly include:
[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 of code conversion based on semantic preservation for watermark embedding, which detects the existence of code patterns to identify watermarks, and identifies the author model of the code according to 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 2023 ACM SIGSAC Conference on Computer and Communications Security. 2023: 2336-2350. This work replaces code tokens in the output of large models with synonymous tokens, and embeds watermarks based on token distribution, which has great potential in preventing remote impersonation attacks.
[0011] (6) Sun Z, Du X, Song F, et al. Codemark: Imperceptible watermarking for code datasets against neural code completion models [C] / / Proceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering. 2023: 1561-1572. This work focuses on tracking code datasets during model training, and changes the distribution of code snippets by applying code transformations to form specific patterns as code watermarks in specific datasets.
[0012] The main defects of the above methods based on generation models are: the need to modify the prompt or model parameters when embedding watermarks, which is difficult to implement 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 token selection, which conflicts with the conditions for extracting watermarks in practical applications, as the original generation prompt is usually not available.
[0013] In the above methods based on code conversion, method (4) requires prior knowledge of which candidate transformations have been applied to the given code, which is usually not available in practical applications; methods (5) and (6) are not directly designed for large model code tracing requirements, and cannot effectively distinguish the source of the code when the generated code is mixed with human-written code, so they are not suitable for large model-related tracing tasks. SUMMARY
[0014] The purpose of the present application is to provide a reversible watermark-based large model code generation traceability method, system, device and medium, which overcomes the technical limitations of relying on prior knowledge, high watermark extraction error rate and inability to effectively trace the generated code model, providing higher security and traceability guarantee for the code generation field.
[0015] The purpose of the present application is achieved by the following technical solutions:
[0016] A reversible watermark-based large model code generation traceability method, the specific steps are as follows:
[0017] Step 1: reversible semantic preservation conversion applicability analysis is performed on the given code C, and a set of applicable conversion rules T is generated applicable ;
[0018] Step 2: a specific salt value salt is set for the large model, and for each rule T applicable in T i , the hash value of the string splicing of the rule name and salt is calculated, all hash values are sorted from large to small, and an ordered conversion rule sequence T sorted is generated ;
[0019] Step 3: set the corresponding watermark information w for the large model, generate the encoded watermark information w encoded through BCH, and select the corresponding reversible semantic conversion sub-rule T i,0 or T i,1 according to the corresponding bit value of w encoded ;
[0020] Step 4: according to step 2, the selected conversion sub-rule is applied to the given code C in order to generate the code C w embedded with the watermark ;
[0021] Step 5: reversible semantic preservation conversion applicability analysis is performed on the code C w embedded with the watermark or the code C # of unknown origin, and an applicable conversion rule set for the extraction stage is generated
[0022] Step 6: according to the specific salt value salt * of the extraction stage large model, calculate the hash value of the string splicing of the rule name and salt * for each rule in T , sort all hash values from large to small, and generate an ordered conversion rule sequence
[0023] Step 7: For the expected watermark information w e Perform BCH encoding to generate the expected watermark information.
[0024] Step 8: Apply the changes to each rule in the selected sequence of transformation sub-rules based on Step 6. Upon inspection, code C was found to be in compliance with the rules. and The state after that determines the bit value corresponding to the rule expression;
[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 the watermark and attempt to recover the original watermark information. ex ;
[0027] Step 11: Compare the original watermark information ω' ex and expected watermark information w e This enables the determination of generated code and the tracing of the generation model, thereby identifying the source of the code.
[0028] Furthermore, the Reversible Semantic Preservation Transformation Applicability Analysis (RSPT) specifically includes:
[0029] Let T be an equivalent semantic transformation rule. i :E - →E + E - and E + These are two abstract code patterns; in the traditional equivalence semantic transformation paradigm, E... - →E + Considered as a complete equivalent semantic transformation rule, in RSPT, an RSPT transformation rule consists of two symmetric 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 respectively i The two SPT rules in the text; therefore, an RSPT rule states that for any code segment C, there exists a code snippet c. - ∈E - ,c + ∈E+ , then
[0030] commutativity: T i,0 (c - ) = c + , T i,1 (c + ) = c -
[0031] idempotency: T i,0 (T i,0 (c - )) = c + , T i,1 (T i,1 (c + )) = c -
[0032] commutativity: T i,m (T j,n (C)) = T j,n (T i,m (C))
[0033] Under the RSPT paradigm, all E - and E + within a piece of code C can be fully converted into each other, thus, no matter whether the code form E present in the original code C is naturally equivalent to E - or E + , or both, it can be converted into a single fixed form E - or E + .
[0034] Further, the reversible semantics preserves the conversion applicability analysis, the specific process is as follows:
[0035] (1) The applicability analysis algorithm parses the code C into a specific syntax tree Tree;
[0036] (2) The applicability analysis algorithm checks the applicability of the rules on Tree by means of syntax tree node search, if the sub-rules T i or T i,0 of the rule T i,1 exist any number of nodes corresponding to them on Tree, then T i is considered to be applicable to C;
[0037]
[0038] wherein T i → C means that T i is applicable to C, n and m are nodes located on the specific syntax tree Tree, means that there are n nodes corresponding to Ti,0 The adapted node set is associated.
[0039] (3) Apply the transformation rule T i in step (2) to code C applicable .
[0040] Further, the step 2 sorts the rules according to the descending order of hash values of all rules in T applicable , sorted
[0041]
[0042] where sort represents a basic numerical sorting function, and hash represents the result of hash value calculation after string concatenation.
[0043] Further, the step 3 applies the first l rules in T encoded ,
[0044] to the encoded watermark 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 code space by taking the modulus of the generating polynomial g(x), to obtain the final code word sequence that satisfies the coding constraints; x is a formal variable in the polynomial, representing the expansion form of the watermark information in the polynomial domain.
[0048] Further, the step 4 applies the first l rules in T sorted sorted in step 2 to the encoded watermark w i , for each rule T encoded , extracts the corresponding bit bit from the encoded watermark w i,0 , bit is 0 or 1, and applies the transformation rule T i,1 or T w to code C according to the value of bit, and iterates the above process to obtain the code C i with embedded watermark,
[0049] T sorted = T sorted [i], if i < l
[0050]
[0051] Further, the step 9 is specifically:
[0052] For the encoded expected watermark information and From the conversion rule numbered i is sequentially taken out and the corresponding bit information bit 1 or 0 in , assuming the kth rule and exists, first, the forward verification of this bit information is performed, that is:
[0053]
[0054] Wherein, Tag positive is the Boolean value obtained by the forward verification;
[0055] Then, the reverse verification of this bit information is performed, since the bit is inverted, that is, the reverse verification is performed using the 0 value, that is:
[0056]
[0057] Wherein, Tag negative is the Boolean value obtained by the reverse verification;
[0058] Finally, according to Tag positive , Tag negative and the value of the expected kth bit information bit, the extraction bit value for this bit is obtained, that is:
[0059]
[0060] Wherein, ω ex [k] refers to the value of the kth bit information bit of ω ex , and is the inverted value of the bit information bit of . If the above conditions are not met, the code is not embedded with watermark, otherwise it is embedded with watermark.
[0061] Further, the step 10 is specifically:
[0062] ω ex is expressed as a polynomial:
[0063] r(x) = r0+r1x+r2x 2 +…+r n-1 x n-1
[0064] The synthetic value S of the check code word is calculated by the roots of the generated polynomial i :
[0065] S i = r (α i ), i = 1, 2, …, 2t
[0066] Wherein, α is the primitive element of the finite field GF(2 m );
[0067] The error locating polynomial σ(x) is calculated using the Berlekamp-Messay algorithm:
[0068] σ(x) = 1 + σ1x + σ2x 2 + … + σ t x t
[0069] The identified error position corresponding bit is flipped to obtain the corrected code word r'(x); the check bit is removed from r'(x) and the first k bits are extracted as the decoded watermark information ω' ex .
[0070] A computer device / apparatus / system, comprising a memory, a processor and a computer program stored on the memory, the processor executing the computer program to implement the steps of a large model generated code traceability method based on reversible watermarking.
[0071] A computer program product comprising computer programs / instructions that, when executed by a processor, implement the steps of a large model generated code traceability method based on reversible watermarking.
[0072] A computer-readable storage medium having stored thereon computer programs / instructions that, when executed by a processor, implement the steps of a large model generated code traceability method based on reversible watermarking.
[0073] The beneficial effects of the present application are:
[0074] With the wide application of large language models (LLMs) in code generation tasks, the authenticity and author traceability of codes have become increasingly prominent. However, existing code watermark traceability methods often rely on unobtainable prior knowledge, such as prompt information when generating code, limiting their practical application and having many deficiencies and limitations in terms of attack resistance.
[0075] To solve the above problems, the present application can embed and extract watermark by equivalent transformation of original syntax and structural semantics under the premise of maintaining code function, realize watermark embedding and extraction with zero prior knowledge, and is suitable for various programming languages, including strict syntax C and C++. Code transformation is realized through specific syntax tree, ensuring support for complex code structure and minimizing code modification of watermark.
[0076] In addition, the design of the present application has certain attack resistance. First, by adopting a salted hash strategy to sort the applicable rules, the salted hash value is calculated for all candidate rules and their sub-rules, ensuring that the watermark has pseudo-randomness, effectively preventing rainbow table attacks based on pre-computed hash value tables that attackers may implement. Second, by introducing BCH error correction code, the watermark can automatically correct bit errors caused by accidental modification or malicious destruction during extraction, improving the attack resistance and reliability of the watermark. BRIEF DESCRIPTION OF DRAWINGS
[0077] Figure 1 The flowchart of the method of the present application. DETAILED DESCRIPTION
[0078] The present application will be further described below in conjunction with the accompanying drawings.
[0079] According to Figure 1 A flowchart of a large model generated code traceability method based on reversible watermarking. In the watermark embedding stage, first, the code conversion applicability verifier is used to verify the code conversion applicability of the given code to identify the applicable code conversion method. Then, based on the given salt value, the sequence of applicable conversion methods is reordered, and by selectively applying these conversions, the watermark embedding of the generated code is systematically completed. In the traceability stage, given a piece of code to be verified, the method systematically identifies and verifies the applied conversion by combining bidirectional state verification with error correction decoding, then extracts the watermark information and performs error correction, and finally realizes the traceability of the generated model according to the extracted watermark.
[0080] In the present application, when reversible semantic preservation conversion applicability analysis and watermark extraction are mentioned, the code C refers to all possible compatible codes of the method. In the watermark embedding method, the code C mentioned refers only to the generated code produced by the large language model M through input prompts.
[0081] C = M(P)
[0082] Where M is a large language model, and P is a pre-defined prompt.
[0083] The present application takes the reversible equivalent semantic transformation paradigm (RSPT) as the necessary basis for the method of the present application, and the reversible equivalent semantic transformation paradigm (RSPT) is specifically:
[0084] Let T be an equivalence semantic transformation rule i - → E + , where E - and E + are two abstract code patterns. In the traditional equivalence semantic transformation paradigm, E - → E + is considered as a complete equivalence semantic transformation rule. In RSPT, a RSPT transformation rule is composed of two symmetric equivalence semantic transformation rules, a RSPT rule is denoted as T i : [E - → E + , E + → E - ], T i,0 and T i,1 correspond to the two SPT rules in T i respectively. Therefore, a RSPT rule indicates that for any code C, where any code segment c - ∈ E - , c + ∈ E + , we have:
[0085] (1) Commutativity: T i,0 (c - ) = c + , T i,1 (c + ) = c -
[0086] (2) Idempotency: T i,0 (T i,0 (c - )) = c + , T i,1 (T i,1 (c + )) = c -
[0087] (3) Associativity: T i,m (T j,n (C)) = T j,n (T i,m (C))
[0088] Under the RSPT paradigm, all E - and E + within a code are completely transformable to each other. Therefore, no matter whether the code form E exists in the original code C is naturally equivalent to E - or E + , or both exist, it can be transformed into a single fixed form E - Or E + .
[0089] The application is a large model code traceability method based on reversible watermarking, and the specific steps are as follows:
[0090] Step 1: reversible semantic preservation conversion applicability analysis is performed on the given code C to generate a set of applicable conversion rules T aplicable ;
[0091] For a given code C and a set of reversible equivalent semantic conversion rules T, the reversible semantic preservation conversion applicability analysis algorithm is as follows:
[0092] (1) The applicability analysis algorithm parses the code C into a specific syntax tree Tree, which is processed by the next step.
[0093] (2): The applicability analysis algorithm checks the applicability of the rules on Tree through syntax tree node search, and if the sub-rules T i or T i,0 of the rule T i,1 exist in any number of nodes corresponding to them on Tree, then T i is considered to be applicable to C.
[0094]
[0095] (3) The conversion rule T i applicable to the code C in step (2) is added to the conversion rule set T applicable applicable to the current code.
[0096] Step 2: Watermark embedding
[0097] Step 2.1: Set a specific salt value salt for the large model, and for each rule T applicable in T i , calculate the hash value of the string concatenation of the rule name and salt, sort all hash values from large to small, and generate an ordered conversion rule sequence T sorted ;
[0098] T sorted =sort(T applicable ,key=hash(t,salt))
[0099] Where, sort represents a basic numerical sorting function, hash(t,salt) represents the result obtained by calculating the hash value after string concatenation.
[0100] Step 2.2: Set the corresponding watermark information w for the large model, and generate the encoded watermark information wencoded ,
[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 code 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, representing the expansion form of the watermark information in the polynomial domain;
[0105] According to the corresponding bit value bit of w encoded , the corresponding reversible semantic conversion sub-rule T i,0 or T i,1 is selected;
[0106] Step 2.3: The first l rules in the sorted conversion rule set T sorted obtained in step 2.1, for each rule T i , the corresponding bit (0 or 1) is extracted from the encoded watermark w encoded , and the conversion rule T i,0 or T i,1 is applied to the code C according to the value of bit, and the above process is iterated to obtain the code C embedded with the watermark w .
[0107] T i =T sorted [i],ifi<l
[0108]
[0109] Step 3: Watermark extraction and tracing
[0110] Step 3.1: Perform reversible semantic preservation conversion applicability analysis on the code C w embedded with the watermark or the code C # of unknown origin, and generate the applicable conversion rule set for the extraction stage
[0111] Step 3.2: According to the salt value salt * specific to the large model in the extraction stage, apply each rule T in T Calculation rule name With salt * The hash values after string concatenation are sorted in descending order according to the rules to generate an ordered sequence of transformation rules.
[0112]
[0113] Step 3.3: For the expected watermark information w e Perform BCH encoding to generate the expected watermark information.
[0114] Step 3.4: Based on Step 3.2, the watermark extraction algorithm iterates through the sorted set of applicable conversion rules. The first l rules in the set, for each rule By examining code C in the application rules and After determining the state, the extracted watermark information is determined, and the corresponding bit value is determined according to the rule expression.
[0115] Step 3.5: Sequentially check the ordered transformation rule sequence T sorted Each rule within From C w Extract watermark information w ex ;
[0116] For the encoded expected watermark information and from Extract the transformation rule for number i in sequence And in The corresponding bit information of the label is 1 or 0. Assuming the k-th rule as well as If it exists, first perform a positive verification on this piece of information, that is:
[0117]
[0118] Among them, Tag positive It is the Boolean value obtained from the positive verification;
[0119] Then, perform reverse verification on this piece of information, because... Therefore, we invert this bit, that is, we use the value 0 for reverse verification, i.e.:
[0120]
[0121] Among them, Tag negative It is the Boolean value obtained from reverse verification;
[0122] Ultimately, according to Tagpositive , Tag negative and the value of the kth bit of the information bit, the extraction bit value for this bit is obtained, i.e.:
[0123]
[0124] where ω ex [k] denotes the value of the kth bit of the information bit of ω ex , is the flipping value of the bit of the information bit of ω .
[0125] If none of the above conditions are met, the code is not embedded with watermark, otherwise it is embedded with watermark.
[0126] Step 3.6: using the BCH decoding algorithm, decode w ex to attempt to recover the original watermark information ω' ex ;
[0127] Let ω ex be represented as a polynomial:
[0128] r(x) = r0+ r1x+ r2x 2 + … + r n-1 x n-1
[0129] The syndrome value S i of the check code word is calculated by the root of the generating polynomial:
[0130] S i = r(α i ), i = 1, 2, …, 2t
[0131] where α is the primitive element of the finite field GF(2 m );
[0132] The error locating polynomial σ(x) is calculated using the Berlekamp-Massey algorithm:
[0133] σ(x) = 1 + σ1x+ σ2x 2 + … + σ t x t
[0134] The identified error position is flipped to obtain the corrected code word r'(x); the check bits are removed from r'(x) and the first k bits are extracted as the decoded watermark information ω' ex .
[0135] Step 3.7: by comparing the original watermark information ω' ex and the expected watermark information w e, to realize the judgment of the generated code and the tracing of the generated model, and then determine the source of the code.
[0136] Embodiment 1
[0137] The present application verifies the proposed large model code generation code tracing method based on reversible watermarking in two aspects, including watermark extraction capability and attack resistance.
[0138] (1) Watermark extraction capability:
[0139] Table 1 shows the evaluation results of the present application in the watermark extraction task. The experimental data set is based on the cross-language project-level code generated by the large model ChatGPT-4o and the agent ChatDev, including the MsgACC results before and after applying BCH encoding error correction (4-bit encoding is correctly identified as a correctly identified sample). The experimental results are shown in Table 1, where the watermark encoding part shows the watermark information before BCH encoding. Next, the experimental results are analyzed. First, on the data sets of the three languages, for each watermark information sequence, this method shows almost perfect MsgACC, for example, on the data sets of C and Python languages, the MsgACC of each watermark information extraction before and after correction is 100%, showing the accuracy and stability of the watermark information extraction of this method. The lowest MsgACC obtained on the C++ language data set also reached 99.60%. In summary, this method has excellent watermark extraction accuracy.
[0140] Table 1 Watermark extraction capability evaluation results
[0141]
[0142] (2) Attack resistance:
[0143] Table 2 shows the evaluation results of the watermark extraction capability of the present application in the context of a destructive attack. The experiment assumes that the attacker knows the technical details of watermark embedding and extraction, but cannot obtain all the information in the regular order. The simulated attacker destroys the watermark encoding by randomly selecting 1 conversion from the rule set. The attacker can reverse some bits or destroy the encoding sequence. Analysis of the experimental results shows that, compared with the normal state, the pre-correction MsgACC decreases by about 20%, which indicates that this attack will seriously affect the integrity of the watermark information without error correction code, but the comparison between the post-correction MsgACC and the normal state shows that the BCH error correction algorithm almost restores all the destroyed watermark information. For example, in the case of embedding the 0101 watermark information in the C language data set, the attack reduces the pre-correction MsgACC from 100% to 78.83%, but the post-correction MsgACC is restored to 100%, which is the same as the normal state. The post-correction MsgACC of all data sets under this attack condition decreases by at most 0.2%.
[0144] Table 2 Anti-attack experiment results
[0145]
[0146] The foregoing embodiments of the reversible watermark-based large model generation code provenance method involve all relevant contents of each step, which can be cited in the functional description of the corresponding functional modules of the deep forgery detection explainable system based on causal analysis in the embodiments of the present application. Here, no further elaboration is made.
[0147] The division of modules in the embodiments of the present application is illustrative, and is only a logical functional division. In actual implementation, there can be another division manner. In addition, each functional module in each embodiment of the present application can be integrated in one processor, or can be physically separated, or two or more modules can be integrated in one module. The integrated module can be realized in the form of hardware or in the form of a software functional module.
[0148] In another embodiment of the present application, a computer device is provided, which comprises a processor and a memory for storing a computer program comprising program instructions, and the processor is configured to execute the program instructions stored in the computer storage medium. The processor can be a central processing unit (CPU), and can also 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., which are the computing core and control core of the terminal, and are suitable for implementing one or more instructions, and are specifically suitable for loading and executing one or more instructions in the computer storage medium to implement a corresponding method process or a corresponding function; the processor in the embodiments of the present application can be used for the operation of the code provenance method based on reversible watermarking of large models.
[0149] In another embodiment of the present application, the present application further provides a storage medium, specifically a computer readable storage medium (Memory), which is a memory device in a computer device, and is used for storing programs and data. It can be understood that the computer readable storage medium here can include the built-in storage medium in the computer device, and of course can also include the expansion storage medium supported by the computer device. The computer readable storage medium provides a storage space, which stores the operating system of the terminal. Moreover, one or more instructions suitable for being loaded and executed by the processor are also stored in the storage space, and these instructions can be one or more computer programs (including program codes). It should be noted that the computer readable storage medium here can be a high-speed RAM memory, or a non-volatile memory such as at least one disk memory. One or more instructions stored in the computer readable storage medium can be loaded and executed by the processor to implement the corresponding steps of the code provenance method based on reversible watermarking of large models in the above embodiments.
[0150] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0151] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations 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, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0152] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0153] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0154] The above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the specific implementation of the present invention. Any modifications or equivalent substitutions that do not depart from the spirit and scope of the present invention should be covered within the protection scope of the claims of the present invention.
Claims
1. A method for generating code provenance of a large model based on reversible watermarking, characterized in that: Step 1: For the given code Perform Reversible Semantic Preservation Transformation Applicability Analysis (RSPT) to generate a set of applicable transformation rules. The Reversible Semantic Preservation Transformation Applicability Analysis (RSPT) specifically involves: denoting an equivalent semantic transformation rule as... ,in and These are two abstract code patterns; in the traditional equivalent semantic transformation paradigm, Considered as a complete equivalent semantic transformation rule, in RSPT, an RSPT transformation rule consists of two symmetric equivalent semantic transformation rules. An RSPT rule is denoted as... , and Corresponding to The two SPT rules in the code; therefore, an RSPT rule indicates that for any given piece of code There are still code snippets in it. Then we have: Interchangeability: Idempotency: ; Exchangeability: = ; In the RSPT paradigm, all and within a piece of code are fully convertible, so that regardless of the form of code present in the original code or , or both, it can be converted to a single fixed form or ; the process is as follows: (1) the suitability analysis algorithm parses the code into a concrete syntax tree ; (2) The applicability analysis algorithm checks the applicability of the rule on the syntax tree by searching the nodes of the syntax tree. If there are any number of nodes corresponding to the sub-rules of the rule on the syntax tree, the rule is considered applicable. ; wherein, represents is adapted for , and is a node located on a specific syntax tree , represents that there exists a node associated with a set of nodes to which the node is adapted. (3) Apply the code in step (2) Conversion rules Add to the set of transformation rules applicable to the current code middle; Step 2: Set a specific salt value for the large model ,right Each rule in Calculation rule name and After string concatenation Value, all Sort the rules by value from largest to smallest to generate an ordered sequence of transformation rules. ; Step 3: setting corresponding watermark information for the large model , generating encoded watermark information through BCH , and selecting corresponding reversible semantic conversion sub-rules according to the corresponding bit values of ; or ; or ; Step 4: Apply the selected transformation sub-rules in sequence to the given code according to step 2 In this case, the code with the embedded watermark is generated ; Step 5: reversible semantic preserving transformation applicability analysis is performed on the code with watermark embedded or code of unknown origin performing reversible semantic preserving transformation applicability analysis, generating a set of applicable transformation rules for the extraction phase ; Step 6: According to the salt value of the extraction stage model specific to the salt value , for each rule , the rule name , the value of after string splicing with , the value of , sort all values from large to small, and generate an ordered conversion rule sequence ; Step 7: Performing BCH encoding on the expected watermark information to generate encoded expected watermark information ; Step 8: Check each rule in the selected sequence of transformation sub-rules against the code After applying the rule and determine the bit value corresponding to the rule expression; Step 9: Sequentially check the ordered transformation rule sequence each rule within the , extract watermark information from ; Step 10: Using the BCH decoding algorithm, decode attempt to recover the original watermark information ; Step 11: Determining the generation code by comparing the original watermark information with the expected watermark information , realizing the determination of the generation code and the traceability of the generation model, and further determining the source of the code.
2. The method of claim 1, wherein: The step 2 is according to all rules of the rules are sorted in descending order of the values, resulting in , ; wherein, represents a basic numerical ordering function, represents the result of a value calculation performed after string concatenation. represents the result of a value calculation performed after string concatenation.
3. The method of claim 1, wherein: The encoded watermark information in step 3 , ; ; ; wherein, is the watermark information; By taking modulo of the generating polynomial , the original information polynomial is mapped into a specific encoding space to get the final codeword sequence satisfying the encoding constraint; is the formal variable in the polynomial, representing the expansion form of the watermark information in the polynomial domain.
4. The method of claim 1, wherein: Step 4 involves sorting the set of transformation rules from step 2. The first l rules in the set, for each rule From the encoded watermark Extract the corresponding bit, where the bit is 0 or 1, and apply the conversion rule based on the bit value. or Applied to code The above process is iterated to obtain the code with the embedded watermark. , ; 。 5. The method of claim 1, wherein: the step 9 is specifically: For the encoded expected watermark information and ,from Take out the number in sequence Conversion rules and in The corresponding label Information bits or Assuming the first One rule as well as If it exists, first perform a positive verification on this piece of information, that is: ; ; wherein is the Boolean value resulting from the positive verification; The bit is again verified in reverse, and since the bit is inverted, i.e. the value is verified in reverse, i.e.: ; ; wherein is the Boolean value resulting from the reverse verification; Finally, depending on , and the value of the expected bit of information, the value of the extraction for this bit is obtained, i.e.: ; ; wherein, pointing the first bit value of the information bit, is the inverted value of the 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.
6. The method of claim 1, wherein: the step 10 is specifically: will be described below. expressed as a polynomial: ; Computing the syndrome value of the check code word by generating the roots of the polynomial : ; wherein is a primitive element of the finite field of order Calculating error-locating polynomials using the berlekamp-massey algorithm : ; Flip the bits corresponding to the identified error positions to obtain a corrected codeword ; remove the check bits from , and extract the first bits as the decoded watermark information .
7. A computer system comprising a memory, a processor, and a computer program stored on the memory, wherein: the processor executes the computer program to implement the steps of the method of any one of claims 1 to 6.
8. A computer program product comprising computer programs / instructions, characterized in that: The computer program / instructions, when executed by the processor, implement the steps of the method of any one of claims 1 to 6.
9. A computer readable storage medium having stored thereon computer programs / instructions, characterized in that: The computer program / instructions, when executed by the processor, implement the steps of the method of any one of claims 1 to 6. The computer program / instructions, when executed by the processor, implement the steps of the method of any one of claims 1 to 6.
Citation Information
Patent Citations
Multi-detector watermark detection method and device, equipment, storage medium and product
CN118821087A
Big language model dual watermark embedding method
CN119357929A