A smart contract upgrading method, device, equipment and storage medium

By dividing smart contracts into forwarding contracts and data contracts, and dissolving and re-establishing the calling relationship, the problem of large user-side modifications during smart contract upgrades is solved, enabling an upgrade process that does not require user-side modifications. Furthermore, the amount of modification is reduced by storing business data through key-value pairs.

CN115511622BActive Publication Date: 2026-02-10SHANGHAI NANOJCLEAN TECHNOLOGY CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202110692949.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-06-22
Publication Date
2026-02-10
Estimated Expiration
2041-06-22

AI Technical Summary

Technical Problem

During the upgrade of smart contracts, existing technologies require modifications to the user side, especially when the data structure of business logic contracts changes, resulting in significant modifications.

Method used

The smart contract is divided into a decoupled forwarding contract and a data contract. After receiving an upgrade request, the old calling relationship between the old business logic contract and the forwarding contract is terminated, a new calling relationship between the new business logic contract and the forwarding contract is established, and the data storage address of the new business logic contract is configured to be the address of the data contract, while the address of the forwarding contract remains unchanged, so as to provide calling for the new business logic contract.

Benefits of technology

During the upgrade of smart contracts, no changes need to be made to the user side, reducing the amount of modification required. Business data is stored in a key-value pair manner, ensuring that the data contract does not need to be modified when the data structure changes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115511622B_ABST
    Figure CN115511622B_ABST
Patent Text Reader

Abstract

The application discloses an upgrading method of a smart contract, the smart contract comprising a business logic contract and an agent contract, the agent contract being further divided into a forwarding contract and a data contract which are decoupled from each other; the forwarding contract is used for forwarding a calling request of a user to the business logic contract, and the data contract is used for storing business data generated when the business logic contract is called; the old calling relationship between the old business logic contract and the forwarding contract is cancelled, a new calling relationship between the new business logic contract and the forwarding contract is established, and the data storage address of the new business logic contract is configured as the address of the data contract, so as to realize the upgrading of the old business logic contract to the new business logic contract; during the upgrading, the address of the forwarding contract remains unchanged for the user, so that the forwarding contract is used as an interface to provide the calling of the new business logic contract to the user after the upgrading of the old business logic contract to the new business logic contract is completed; in this way, the user side does not need to be changed, and the amount of change is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of blockchain technology, and in particular to a method, apparatus, device, and computer-readable storage medium for upgrading smart contracts. Background Technology

[0002] Smart contracts are a typical application of blockchain technology. They can be deployed on the blockchain and are essentially coded instances of contracts between two parties. They are based on a replicable, shared distributed ledger and execute transactions according to the terms of the contract.

[0003] In some cases, it's necessary to upgrade the business logic portion of a smart contract. For example, a vulnerability in a smart contract could allow it to be compromised by hackers or other malicious actors, leading to financial losses. However, when deploying the upgraded smart contract, its address will differ from the old one. This necessitates coordination with all users to ensure they access the new smart contract through its new address.

[0004] To minimize modifications to the user side, the industry categorizes smart contracts into proxy contracts and business logic contracts. The proxy contract handles request forwarding and data storage, while the business logic contract implements the business logic, thus decoupling the two. In some examples, users can invoke the business logic contract through the proxy contract, and the business data generated when the business logic contract is invoked is stored in the proxy contract. Therefore, upgrading a smart contract only requires upgrading the business logic contract, without modifying the logic in the proxy contract responsible for forwarding requests, and consequently, eliminating the need to upgrade the proxy contract itself and thus avoiding any modifications to the user side.

[0005] However, upgrading the business logic contract may cause changes to the data structure of the business data generated when the business logic contract is invoked. This, in turn, necessitates adaptation modifications to the proxy contract to store the changed business data. Therefore, even with the approach of dividing smart contracts into proxy contracts and business logic contracts, upgrades still inevitably involve significant changes to the user side. Summary of the Invention

[0006] To address the aforementioned technical problems, this application provides a method, apparatus, device, and storage medium for upgrading smart contracts. This method eliminates the need for modifications to the user side during the smart contract upgrade process, thereby reducing the amount of modification required.

[0007] The embodiments of this application disclose the following technical solutions:

