# US 12,067,377 B2 · System and a method for automatic generation of smart contracts across blockchain platforms

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 12,067,377 B2
- Document ID: US12067377B2
- Status: Granted
- Kind: B2
- Application number: 17/903,136
- Filed: 2022-09-06
- Published: 2023-03-09
- Granted: 2024-08-20
- Earliest claimed: 2021-09-06
- Assignees: Mphasis Limited
- Applicants: Mphasis Limited
- Inventors: Biju Mathews; Sanjeev Kumar Madhavan; Karthik Ganti; Chakkirala Venkata Sai Kalyani; Agnelo Marques
- Web page: https://patentgrep.com/patent/US12067377B2

## CPC

- G06F 8/30: Creation or generation of source code
- G06F 9/44: Arrangements for executing specific programs
- G06F 8/40: Transformation of program code
- G06F 8/427: {Parsing}
- H04L 9/50: {using hash chains, e.g. blockchains or hash trees}
- H04L 63/00: {Network architectures or network communication protocols for network security (cryptographic mechanisms or cryptographic arrangements for secret or secure communication H04L9/00; network architectures or network communication protocols for wireless network security H04W12/00; security arrangements for protecting computers or computer systems against unauthorised activity G06F21/00)}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- H04L: TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION (arrangements common to telegraphic and telephonic communication H04M)

## Abstract

The present invention provides for a system (100) and a method for generating smart contracts for blockchain platforms. An input received as natural language text is processed into a first parameter to generate a Domain Specific Language (DSL) construct. DSL construct is disintegrated into a stream of tokens and a syntax analysis is performed on the stream of tokens to check if the syntax of the DSL construct matches with a grammar file defined for the DSL construct. Each of the marked lines of the stream of tokens is read and the read marked lines are transformed into an organized structure. A file specific to a target blockchain platform is generated based on a second parameter and the organized structure is mapped with the generated file associated with the target blockchain platform to generate a target code template for generating a deployable target smart contract for the target blockchain platform.

## Claims

### Claim 1

A system for generating smart contracts for blockchain platforms, the system comprising:
a memory storing program instructions;
a processor executing program instructions stored in the memory and configured to execute a template generator engine to:
process input received as a natural language text into a first parameter to generate a Domain Specific Language (DSL) construct;
disintegrate the DSL construct into a stream of tokens;
perform a syntax analysis on the stream of tokens to check if the syntax of the DSL construct matches with a grammar file defined for the DSL construct, wherein the lines in the steam of tokens without error are marked;
read each of the marked lines of the stream of tokens and transform the read marked lines into an organized structure;
generate a file specific to a target blockchain platform based on a second parameter; and
map the organized structure with the generated file associated with the target blockchain platform to generate a target code template for generating a deployable target smart contract for the target blockchain platform, wherein the organized structure is an Abstract Syntax Tree (AST) that represents a source code corresponding to the DSL construct including a structure of instructions stated in the DSL construct.

### Claim 2 (depends on 1)

The system as claimed in claim 1, wherein the template generator engine comprises an input unit to process the first parameter comprising a formatted user story to generate the DSL construct, wherein a JSON file is created to list field names and data types for each attribute used in the DSL construct.

### Claim 3 (depends on 1)

The system as claimed in claim 1, wherein the DSL construct is implemented via an eclipse framework with a pre-determined set of rules for building the DSL construct, wherein the predetermined set of rules are defined in a structured file of an xtext framework, the predefined set of rules including keywords, identifiers, statements, and operators used in the DSL construct.

### Claim 4 (depends on 1)

The system as claimed in claim 1, wherein the DSL construct comprises syntax including an asset definition attribute, a function definition attribute and a contract definition attribute that represents the user story in a domain specific format.

### Claim 5 (depends on 1)

The system as claimed in claim 1, wherein each line of the stream of tokens is checked to identify any discrepancy with respect to a syntactic structure defined in the grammar file for the DSL construct.

### Claim 6 (depends on 1)

The system as claimed in claim 1, wherein the template generator engine comprises a lexer to define the grammar file for the DSL construct, and wherein the grammar file is defined using xtext and provides capability for parsing, linking, type checking and compilation of the DSL construct.

### Claim 7 (depends on 1)

The system as claimed in claim 1, wherein each node of the AST represents a specific and independent construct of the source code preserving details of the source code.

### Claim 8 (depends on 1)

The system as claimed in claim 1, wherein the AST comprises identifiers, assigned values and required operations that are defined in the DSL construct, and order of executions is retained in the AST.

### Claim 9 (depends on 1)

The system as claimed in claim 1, wherein the template generator engine comprises a semantic analyzer to analyze semantics of the organized structure without need to parse the DSL construct again, wherein generation of the organized structure is considered as indicative of correctness of the syntax in the DSL construct.

### Claim 10 (depends on 1)

The system as claimed in claim 1, wherein the template generator engine comprises a smart contract file generator to generate the second parameter indicative of the target blockchain platform based on a tag received from an input unit to generate the file in an xtend format (xtend file) specific to the target blockchain platform, wherein the xtend file comprises a structure required for generating the target code template.

### Claim 11 (depends on 10)

The system as claimed in claim 10, wherein the target smart contract code generator to pick up code snippets values from the AST and merge it with respective xtend files to create the target code template, wherein placeholder values in the xtend files are replaced with code snippet values from the AST.

