Blockchain Reflection Mechanism via Wasm Metadata

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Current blockchain technologies lack an efficient mechanism for implementing reflection in smart contracts, which limits the flexibility and dynamic execution of functions within contracts.

Innovation Solution

A method for implementing a reflection mechanism in a blockchain involves a compiler that generates metadata for types and functions in contract source code, packages this metadata into a Wasm file, and compiles reflection code into bytecode that can execute functions dynamically based on metadata during runtime.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Adaptability or versatility

If traditional blockchain smart contracts are used, then the basic transfer transaction function is provided, but the flexibility and dynamic execution capability is limited

Engineering Contradiction:
Improveflexibility and dynamic execution capabilityVSAvoidcontract execution mechanism complexity
Core Design Contradiction:
Adaptability or versatilityVSDevice complexity

Solution Approach 1:

The patent segments the contract execution mechanism into distinct components: metadata storage for type information, reflection code for dynamic function discovery, and a compilation process that transforms source code into Wasm format with embedded metadata. This segmentation allows each component to be optimized independently while working together to provide flexible dynamic execution.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The patent implements preliminary action by generating and packaging metadata during the compilation phase before contract execution. The metadata containing type information is pre-computed and embedded in the Wasm file, enabling the virtual machine to perform efficient runtime reflection without requiring complex on-demand computation during contract execution.

Inventive Principle:
Principle #10Preliminary action

2Adaptability or versatility

If reflection mechanism is added to blockchain, then dynamic function calling capability is improved, but the compilation and execution complexity increases

Engineering Contradiction:
Improvedynamic function calling capabilityVSAvoidcompilation and execution complexity
Core Design Contradiction:
Adaptability or versatilityVSDevice complexity

Solution Approach 1:

The patent introduces metadata as an intermediary between the contract source code and the execution process. This metadata layer contains pre-computed type information that mediates between the static compilation phase and dynamic execution phase, enabling reflection functionality without significantly increasing execution complexity.

Inventive Principle:
Principle #24Intermediary (Mediator)

Solution Approach 2:

The patent replaces complex runtime mechanical systems for dynamic function discovery with a pre-computed metadata approach. Instead of performing complex analysis during execution, the system uses pre-generated metadata structures that enable fast reflection operations, substituting runtime computation with compile-time preparation.

Inventive Principle:
Principle #28Mechanics substitution (Replace mechanical system)

3Productivity

If metadata packaging is implemented in Wasm file, then runtime execution efficiency is improved, but the file size and packaging complexity increases

Engineering Contradiction:
Improveruntime execution efficiencyVSAvoidpackaging complexity
Core Design Contradiction:
ProductivityVSDevice complexity

Solution Approach 1:

The patent merges the metadata packaging process with the existing Wasm compilation process. The metadata is integrated into the Wasm file structure during compilation, combining type information storage with the code compilation operation. This merging approach avoids separate packaging steps and leverages existing Wasm infrastructure.

Inventive Principle:
Principle #5Merging (Combining)

Data Source

PatentUS20250199778A1Implementing reflection mechanism in blockchain
Publication Date: 2025.06.19 ANT BLOCKCHAIN TECHNOLOGY (SHANGHAI) CO LTD
  • US20250199778A1 patent drawing
  • US20250199778A1 patent drawing
  • US20250199778A1 patent drawing

AI summary

Methods, apparatuses, and computer-readable media for implementing a reflection mechanism in a blockchain are described. In an example process, a compiler compiles contract source code comprising reflective programming into a Wasm file. The compiler generates metadata of a first type and a first function in the first type, and packages the metadata in the Wasm file; and generates contract bytecode of a second function that obtains a first function type and first function content according to dynamic parameters. After receiving a transaction that calls a contract, a virtual machine loads the Wasm file, uses the metadata in the Wasm file to initialize a part of a memory in a created linear memory region; and parses and executes the contract bytecode in the Wasm file. When executing the bytecode of the second function, the virtual machine determines and executes, based on the metadata, the first function in the linear memory region.