[0008] Firstly, this application provides a method for upgrading a smart contract, wherein the smart contract includes a business logic contract and a proxy contract; the proxy contract includes a decoupled forwarding contract and a data contract; the forwarding contract is used to forward user calls to the business logic contract, and the data contract is used to store business data generated when the business logic contract is called; the method includes:

[0009] Receive an upgrade request for the smart contract, the upgrade request carrying a new business logic contract obtained after upgrading the old business logic contract;

[0010] According to the upgrade request, the old calling relationship between the old business logic contract and the forwarding contract is terminated, a new calling relationship between the new business logic contract and the forwarding contract is established, and the data storage address of the new business logic contract is configured as the address of the data contract, so as to upgrade the old business logic contract to the new business logic contract.

[0011] During the process of upgrading the old business logic contract to the new business logic contract, the address of the forwarding contract remains unchanged for the user, so that after the upgrade of the old business logic contract to the new business logic contract is completed, the user can be provided with the call to the new business logic contract through the forwarding contract as an interface.

[0012] In some possible implementations, the data contract stores the business data generated when the business logic contract is invoked in key-value pairs.

[0013] In some possible implementations, the business request includes a data storage request, and the key-value pair includes a primary key and a field; the method further includes:

[0014] The interface receives data storage requests, which carry primary keys and fields.

[0015] Create a new association between the primary key and the field in the data contract;

[0016] Based on the aforementioned relationship, the business data generated when the business logic contract is invoked is stored in the field corresponding to the primary key.

[0017] In some possible implementations, the business request includes a data retrieval request, and the method further includes:

[0018] The interface receives a data retrieval request, which carries the target primary key.

[0019] Search the data contract for the target association corresponding to the target primary key;

[0020] Based on the target association, return the business data stored in the target field corresponding to the target primary key.

[0021] In some possible implementations, the method further includes:

[0022] The new business logic contract is determined to meet preset conditions;

[0023] The preset condition is that the new business logic contract passes the test.

[0024] In some possible implementations, the data contract is also used to store temporary data, which is data that can be lost after the smart contract is upgraded.

[0025] Secondly, this application provides a smart contract upgrade device, wherein the smart contract includes a business logic contract and a proxy contract; the proxy contract includes a decoupled forwarding contract and a data contract; the forwarding contract is used to forward user call requests to the business logic contract, and the data contract is used to store business data generated when the business logic contract is called; including:

[0026] A receiving unit is configured to receive an upgrade request for the smart contract, the upgrade request carrying a new business logic contract obtained after upgrading the old business logic contract;

[0027] The upgrade unit is used to, according to the upgrade request, terminate the old calling relationship between the old business logic contract and the forwarding contract, establish a new calling relationship between the new business logic contract and the forwarding contract, and configure the data storage address of the new business logic contract as the address of the data contract, so as to upgrade the old business logic contract to the new business logic contract.

[0028] During the process of upgrading the old business logic contract to the new business logic contract, the address of the forwarding contract remains unchanged for the user, so that after the upgrade of the old business logic contract to the new business logic contract is completed, the user can be provided with the call to the new business logic contract through the forwarding contract as an interface.

[0029] In some possible implementations, the data contract stores the business data generated when the business logic contract is invoked in key-value pairs.

[0030] In some possible implementations, the business request includes a data storage request, and the key-value pair includes a primary key and a field; the apparatus further includes a storage unit.

[0031] The receiving unit is further configured to receive a data storage request through the interface, the data storage request carrying a primary key and a field;

[0032] The storage unit is used to establish a new association between the primary key and the field in the data contract; and to store the business data generated when the business logic contract is called into the field corresponding to the primary key according to the association.

[0033] In some possible implementations, the service request includes a data acquisition request, and the device further includes a reading unit;

[0034] The receiving unit is further configured to receive a data acquisition request through the interface, wherein the data acquisition request carries a target primary key;

[0035] The reading unit is used to find the target association corresponding to the target primary key in the data contract; and return the business data stored in the target field corresponding to the target primary key based on the target association.

[0036] In some possible implementations, the device further includes a testing unit;

[0037] The testing unit is used to determine whether the new business logic contract meets preset conditions;

[0038] The preset condition is that the new business logic contract passes the test.

[0039] In some possible implementations, the data contract is also used to store temporary data, which is data that can be lost after the smart contract is upgraded.

[0040] Thirdly, this application provides a computing device, comprising:

