Wasm Smart Contract Execution With Codehash Caching
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing smart contract execution engines face performance issues due to the inefficiencies of WebAssembly (Wasm) bytecode execution, particularly in blockchain environments, where complex functions like the start function incur significant overheads and time consumption.
Innovation Solution
Optimize Wasm bytecode by determining a codehash of the Wasm contract, creating a linear memory, and executing the bytecode with a Wasm virtual machine instance, optimizing and caching a Wasm module object to improve execution efficiency.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Speed
If Wasm bytecode is executed directly without optimization, then the execution process is simple, but the execution speed is slow and overhead is high
Solution Approach 1:
The patent applies preliminary action by optimizing Wasm bytecode before execution. The system performs bytecode optimization in advance, converting unoptimized Wasm bytecode into optimized form and caching the results. This preliminary optimization reduces execution overhead and improves speed during actual contract execution, resolving the contradiction between execution speed and process complexity.
2Productivity
If Wasm bytecode is optimized and cached, then execution efficiency is improved, but memory usage increases
Solution Approach 1:
The patent extracts only the necessary optimized components for caching. Instead of caching entire Wasm modules, the system extracts and caches specifically the optimized bytecode portions that will be reused during execution. This selective extraction reduces memory consumption while maintaining execution efficiency benefits.
3Reliability
If complex functions like start function are executed, then complete functionality is achieved, but overhead and time consumption increase
Solution Approach 1:
The patent extracts and removes unnecessary complex functions from the Wasm bytecode during optimization. Specifically, the start function and other non-essential complex functions are identified and extracted, reducing execution overhead while maintaining the core functionality needed for smart contract execution. This resolves the contradiction between functionality completeness and time consumption.
Data Source
AI summary
Smart contract calling is described. A blockchain node receives a transaction that calls a contract. The transaction indicates a called contract account address, a called function, and an input parameter, and the contract is a WebAssembly (Wasm) contract existing before optimization. The blockchain node determines a codehash of the Wasm contract based on the contract account address, and optimizes Wasm bytecode corresponding to the codehash, to obtain and cache a Wasm module object. Each process of executing the Wasm bytecode includes: starting a Wasm virtual machine instance, creating a linear memory corresponding to the instance based on the cached Wasm module object, and filling the linear memory. Code is executed in a code segment in the Wasm module object based on the filled linear memory and the input parameter.


