Smart Contract Bytecode Compilation for Blockchain Nodes

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Blockchain-based smart contracts face challenges in cross-platform scalability and execution efficiency due to differences in CPU architectures and instruction sets, leading to difficulties in ensuring consistent execution across various hardware and software environments.

Innovation Solution

The implementation of a method that compiles smart contract bytecode into machine code using global compilation methods like Ahead-of-Time (AoT) or Just-In-Time (JIT) compilation, optimizing for specific hardware and environments, and caching hotspot code for efficient execution, while also allowing local compilation to bypass time-consuming global compilation during service requests.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If global compilation methods (AoT or JIT) are used to compile smart contract bytecode into machine code, then execution efficiency is improved, but storage overhead increases due to caching machine code

Engineering Contradiction:
Improveexecution efficiencyVSAvoidstorage overhead
Core Design Contradiction:
ProductivityVSQuantity of substance

Solution Approach 1:

The patent applies local quality by differentiating the compilation approach based on code characteristics: hotspot code (frequently executed) is compiled and cached to machine code for high performance, while non-hotspot code remains in bytecode form. This selective compilation optimizes storage usage while maintaining execution efficiency for critical paths.

Inventive Principle:
Principle #3Local quality

Solution Approach 2:

The patent implements partial compilation rather than full compilation of all smart contract code. Only the necessary portion (hotspot code) is compiled to machine code and cached, while the rest remains as bytecode. This partial action reduces storage overhead while still achieving performance improvements for the most critical execution paths.

Inventive Principle:
Principle #16Partial or excessive action

2Reliability

If global compilation is performed for all smart contracts, then consistent execution across diverse nodes is ensured, but compilation time and resource consumption increase

Engineering Contradiction:
Improveexecution consistencyVSAvoidcompilation time
Core Design Contradiction:
ReliabilityVSLoss of time

Solution Approach 1:

The patent uses preliminary action by pre-compiling hotspot code to machine code and caching it before execution. This pre-compilation allows the system to bypass time-consuming compilation during service requests, ensuring both execution consistency and reduced latency.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent segments smart contract code into hotspot code and non-hotspot code, applying different compilation strategies to each segment. This segmentation allows selective compilation of only the critical paths that require consistent execution, reducing overall compilation time while maintaining reliability for essential operations.

Inventive Principle:
Principle #1Segmentation

3Speed

If machine code is cached for frequently executed code, then execution speed is improved, but memory usage increases

Engineering Contradiction:
Improveexecution speedVSAvoidmemory usage
Core Design Contradiction:
SpeedVSQuantity of substance

Solution Approach 1:

The patent applies local quality by identifying and caching only hotspot code (frequently executed portions) as machine code, while leaving non-hotspot code in bytecode form. This selective approach optimizes execution speed for critical paths while minimizing memory consumption by avoiding unnecessary compilation of less frequently executed code.

Inventive Principle:
Principle #3Local quality

Solution Approach 2:

The patent implements partial caching of only the necessary machine code portions. By caching only hotspot code rather than all compiled code, the system achieves execution speed improvements for critical operations while keeping memory usage proportional to the actual performance needs.

Inventive Principle:
Principle #16Partial or excessive action

Data Source

PatentEP3961375B1Improving smart contracts execution
Publication Date: 2023.11.29 ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
  • EP3961375B1 patent drawingFigure 1
  • EP3961375B1 patent drawingFigure 2~3
  • EP3961375B1 patent drawingFigure 4~5

AI summary

The present specification provides a method, a blockchain node, and a storage medium for executing a smart contract. An embodiment of the method for executing a smart contract includes: receiving, by a blockchain node, a request for creating a smart contract, where the request includes bytecode of the smart contract; compiling, by the blockchain node, the bytecode of the smart contract into first machine code by using a global compilation method after deploying the smart contract, and storing the first machine code; and executing, by the blockchain node when executing the deployed smart contract, the first machine code if the first machine code of the smart contract is locally stored. In the embodiments of the present application, when global compilation has not been completed, the bytecode of the smart contract is locally compiled and executed, so that normal processing of a blockchain service request can be ensured while global compilation is performed.