IP Library › Granted Patent US 12,327,088
Granted Patent B1
US 12,327,088 · App. 19/031,223 · Granted Jun 10, 2025

Method and system for generating abstract of smart contract based on large language model and semantic enhancement

Inventors: Xiaoqi Li (Haikou, CN); Yingjie Mao (Haikou, CN); Wenkai Li (Haikou, CN); Xin Wang (Haikou, CN); Lei Xie (Haikou, CN)
Assignee: HAINAN UNIVERSITY
G06F40/30G06F40/211
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12,327,088
App. No.
19/031,223
Granted
Jun 10, 2025
Kind
B1
Abstract

A method and system for generating an abstract of a smart contract based on a large language model and semantic enhancement. The method includes: parsing a source code of a smart contract to generate an abstract syntax tree; extracting code semantic information; converting a contract function node of the abstract syntax tree into a function callback chart; and generating a high-quality abstract of code of the smart contract by utilizing the code semantic information extracted by the large language model and callback information in the function callback chart. By learning and understanding the semantic information and callback information of the smart contract function, the large language model can accurately understand and reason deep semantic information of the code to generate the high-quality abstract of the code of the smart contract. The a multi-model capability of the large language model to extract, understand, and reason the callback information of the function callback chart improves comprehension capability of the large language model on a code callback structure.

Claims (32)

1. A method for generating an abstract of a smart contract based on a large language model and semantic enhancement, comprising:

acquiring a source code of a smart contract, and parsing the source code of the smart contract to generate an abstract syntax tree;

extracting code semantic information in the source code of the smart contract from the abstract syntax tree;

traversing the abstract syntax tree, converting the source code of the smart contract into a function callback chart, and storing the function callback chart and the code semantic information in a code sample database;

determining a target code segment, and searching for, in the code sample database, target code semantic information most similar to the target code segment and a target function callback chart; and

inputting a source code of the target code segment, the target code semantic information, and the target function callback chart into the large language model, and parsing data outputted by the large language model to obtain an abstract corresponding to the target code segment and outputting the abstract.

2. The method for generating an abstract of a smart contract based on a large language model and semantic enhancement according to claim 1 , wherein the parsing the source code of the smart contract to generate an abstract syntax tree comprises:

parsing the source code of the smart contract by using a solidity_parser tool, and taking the smart contract or a function in the source code of the smart contract as a root node, a sentence or expression as an internal node, and basic elements such as a variable and a constant as leaf nodes.

3. The method for generating an abstract of a smart contract based on a large language model and semantic enhancement according to claim 1 , wherein the code semantic information comprises a contract member variable, a contract type, a contract function, a function name, a function declaration, an introverted function, and function callback.

4. The method for generating an abstract of a smart contract based on a large language model and semantic enhancement according to claim 1 , wherein the traversing the abstract syntax tree, converting the source code of the smart contract into a function callback chart comprises:

traversing each contract node in the abstract syntax tree, traversing each function node in each contract node, and traversing a function callback node in each function node;

traversing each function callback node to obtain a function callback tree;

traversing each function callback node in the function callback tree to obtain callback information corresponding to each function callback node; and

obtaining a vector-free function callback chart based on the callback information.

5. The method for generating an abstract of a smart contract based on a large language model and semantic enhancement according to claim 4 , further comprising:

describing the callback information corresponding to the function callback node by using graphviz;

storing the function callback node after the callback information is described in an unordered non-repetitive element sequence; and

traversing each function callback node in the function callback tree, and searching for nodes in the non-repetitive element sequence till traversing the function callback tree to obtain the vector-free function callback chart.

6. The method for generating an abstract of a smart contract based on a large language model and semantic enhancement according to claim 1 , wherein the determining a target code segment, and searching for, in the code sample database, target code semantic information most similar to the target code segment and a target function callback chart comprise:

vectorizing the target code segment to obtain an input matching vector;

reading all function codes in the code sample database and converting each function code into a function code vector list;

matching the input matching vector with the function code vector list to output a target number corresponding to the function code vector most similar to the input matching vector; and

reading the target code semantic information and the target function callback chart from the code sample database according to the target number.

7. The method for generating an abstract of a smart contract based on a large language model and semantic enhancement according to claim 1 , wherein a training process of the large language model comprises:

determining sample code semantic information and a sample function callback chart and inputting the sample code semantic information and the sample function callback chart into the large language model; and

adjusting parameters in the large language model by taking the target code semantic information and the target function callback chart as learning objects.

8. A system for generating an abstract of a smart contract based on a large language model and semantic enhancement, comprising:

an abstract syntax generation module, configured to acquire a source code of a smart contract, and parse the source code of the smart contract to generate an abstract syntax tree;

an information extraction module, configured to extract code semantic information in the source code of the smart contract from the abstract syntax tree;

a data storage module, configured to traverse the abstract syntax tree, convert the source code of the smart contract into a function callback chart, and store the function callback chart and the code semantic information in a code sample database;

a searching module, configured to determine a target code segment, and search for, in the code sample database, target code semantic information most similar to the target code segment and a target function callback chart; and

an abstract generation module, configured to input a source code of the target code segment, the target code semantic information, and the target function callback chart into the large language model, and parse data outputted by the large language model to obtain an abstract corresponding to the target code segment and outputting the abstract.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Mar 21, 2025
From: LI, XIAOQI; MAO, YINGJIE; LI, WENKAI; WANG, XIN; XIE, LEI
To: HAINAN UNIVERSITY
Reel/Frame 070584/0721 →
Priority Claims (1)
CN 202410980531.5 · Jul 22, 2024 · national
References Cited (6)
US 10809984B2 · Mizrahi · 2020 [cited by examiner]
US 11068244B2 · Rich · 2021 [cited by examiner]
US 11301619B2 · Choudhari · 2022 [cited by examiner]
US 11893385B2 · Balasubramanian · 2024 [cited by examiner]
US 20230106226A1 · Bahrami · 2023 [cited by examiner]
US 20240111658A1 · Bo · 2024 [cited by examiner]
Cited By (1)
US 12,608,940