[0041] A memory for storing computer programs and transferring the computer programs to the processor;

[0042] A processor configured to execute the method described in any one of the first aspects according to instructions in the computer program.

[0043] Fourthly, this application provides a computer-readable storage medium for storing computer software instructions that, when the computer-readable storage medium is run on a computer, enable the computer to perform the method described in any one of the first aspects above.

[0044] As can be seen from the above technical solution, this application has the following advantages:

[0045] This application provides a method for upgrading smart contracts. This method further decouples the proxy contract within the smart contract, dividing it into a decoupled forwarding contract and a data contract. Upon receiving an upgrade request for the smart contract, based on the new business logic contract obtained after upgrading the old business logic contract (included in the upgrade request), the old calling relationship between the old business logic contract and the forwarding contract is terminated, a new calling relationship is established between the new business logic contract and the forwarding contract, and the data storage address of the new business logic contract is configured to be the address of the data contract. During the upgrade process from the old business logic contract to the new business logic contract, the address of the forwarding contract remains unchanged for the user. This ensures that after the upgrade is complete, the user is provided with access to the new business logic contract through the forwarding contract. Thus, even if the data structure of the business data changes after upgrading from the old to the new business logic contract, the decoupling of the data contract and the forwarding contract eliminates the need to modify the forwarding contract itself (i.e., the forwarding contract's address remains unchanged), thereby significantly reducing the amount of modification required on the user side.

[0046] Furthermore, this data contract can store business data generated when the business logic contract is invoked in a key-value pair format, achieving the effect of using a general data structure to store business data. Thus, even if the data structure of the business data changes, there is no need to modify the data contract. Attached Figure Description

[0047] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0048] Figure 1 A schematic diagram of a blockchain system provided in an embodiment of this application;

[0049] Figure 2 A flowchart illustrating a smart contract upgrade method provided in this application embodiment;

[0050] Figure 3 This is a schematic diagram of a smart contract upgrade device provided in an embodiment of this application. Detailed Implementation

[0051] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.

[0052] To facilitate understanding by those skilled in the art, the technical terms involved in this application will be introduced below.

[0053] Smart contracts are a typical application of blockchain technology. Deployed on the blockchain, smart contracts are essentially coded instances of contracts between two parties, based on a replicable, shared distributed ledger, and execute transactions according to the provisions of the transaction contract.

[0054] However, in some cases, it is necessary to upgrade the part of the smart contract that is responsible for business logic in order to patch the vulnerabilities in the smart contract and prevent intrusion by hackers and other malicious actors.

[0055] Upgrading smart contracts involves changes to the contract's address, necessitating modifications to the user side so users can invoke the smart contract using the new address. To minimize user-side modifications, the industry categorizes smart contracts into proxy contracts and business logic contracts. However, even in this approach, changes to the data structure of business data generated when the business logic contract is invoked still require modifications to the proxy contract, ultimately impacting user-side modifications and resulting in significant changes.

[0056] In view of this, embodiments of this application provide a method for upgrading a smart contract. This method can be executed by a blockchain system. The smart contract includes a business logic contract and a proxy contract. The proxy contract includes a decoupled forwarding contract and a data contract: the forwarding contract forwards user calls to the business logic contract, and the data contract stores business data generated when the business logic contract is called. Specifically, the method includes: the blockchain system receiving an upgrade request for a smart contract, the upgrade request carrying a new business logic contract obtained after upgrading the old business logic contract; the blockchain system, according to the upgrade request, deactivating the old call relationship between the old business logic contract and the forwarding contract, establishing a call relationship between the new business logic contract and the forwarding contract, and configuring the data storage address of the new business logic contract as the address of the data contract, thereby upgrading the old business logic contract to the new business logic contract; wherein, during the upgrade process, the address of the forwarding contract remains unchanged for the user, so that after the upgrade is complete, the user is provided with the call to the new business logic contract through the forwarding contract. Thus, this method allows for upgrades to smart contracts without requiring modifications to the user side, thereby reducing the amount of changes needed.

[0057] To make the technical solution of this application clearer and easier to understand, the blockchain system provided in the embodiments of this application will be introduced below.

[0058] like Figure 1 The diagram shows a blockchain system 100, which includes a forwarding contract 110, a business logic contract 120, and a data contract 130.