### Claim 12 (depends on 1)

The system as claimed in claim 1, wherein the template generator engine comprises a target smart contract code generator that maps the file generated by a smart contract file generator in the template generator engine with the organized structure from a semantic analyzer in the template generator engine to generate the target code template.

### Claim 13 (depends on 1)

The system as claimed in claim 1, wherein the file generated for a specific target blockchain platform comprises structure, mappings, functions with implicit conditional checks and events for smart contracts.

### Claim 14 (depends on 1)

The system as claimed in claim 1, wherein a single solidity code template with required structure, functions, mappings, data and conditions is generated from a single xtend file.

### Claim 15

A method for generating smart contracts for blockchain platforms, the method comprising:
processing, by a processor, input received as a natural language text into a first parameter to generate a Domain Specific Language (DSL) construct;
disintegrating the DSL construct into a stream of tokens;
performing a syntax analysis on the stream of tokens to check if the syntax of the DSL construct matches with a grammar file defined for the DSL construct, wherein the lines in the steam of tokens without errors are marked;
reading each of the marked lines of the stream of tokens and transforming the read marked lines into an organized structure;
generating a file specific to a target blockchain platform based on a second parameter; and
mapping the organized structure with the generated file associated with the target blockchain platform to generate a target code template for generating a target smart contract for the target blockchain platform-, wherein the organized structure comprises creating an Abstract Syntax Tree (AST), the AST represents a source code of the DSL construct including a structure of instructions stated in the DSL construct.

### Claim 16 (depends on 15)

The method as claimed in claim 15, wherein the step of processing comprises processing the first parameter including a formatted user story to generate the DSL construct, wherein a JSON file is created to list field names and data types for each attribute used in the DSL construct.

### Claim 17 (depends on 15)

The method as claimed in claim 15, wherein the DSL construct is implemented via an eclipse framework with a pre-determined set of rules for building the DSL construct, wherein the predetermined set of rules are defined in a structured file of an xtext framework, the predefined set of rules including keywords, identifiers, statements, and operators used in the DSL construct.

### Claim 18 (depends on 15)

The method as claimed in claim 15, wherein the DSL construct comprises syntax including an asset definition attribute, a function definition attribute and a contract definition attribute that represents the user story in a domain specific format.

### Claim 19 (depends on 15)

The method as claimed in claim 15, wherein the step of disintegrating the DSL construct comprises converting a sequence of elements associated with attributed in the DSL construct into the stream of tokens, the elements comprising keywords, identifies, literals, operators and separators.

### Claim 20 (depends on 15)

The method as claimed in claim 15, wherein the step of performing a syntax analysis comprises checking each line of the stream of tokens to identify any discrepancy with respect to a syntactic structure defined in the grammar file for the DSL construct, the grammar file is defined using xtext and provides capability for parsing, linking, type checking and compilation of the DSL construct.

### Claim 21 (depends on 15)

The method as claimed in claim 15, wherein each node of the AST represents a specific and independent construct of the source code preserving details of the source code, and wherein order of executions are retained in the AST, the AST comprising identifiers, assigned values and required operations that are defined in the DSL construct.

### Claim 22 (depends on 15)

The method as claimed in claim 15, wherein semantics of the AST are analyzed without the need to parse the DSL construct again, wherein generation of the organized structure is considered as indicative of correctness of the syntax in the DSL construct.

### Claim 23 (depends on 15)

The system as claimed in claim 15, wherein the step of generating the file comprises generating the file in an xtend format (xtend file) which is specific to the target blockchain platform, the xtend file comprises a structure, mappings, functions with implicit conditional checks and events required for generating the target code template for generating the target smart contract.

### Claim 24 (depends on 23)

The method as claimed in claim 23, wherein the step of mapping comprises mapping the xtend file with the AST to generate the target code template.

### Claim 25 (depends on 23)

The method as claimed in claim 23, wherein the step of mapping comprises picking up code snippets values from the AST and merging the code snippets values with respective xtend files to create the target code template, wherein placeholder values in the xtend files are replaced with code snippet values from the organized structure.

### Claim 26 (depends on 15)

The method as claimed in claim 15, wherein the target code template is a single solidity code template with required structure, functions, mappings, data and conditions which is generated from a single xtend file.

### Claim 27

A computer program product comprising:
a non-transitory computer-readable medium having computer program code stored thereon, the computer-readable program code comprising instructions that, when executed by a processor, causes the processor to:
process input received as a natural language text into a first parameter to generate a Domain Specific Language (DSL) construct;
disintegrate the DSL construct into a stream of tokens;
perform a syntax analysis on the stream of tokens to check if the syntax of the DSL construct matches with a grammar file defined for the DSL construct, wherein the lines in the steam of tokens without error are marked;
read each of the marked lines of the stream of tokens and transform the read marked lines into an organized structure;
generate a file specific to a target blockchain platform based on a second parameter; and
map the organized structure with the generated file associated with the target blockchain platform to generate a target code template for generating a deployable target smart contract for the target blockchain platform, wherein the organized structure is an Abstract Syntax Tree (AST) that represents a source code corresponding to the DSL construct including a structure of instructions stated in the DSL construct.
