# US 2021/0081185 A1 · System and method for compiling high-level language code into a script executable on a blockchain platform

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

- Number: US 2021/0081185 A1
- Document ID: US20210081185A1
- Status: Published application
- Kind: A1
- Application number: 16/629,295
- Filed: 2018-07-05
- Published: 2021-03-18
- Earliest claimed: 2017-07-07
- Assignees: nChain Holdings Limited
- Applicants: nChain Holdings Limited
- Inventors: Craig Steven WRIGHT; Stephane SAVANAH
- Web page: https://patentgrep.com/patent/US20210081185A1

## CPC

- H04L 9/0618: {Block ciphers, i.e. encrypting groups of characters of a plain text message using fixed encryption transformation}
- G06F 8/31: {Programming languages or programming paradigms}
- G06F 8/41: Compilation
- G06F 8/433: {Dependency analysis; Data or control flow analysis}
- G06F 8/443: {Optimisation}
- G06F 8/452: {Loops}
- G06F 8/51: Source to source
- H04L 9/0637: {Modes of operation, e.g. cipher block chaining [CBC], electronic codebook [ECB] or Galois/counter mode [GCM]}
- H04L 9/0643: {Hash functions, e.g. MD5, SHA, HMAC or f9 MAC}
- H04L 9/3247: {involving digital signatures}
- H04L 9/3297: {involving time stamps, e.g. generation of time stamps}
- H04L 9/50: {using hash chains, e.g. blockchains or hash trees}
- H04L 63/1458: {Denial of Service}
- H04L 2209/56: Financial cryptography, e.g. electronic payment or e-cash
- H04L: TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION (arrangements common to telegraphic and telephonic communication H04M)
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A computer-implemented method (and corresponding system) is provided that enables or facilitates the execution of a portion of source code, written in a high-level language (HLL), on a blockchain platform. The method and system can include a blockchain compiler, arranged to convert a portion of high-level source code into a form that can be used with a blockchain platform. This may be the Bitcoin blockchain or an alternative. The method can include: receiving the portion of source code as input; and generating an output script comprising a plurality of op codes. The op codes are a subset of op codes that are native to a functionally-restricted, blockchain scripting language. The outputted script is arranged and/or generated such that, when executed, the script provides, at least in part, the functionality specified in the source code. The blockchain scripting language is restricted such that it does not natively support complex control-flow constructs or recursion via jump-based loops or other recursive programming constructs. The step of generating the output script may comprise the unrolling at least one looping construct provided in the source code. The method may further comprise providing or using an interpreter or virtual machine arranged to convert the output script into a form that is executable on a blockchain platform.

## Claims

### Claim 1

A computer-implemented method comprising the steps:
receiving a portion of source code as input, wherein the portion of source code is written in a high-level language (HLL); and
generating an output script comprising a plurality of op_codes selected from and/or native to a functionally-restricted, blockchain scripting language such that, when executed, the script provides, at least in part, the functionality specified in the portion of source code.

### Claim 2 (depends on 1)

A method according to claim 1 and comprising the step of: providing or using a compiler arranged to perform the steps of claim 1.

### Claim 3 (depends on 1)

A method according to claim 1 wherein the output script is generated by performing a static compilation.

### Claim 4 (depends on 1)

A method according to claim 1 wherein: the blockchain scripting language is restricted such that it does not natively support complex control-flow constructs, recursion and/or jump-based loops.

### Claim 5 (depends on 1)

The method of claim 1 wherein the step of generating the output script comprises:
unrolling at least one looping construct provided in the source code.

### Claim 6 (depends on 1)

The method of claim 1 and further comprising the step of:
providing or using an interpreter or virtual machine arranged to convert the output script into a form that is executable on a blockchain platform.

### Claim 7 (depends on 1)

The method of claim 1 and further comprising the step of:
optimising the output script at least once to provide a more efficient or reduced version of the output script.

### Claim 8 (depends on 1)

The method of claim 1 wherein the step of generating the output script comprises the use of derivative free optimisation.

### Claim 9 (depends on 1)

The method of claim 1 wherein: the HLL and/or a compiler component arranged to perform the steps of any preceding claim form part of a software development kit (SDK).

### Claim 10 (depends on 1)

The method of claim 1 wherein: the source code is arranged to implement a smart contract.

### Claim 11 (depends on 1)

The method of claim 1 wherein: the HLL comprises at least one primitive or construct which can be translated directly into one or more primitives native to the blockchain scripting language.

### Claim 12 (depends on 1)

The method of claim 1 wherein: the blockchain scripting language is stack-based and the HLL comprises one or more primitives arranged to perform an operation on a stack used by the blockchain scripting language.

### Claim 13 (depends on 1)

The method of claim 1 wherein: the HLL comprises a primitive arranged to push a number of inputs to the source code onto a stack used for memory allocation by the blockchain scripting language.

### Claim 14 (depends on 1)

The method of claim 1 wherein the HLL comprises at least one of the following primitives or operators or their functional equivalent:
Initiate;
Declare;
Increment;
IF;
While;
Populate;
Monus;
Reset;
Rawscript;
Abort;
Retrieve
Hash, hash 160, or another hash operation or a variation thereof.

### Claim 15

A computer-implemented method comprising the step of using static compilation to translate a portion of source code into a blockchain-compatible script, preferably wherein the static compilation comprises the step of loop unrolling.

### Claim 16 (depends on 1)

A computer-implemented system arranged to implement the steps of claim 1.

### Claim 17 (depends on 16)

A system according to claim 16 and comprising a compiler arranged to:
receive a portion of source code as input, the source code being written in a high-level language (HLL); and
generate an output script comprising a plurality of op_codes selected from a functionally-restricted, blockchain scripting language such that, when executed, the script provides, at least in part, the functionality specified in the source code.

### Claim 18 (depends on 16)

A system according to claim 16 and comprising a software development kit (SDK).

### Claim 19 (depends on 15)

A computer-implemented system arranged to implement the steps of claim 15.