[0059] Among them, the forwarding contract 110 and the data contract 130 are decoupled. The forwarding contract 110 is responsible for forwarding the user's call request to the business logic contract 120, and the data contract 130 is used to store the business data generated when the business logic contract 120 is called.

[0060] When it is necessary to upgrade the business logic contract in the blockchain system 100, such as upgrading the old business logic contract 121 to the new business logic contract 122, the blockchain system will terminate the old call relationship between the old business logic contract 121 and the forwarding contract 110, establish a new call relationship between the new business logic contract 122 and the forwarding contract 110, and configure the data storage address of the new business logic contract 122 as the address of the data contract 130.

[0061] Because the forwarding contract 110 and the data contract 130 are decoupled, when the old business logic contract 121 is upgraded to the new business logic contract 122, even if the data structure of the business data generated when the new business logic contract 122 is called changes, and the data contract 130 is modified, the forwarding contract 110 will not be affected. That is, no changes need to be made to the user side, thereby reducing the amount of changes required for smart contract upgrades.

[0062] To make the technical solution of this application clearer and easier to understand, the upgrade method of smart contracts provided in the embodiments of this application will be introduced from the perspective of a blockchain system.

[0063] like Figure 2 The flowchart shown illustrates a smart contract upgrade method, which includes:

[0064] S201: The blockchain system receives an upgrade request for a smart contract, the upgrade request carrying a new business logic contract obtained after upgrading the old business logic contract.

[0065] The smart contract comprises a business logic contract and a proxy contract. This method further decouples the proxy contract, resulting in a forwarding contract and a data contract. The forwarding contract forwards user requests to the business logic contract, while the data contract stores the business data generated when the business logic contract is invoked.

[0066] The old business logic contract may be a vulnerability-laden contract, while the new business logic contract is a contract obtained by fixing the vulnerabilities in the old contract. This new business logic contract is included in the upgrade request so that the blockchain system can upgrade the business logic portion of the smart contract based on the upgrade request.

[0067] S202: Based on the upgrade request, the blockchain system terminates the old call relationship between the old business logic contract and the forwarding contract, establishes a new call relationship between the new business logic contract and the forwarding contract, and configures the data storage address of the new business logic contract to the address of the data contract, so as to upgrade the old business logic contract to the new business logic contract.

[0068] Specifically, dissolving the old call relationship between the old business logic contract and the forwarding contract means ceasing to use the old business logic contract. When the forwarding contract receives a user's call request again, it will no longer forward the request to the old business logic contract. Establishing a new call relationship between the new business logic contract and the forwarding contract means that when the forwarding contract receives a user's call request again, it will forward the request to the new business logic contract, thus enabling the user to call the new business logic contract.

[0069] The blockchain system then configures the data storage address of the new business logic contract to the address of the data contract. In this way, when the new business logic contract is called, the generated business data can be stored in the original data contract.

[0070] During the upgrade from the old business logic contract to the new one, the address of the forwarding contract remains unchanged for the user, thus requiring no modifications to the user side. Once the upgrade is complete, the blockchain system uses the forwarding contract as an interface to provide users with access to the new business logic contract. In this way, users can invoke the new business logic contract simply by forwarding it.

[0071] In some implementations, data contracts can store business data generated when the business logic contract is invoked in key-value pairs. When data contracts store business data in key-value pairs, they can achieve the effect of a general data structure. Therefore, if the data structure of the business data changes, there is no need to modify the data contract; only the appropriate key-value pairs need to be selected.

[0072] For example, the old data structure is "Name-Gender", and the new data structure is "Name-Gender-Age". It's clear that a new "Age" field has been added to the data structure. When a data contract stores business data using key-value pairs, the relationships between the primary key and fields can be preset, such as "1-Name", "2-Gender", and "3-Age". In this way, when the data structure of the business data changes, only the corresponding primary key needs to be selected, without requiring upgrades or modifications to the data contract, thus reducing the amount of modification required.

[0073] In some implementations, the business request includes a data storage request, and the key-value pair includes a primary key and a field. The method further includes: the blockchain system receiving the data storage request through the aforementioned interface (i.e., the forwarding contract), the data storage request carrying the primary key and field; establishing a new association between the primary key and the field in the data contract; and storing the business data generated when the business logic contract is invoked into the field corresponding to the primary key based on the association.

