Processor Special Purpose Register for Smart Contract Gas Deduction
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
The existing methods for performing resource deduction in smart contracts on blockchain platforms are inefficient due to the use of general-purpose instructions, which makes the GAS deduction process a hot operation, affecting the execution efficiency of smart contracts.
Innovation Solution
The implementation of special-purpose extended instructions and registers within a processor to manage resource deduction, allowing for more efficient GAS balance management and deduction operations, reducing the number of clock cycles required for deduction processes.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Productivity
If general purpose instructions are used to perform GAS deduction operation, then the processor can execute the operation, but the execution efficiency of the smart contract is affected due to the operation being a hot operation (frequently performed)
Solution Approach 1:
The patent segments the GAS deduction operation from general-purpose instructions by introducing a dedicated counter register and specific deduction instructions. This separates the frequently executed deduction logic from the general instruction stream, allowing optimized handling of this hot operation while maintaining the universality of the processor for other tasks.
Solution Approach 2:
The patent introduces a counter register as an intermediary component between the general-purpose registers and the deduction logic. This counter register serves as a specialized buffer that stores the remaining GAS balance and facilitates efficient deduction operations through dedicated instructions, reducing the time penalty associated with frequent deductions.
2Reliability
If multiple general purpose instructions are used for GAS deduction, then the deduction can be performed, but the number of clock cycles required increases
Solution Approach 1:
The patent extracts the GAS balance management functionality from the general-purpose instruction set by introducing a dedicated counter register and specific deduction instructions (e.g., PUSH, POP, CALL, RETURN with gas accounting). This extraction consolidates multiple general instructions into a streamlined sequence that maintains correctness while reducing the instruction count for deduction operations.
3Reliability
If GAS deduction is performed before each basic block execution, then resource management is ensured, but the frequent execution makes it a hot operation affecting overall performance
Solution Approach 1:
The patent performs preliminary actions by pre-calculating and storing the GAS consumption of basic blocks during compilation, and by maintaining a dedicated counter register that is ready for rapid deduction. This preparation allows the hot deduction operation to execute efficiently during runtime, maintaining resource management accuracy without sacrificing execution speed.
Data Source
Figure 1~2
Figure 3
Figure 4
AI summary
Embodiments of the present specification provide methods and processors for performing resource deduction for execution of a smart contract. The method is performed by a processor, the processor includes a special purpose register, and the special purpose register stores a first resource balance for executing the smart contract. The method includes: reading a first extended instruction, where the first extended instruction includes a resource deduction quota corresponding to a predetermined code set, and performing the following operations based on the first extended instruction: reading the first resource balance from the special purpose register; comparing the first resource balance with the resource deduction quota; if the comparison result is that the first resource balance is greater than or equal to the resource deduction quota, subtracting the resource deduction quota from the first resource balance to obtain a second resource balance; and storing the second resource balance in the special purpose register.