[0074] It is evident that even if the data structure of business data changes, the use of key-value pairs to store business data achieves the effect of a general data structure, thus eliminating the need to modify the data contract and further reducing the amount of modification required.

[0075] In some implementations, the business request includes a data acquisition request. The method further includes: the blockchain system receiving the data acquisition request through the interface, the data acquisition request carrying a target primary key; searching for the target association corresponding to the target primary key in the data contract; and returning the business data stored in the target field corresponding to the target primary key based on the target association. Thus, this method enables the storage of business data within the data contract.

[0076] In some implementations, the method further includes: the blockchain system determining that the new business logic contract meets preset conditions, wherein the preset conditions are that the new business logic contract passes the test.

[0077] For example, before deploying a new business logic contract in the blockchain, the blockchain system needs to test the new business logic contract to determine the vulnerabilities in the old business logic contract that the new business logic contract addresses.

[0078] In some implementations, the data contract is also used to store temporary data, which is data that may be lost after a smart contract upgrade. During a smart contract upgrade, some data may be lost, and this lost data can be stored in the data contract.

[0079] This application provides an example of a business logic contract, as follows:

[0080] VIP180 contract

[0081] / **Data Contract - Data Can Be Lost* /

[0082] string public name; / / Full name of the token

[0083] string public symbol; / / token symbol

[0084] uint64 public totalSupply; / / Total token supply

[0085] event Transfer(address indexed_from,address indexed_to,uint256indexed_tokenId);

[0086] / **Data Contracts - General Data Structures* /

[0087] KVStorage public database;

[0088] function mintToken(uint256 _tokenId, address _owner) external onlyOwner

[0089] whenNotPaused {

[0090] / / solium-disable-next-line

[0091] require(mintable, "mintToken: mint token disabled");

[0092] require(ownerOf(_tokenId) == address(0), "mintToken: token already exist");

[0093] _clearAndTransfer(address(0), _owner, _tokenId, "");

[0094] }

[0095] / / / @notice Returns the number of tokens owned by the owner

[0096] function balanceOf(address owner)

[0097] public

[0098] view

[0099] returns (uint256)

[0100] {

[0101] return database.getUInt256(keccak256(abi.encodePacked("balanceOf", owner)));

[0102] }

[0103] / / / @notice Returns the address of the token holder based on the tokenId

[0104] function ownerOf(uint256 tokenId)

[0105] public

[0106] view

[0107] returns(address)

[0108] {

[0109] return database.getAddress(keccak256(abi.encodePacked("ownerOf",tokenId)));

[0110] }

[0111] / / ...

[0112] / / / @notice transfer assets

[0113] function transfer(address to,uint256 tokenId)public whenNotPaused{

[0114] require(to!=address(0),"invalid to");

[0115] require(msg.sender!=to,"sender and to is the same");

[0116] require(_isApprovedOrOwner(msg.sender,tokenId),"permission denied");

[0117] _clearAndTransfer(msg.sender,to,tokenId,"");

[0118] }

[0119] / / / @notice transfers the specified token from the _from account to the _to account and clears expired authorization information.

[0120] function_clearAndTransfer(address_from,address_to,uint256_tokenId,bytes

[0121] memory_data)

[0122] internal

[0123] {

[0124] require(_from != address(0) || _to != address(0), "must not be both empty");

[0125] require(_checkOnVIP181Received(_from, _to, _tokenId, _data), "transfer to non

[0126] VIP181Receiver implementer");

[0127] / / 181 does not need to use SafeMath

[0128] / / 1. Increase in supply

[0129] if (_from == address(0) && _to != address(0)) {

[0130] totalSupply++;

[0131] database.increaseBy(keccak256(abi.encodePacked("balanceOf", _to)), 1);

[0132] }

[0133] / / 2. Transfer

[0134] else if (_from != address(0) && _to != address(0)) {

[0135] database.decreaseBy(keccak256(abi.encodePacked("balanceOf", _from)), 1);

[0136] database.increaseBy(keccak256(abi.encodePacked("balanceOf", _to)), 1);

[0137] }

[0138] / / 3. Destroy

[0139] else if (_from != address(0) && _to == address(0)) {

[0140] totalSupply--;

[0141] database.decreaseBy(keccak256(abi.encodePacked("balanceOf",_from)),1);

[0142] }

[0143] / / Clear approval authorization information

[0144] database.setAddress(keccak256(abi.encodePacked("approval",_tokenId)),

[0145] address(0));

[0146] database.setAddress(keccak256(abi.encodePacked("ownerOf",_tokenId)),_to);

[0147] emit Transfer(_from,_to,_tokenId);

[0148] }

[0149] }

[0150] Based on the above description, the smart contract upgrade method provided in this application decouples the proxy contract in the smart contract again, dividing it into a decoupled forwarding contract and a data contract. Upon receiving an upgrade request for the smart contract, based on the new business logic contract obtained after upgrading the old business logic contract carried in the upgrade request, the old calling relationship between the old business logic contract and the forwarding contract is terminated, a new calling relationship is established between the new business logic contract and the forwarding contract, and the data storage address of the new business logic contract is configured as the address of the data contract. During the upgrade of the old business logic contract to the new business logic contract, the address of the forwarding contract remains unchanged for the user, so that after the upgrade is completed, the user is provided with the call to the new business logic contract through the forwarding contract as an interface. Thus, after upgrading the old business logic contract to the new business logic contract, even if the data structure of the business data changes, because the data contract and the forwarding contract are decoupled, there is no need to modify the forwarding contract; that is, the address of the forwarding contract remains unchanged, and therefore no changes are needed on the user side, greatly reducing the amount of modification required.

[0151] Furthermore, this data contract can store business data generated when the business logic contract is invoked in a key-value pair format, achieving the effect of using a general data structure to store business data. Thus, even if the data structure of the business data changes, there is no need to modify the data contract.

[0152] This application embodiment also provides a smart contract upgrade device, wherein the smart contract includes a business logic contract and a proxy contract; the proxy contract includes a decoupled forwarding contract and a data contract; the forwarding contract is used to forward user call requests to the business logic contract, and the data contract is used to store business data generated when the business logic contract is called. Figure 3 The diagram shows a smart contract upgrade device, which includes:

[0153] The receiving unit 301 is used to receive an upgrade request for the smart contract, the upgrade request carrying a new business logic contract obtained after upgrading the old business logic contract;

[0154] Upgrade unit 302 is used to, according to the upgrade request, terminate the old calling relationship between the old business logic contract and the forwarding contract, establish a new calling relationship between the new business logic contract and the forwarding contract, and configure the data storage address of the new business logic contract as the address of the data contract, so as to upgrade the old business logic contract to the new business logic contract.

[0155] During the process of upgrading the old business logic contract to the new business logic contract, the address of the forwarding contract remains unchanged for the user, so that after the upgrade of the old business logic contract to the new business logic contract is completed, the user can be provided with the call to the new business logic contract through the forwarding contract as an interface.

[0156] In some possible implementations, the data contract stores the business data generated when the business logic contract is invoked in key-value pairs.

[0157] In some possible implementations, the business request includes a data storage request, and the key-value pair includes a primary key and a field; the device further includes a storage unit 303.

[0158] The receiving unit 301 is also configured to receive a data storage request through the interface, the data storage request carrying a primary key and a field;

[0159] The storage unit 303 is used to establish a new association between the primary key and the field in the data contract; and to store the business data generated when the business logic contract is called into the field corresponding to the primary key according to the association.

[0160] In some possible implementations, the service request includes a data acquisition request, and the device further includes a reading unit 304;

[0161] The receiving unit 301 is further configured to receive a data acquisition request through the interface, wherein the data acquisition request carries a target primary key;

[0162] The reading unit 304 is used to find the target association relationship corresponding to the target primary key in the data contract; and return the business data stored in the target field corresponding to the target primary key according to the target association relationship.

[0163] In some possible implementations, the device further includes a test unit 305;

[0164] The test unit 305 is used to determine whether the new business logic contract meets preset conditions.

[0165] The preset condition is that the new business logic contract passes the test.

[0166] In some possible implementations, the data contract is also used to store temporary data, which is data that can be lost after the smart contract is upgraded.

[0167] This application also provides a computing device, including:

[0168] A memory for storing computer programs and transferring the computer programs to the processor;

[0169] A processor is used to execute the smart contract upgrade method described above according to instructions in the computer program.

[0170] This application also provides a computer-readable storage medium for storing computer software instructions that, when the computer-readable storage medium is run on a computer, enable the computer to execute the smart contract upgrade method described above.

[0171] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on its differences from other embodiments. In particular, the device embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments. The system embodiments described above are merely illustrative. The units and modules described as separate components may or may not be physically separate. Furthermore, some or all of the units and modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0172] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.

[0173] The above are merely preferred embodiments of this application and are not intended to limit the application in any way. Although this application has disclosed preferred embodiments above, it is not intended to limit the application. Any person skilled in the art can make many possible variations and modifications to the technical solutions of this application using the methods and techniques disclosed above, or modify them into equivalent embodiments with equivalent changes, without departing from the scope of the technical solutions of this application. Therefore, any simple modifications, equivalent changes, and modifications made to the above embodiments based on the technical essence of this application without departing from the content of the technical solutions of this application shall still fall within the protection scope of the technical solutions of this application.

Claims

1. A method for upgrading smart contracts, characterized in that, The smart contract includes a business logic contract and a proxy contract; the proxy contract includes a decoupled forwarding contract and a data contract; the forwarding contract is used to forward user calls to the business logic contract, and the data contract is used to store business data generated when the business logic contract is called; the method includes: Receive an upgrade request for the smart contract, the upgrade request carrying a new business logic contract obtained after upgrading the old business logic contract; According to the upgrade request, the old calling relationship between the old business logic contract and the forwarding contract is terminated, a new calling relationship between the new business logic contract and the forwarding contract is established, and the data storage address of the new business logic contract is configured as the address of the data contract, so as to upgrade the old business logic contract to the new business logic contract. During the process of upgrading the old business logic contract to the new business logic contract, the address of the forwarding contract remains unchanged for the user, so that after the upgrade of the old business logic contract to the new business logic contract is completed, the user can be provided with the call to the new business logic contract through the forwarding contract as an interface. The data contract stores the business data generated when the business logic contract is invoked in a key-value pair format.

2. The method according to claim 1, characterized in that, The business request includes a data storage request; the key-value pair includes a primary key and a field; the method further includes: The interface receives data storage requests, which carry primary keys and fields. Create a new association between the primary key and the field in the data contract; Based on the aforementioned relationship, the business data generated when the business logic contract is invoked is stored in the field corresponding to the primary key.

3. The method according to claim 2, characterized in that, The business request includes a data acquisition request, and the method further includes: The interface receives a data retrieval request, which carries the target primary key. Search the data contract for the target association corresponding to the target primary key; Based on the target association, return the business data stored in the target field corresponding to the target primary key.

4. The method according to claim 1, characterized in that, The method further includes: The new business logic contract is determined to meet preset conditions; The preset condition is that the new business logic contract passes the test.

5. The method according to any one of claims 1 to 4, characterized in that, The data contract is also used to store temporary data, which is data that may be lost after the smart contract is upgraded.

6. A smart contract upgrade device, characterized in that, The smart contract includes a business logic contract and a proxy contract; the proxy contract includes a decoupled forwarding contract and a data contract; the forwarding contract is used to forward user calls to the business logic contract, and the data contract is used to store business data generated when the business logic contract is called; including: A receiving unit is configured to receive an upgrade request for the smart contract, the upgrade request carrying a new business logic contract obtained after upgrading the old business logic contract; The upgrade unit is used to, according to the upgrade request, terminate the old calling relationship between the old business logic contract and the forwarding contract, establish a new calling relationship between the new business logic contract and the forwarding contract, and configure the data storage address of the new business logic contract as the address of the data contract, so as to upgrade the old business logic contract to the new business logic contract. During the process of upgrading the old business logic contract to the new business logic contract, the address of the forwarding contract remains unchanged for the user, so that after the upgrade of the old business logic contract to the new business logic contract is completed, the user can be provided with the call to the new business logic contract through the forwarding contract as an interface. The data contract stores the business data generated when the business logic contract is invoked in a key-value pair format.

7. A computing device, characterized in that, include: A memory for storing computer programs and transferring the computer programs to a processor; A processor for executing the method of any one of claims 1 to 5 according to instructions in the computer program.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store computer software instructions that, when the computer-readable storage medium is run on a computer, enable the computer to perform the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Ethereum-based intelligent contract updating method and system, storage medium and terminal

    CN109977638A

  • Execution method and device of smart contract in blockchain and electronic equipment

    CN112400182A

  • Data query method and device, storage medium and electronic equipment

    CN112905600A