A method for dynamically upgrading smart contracts based on proxy contracts in blockchain
By introducing a proxy contract architecture into the blockchain, the dynamic upgrade of smart contracts is solved, and the problem that smart contracts cannot be updated in real time in the Ethereum system is ensured, information security and data integrity are ensured, and blockchain technology is provided. New ideas and application prospects.
Patent Information
- Application Number
- CN202110811893.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-19
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2041-07-19
AI Technical Summary
In blockchain technology, especially in the Ethereum system, deployed smart contracts cannot be updated in real time, resulting in difficulties in upgrading and affecting the application and development of blockchain technology.
Adopt a dynamic upgrade method of smart contracts based on proxy contracts, and design a permanent storage agent, owner permanent storage agent and permanent storage module to realize online hot updates of smart contracts, and use hash value verification to ensure data and information security.
It has realized the dynamic upgrade of smart contracts, solved the problem that smart contracts cannot be updated in real time in the Ethereum system, ensured user information security and data integrity, and provided new ideas and application prospects for the future development of blockchain technology.
Smart Images

Figure CN114201206B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a smart contract upgrade method, and in particular to a smart contract dynamic upgrade method based on a proxy contract in a blockchain, and relates to the technical field of blockchain. Background Art
[0002] Blockchain technology is a programmable distributed ledger technology that is jointly maintained by multiple parties and uses cryptography to ensure verifiable transmission and access security, thereby achieving consistent data storage, difficulty in tampering, and non-repudiation. It is precisely because of the advantages of blockchain technology such as decentralization, tamper-proofing, data consistency, and process traceability that its application prospects in various industries have received great attention.
[0003] It can be said that the rapid development of blockchain technology has brought a new change to the current era. It allows different users to trust each other in the blockchain, fundamentally solving the problem of fraud in value transactions. The complete blockchain architecture is generally composed of the data layer, network layer, consensus layer, incentive layer, contract layer and application layer. The bottom layer of the blockchain uses technologies such as data blocks and encryption algorithms to form the data storage mechanism of the bottom layer of the blockchain.
[0004] A smart contract is a computer program that can run on a blockchain. It is a computer protocol that disseminates, verifies, and executes contracts in an information-based manner, allowing trusted transactions without a third party, and these transactions are traceable and irreversible. Smart contracts provide a security method that is superior to traditional contracts and reduces other transaction costs associated with contracts. Users can use smart contracts to conduct transactions and share data, and the characteristics of the blockchain ensure that the entire process of data storage, reading, and execution is traceable and cannot be tampered with. In general, users can create new smart contracts by calling the API interface of the blockchain node, and the installation and operation of each smart contract consumes certain resources. At present, there are two main methods that can be used to upgrade smart contracts, namely: 1. Use proxy contracts; 2. Separate logic and data into different contracts. The fundamental problem that these two methods want to solve is how to update the logic of the contract while still retaining access to the contract state.
[0005] However, as the application continues to deepen, technicians in the field have found that after deploying smart contracts on Ethereum, it will be impossible to update them, which has become one of the pain points of blockchain technology. In summary, if a new hot update blockchain method can be proposed and optimized to solve the problem of the inability to update smart contracts in real time in existing technologies, it will definitely provide great help to the future development and application of blockchain technology. Summary of the invention
[0006] In view of the above-mentioned defects in the prior art, the purpose of the present invention is to propose a method for dynamically upgrading smart contracts based on proxy contracts in blockchain, which is as follows.
[0007] A method for dynamically upgrading a smart contract based on an agent contract in a blockchain is implemented under a blockchain architecture, wherein the architecture includes a user end, a permanent storage agent, a logic smart contract, an owner's permanent storage agent, and a permanent storage module, wherein the user end, the permanent storage agent, and the logic smart contract are bidirectionally connected by signals, the permanent storage agent is also signal-connected to the owner's permanent storage agent and the permanent storage module respectively, and the logic smart contract is also signal-connected to the permanent storage module;
[0008] The method comprises the following steps:
[0009] S1, the permanent storage agent receives the message from the user end and retrieves the data from it;
[0010] S2, the permanent storage agent returns data to the logic smart contract;
[0011] S3. The logic smart contract completes the online hot update;
[0012] S4. The user terminal calls the updated logic smart contract.
[0013] Preferably, S1 specifically includes the following steps:
[0014] S11, initialize the permanent agent;
[0015] S12, the owner permanent storage agent sends a data request to the permanent storage agent;
[0016] S13, the permanent storage agent receives the data from the owner's permanent storage agent and decrypts the data;
[0017] S14, decrypting the updated content;
[0018] S15, after the decryption is completed, the data information is checked, and the data in the permanent storage module is called to determine whether the data structures of the two are consistent. If they are consistent, the message is decrypted continuously, otherwise an error prompt is returned and the process ends;
[0019] S16. The permanent storage agent completes decryption of the data and sends the data to the logical smart contract.
[0020] Preferably, S11 specifically includes the following steps:
[0021] S111. Deploy a permanent storage proxy contract in the blockchain architecture;
[0022] S112. Deploy the initial version of the logic smart contract in the blockchain architecture. The deployment of the logic smart contract is completed using the solidity language;
[0023] S113. Call the permanent storage proxy contract and register the address of the initial version of the logical smart contract into the proxy contract.
[0024] Preferably, S2 specifically includes the following steps:
[0025] S21, forward the data to the logical smart contract through the delegatecall opcode;
[0026] S22. During the data transmission process, the permanent storage agent uses the delegatecall operation code to store all data in the permanent storage module.
[0027] Preferably, S3 specifically includes the following steps:
[0028] S31. After receiving the update request, the logic smart contract calls the permanent storage module to compare the data and function status to ensure that the updated data structure is consistent with the structure defined in the initial version of the logic smart contract. If not, an error message is returned and the process ends.
[0029] S32. The logic smart contract receives an update request from the permanent storage agent, and then sends a request to the permanent storage module. The permanent storage module directly transmits the data to the logic smart contract to complete the update process.
[0030] S33. During the update process of the logical smart contract, a new hash check value will be generated for hash comparison when the user updates.
[0031] Preferably, S4 specifically includes the following steps:
[0032] S41. The user sends a call request to the logical smart contract and performs a hash check at the same time. When the logical smart contract is updated, the permanent storage agent sends a status code update request to all user terminals that call the logical smart contract.
[0033] S42, status code update request actively requests the user end to update;
[0034] S43. The user end updates and calls the updated logic smart contract normally, and then ends the process.
[0035] Compared with the prior art, the advantages of the present invention are mainly reflected in the following aspects:
[0036] A smart contract dynamic upgrade method proposed in the present invention is based on the technology of deploying smart contracts on the Ethereum blockchain. By designing a new proxy contract architecture, the dynamic upgrade of smart contracts is realized, which solves the common problem in the prior art that smart contracts deployed on the Ethereum system cannot be updated in real time.
[0037] In the solution of the present invention, the need for smart contract upgrade is solved by defining a permanent storage agent, an owner permanent storage agent and a permanent storage module. In the entire process, the method uses hash values for proofreading, which fully guarantees the user's information security, the security of the smart contract and the integrity of the data.
[0038] In addition, the solution of the present invention also provides a new idea for the related research and application of hot update of smart contracts, and provides a reference for other related issues in the same field. It can be used as a basis for expansion, extension and in-depth research, and has a very broad application prospect.
[0039] The specific implementation modes of the present invention are further described below in combination with the accompanying drawings of the embodiments, so that the technical solutions of the present invention are easier to understand and grasp. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 Schematic diagram of the upgrading process of the method of the present invention. DETAILED DESCRIPTION
[0041] The present invention discloses a method for dynamically upgrading a smart contract based on a proxy contract in a blockchain, such as Figure 1 As shown, it mainly uses the proxy contract method in the smart contract upgrade method. Although this method cannot directly update the deployed contract code, it can achieve the purpose of smart contract upgrade through a proxy contract architecture. The innovation of this invention lies in the design of a new proxy contract architecture for smart contract upgrade. The specific scheme is as follows.
[0042] A method for dynamically upgrading a smart contract based on an agent contract in a blockchain is implemented under a blockchain architecture. The architecture includes a user end, a permanent storage agent, a logic smart contract, an owner's permanent storage agent, and a permanent storage module. The user end, the permanent storage agent, and the logic smart contract are connected by two-way signals. The permanent storage agent is also connected by signals to the owner's permanent storage agent and the permanent storage module respectively, and the logic smart contract is also connected by signals to the permanent storage module.
[0043] The method of the present invention comprises the steps of:
[0044] S1, the permanent storage agent receives the message from the user end and retrieves the data from it;
[0045] S2, the permanent storage agent returns data to the logic smart contract;
[0046] S3. The logic smart contract completes the online hot update;
[0047] S4. The user terminal calls the updated logic smart contract.
[0048] Specifically, S1 includes the following steps:
[0049] S11, initialize the permanent agent;
[0050] S12. The owner's permanent storage agent sends a data request to the permanent storage agent; the request is encrypted by a hash algorithm to ensure that only the owner of the smart contract can send the corresponding data to the proxy contract. During the message transmission process, it is transmitted in the form of bytes, and its signature will be encrypted and attached to the first 31 bytes of the message (0x00-0x1F). When retrieving the message, it is necessary to start from position 0x20 (the 32nd byte), that is, the message is placed from byte 32 onwards.
[0051] S13. The permanent storage agent receives data from the owner's permanent storage agent and decrypts the data. After receiving the data, the permanent storage agent first decrypts the first 31 bytes to determine whether the signature saved by the logic contract is consistent with the signature received by the permanent agent. If they are consistent, the message will continue to be decrypted. Otherwise, an error prompt will be returned and the process will end.
[0052] S14, decrypt the updated content; As mentioned above, the first 0x20 bytes of the data are the signature of the smart contract owner, and the data will be taken from the 32nd byte until the end of the data. After getting the data, decrypt the data taken from the 32nd byte.
[0053] S15, after the decryption is completed, the data information is checked, and the data in the permanent storage module is called to determine whether the data structures of the two are consistent. If they are consistent, the message is decrypted continuously, otherwise an error prompt is returned and the process ends;
[0054] S16. The permanent storage agent completes decryption of the data and sends the data to the logical smart contract.
[0055] Furthermore, S11 specifically includes the following steps:
[0056] S111. Deploy a permanent storage proxy contract in the blockchain architecture;
[0057] S112. Deploy the initial version of the logic smart contract in the blockchain architecture. The deployment of the logic smart contract is completed using the solidity language;
[0058] S113. Call the permanent storage proxy contract and register the address of the initial version of the logical smart contract into the proxy contract.
[0059] Specifically, S2 includes the following steps:
[0060] S21, forward the decrypted data in S1 to the logical smart contract through the delegatecall opcode; in the blockchain system, the solidity language can use opcodes to call smart contracts, generally there are delegatecall opcodes and call opcodes. The functions of the delegatecall opcode and the call opcode are similar, the only difference is that the former only uses the code of the given address, and other information uses the current contract (such as storage, balance, etc.). The delegatecall opcode is used in the present invention, through which data can be sent to the specified address and the function call status can be retained.
[0061] S22. During the data transmission process, the permanent storage agent uses the delegatecall opcode to store all data in the permanent storage module. The permanent storage module defines all variable information and data structures in the smart contract. When the delegatecall opcode is used to update the state, the state of the contract is retained and only part of the data is updated. The method of the present invention only changes the value of the logical smart contract, but does not change the address of the smart contract.
[0062] Specifically, S3 includes the following steps:
[0063] S31. After receiving the update request, the logic smart contract calls the permanent storage module to compare the data and function status to ensure that the updated data structure is consistent with the structure defined in the initial version of the logic smart contract. If not, an error message is returned and the process ends.
[0064] It is important to note here that subsequent versions of the logic smart contract should not define any additional state variables, and all versions of the logic smart contract must always use the storage structure defined at the beginning.
[0065] S32. The logic smart contract receives an update request from the permanent storage agent, and then sends a request to the permanent storage module. The permanent storage module directly transmits the data to the logic smart contract to complete the update process.
[0066] S33. During the update process of the logical smart contract, a new hash check value will be generated for hash comparison when the user updates.
[0067] Specifically, S4 includes the following steps:
[0068] S41. The user sends a call request to the logical smart contract and performs a hash check to verify the integrity of the contract and ensure that the contract cannot be tampered with by non-smart contract owners. When the logical smart contract is updated, the hash value will be different. Therefore, when the logical smart contract is updated, the permanent storage agent will send a status code update request to all user terminals that call the logical smart contract.
[0069] S42, the status code update request actively requires the user end to update; due to the characteristics of the delegatecall operation code, the method of the present invention changes the logical smart contract but the calling contract address does not change. Therefore, the user end does not need to change the address after calling the updated logical smart contract, but only needs to update the value in the logical smart contract.
[0070] S43. The user end updates and calls the updated logic smart contract normally, and then ends the process.
[0071] In summary, the present invention is based on the technology of deploying smart contracts on the Ethereum blockchain. By designing a new proxy contract architecture, the dynamic upgrade of smart contracts is realized, which solves the common problem in the prior art that smart contracts deployed on the Ethereum system cannot be updated in real time.
[0072] In the solution of the present invention, the need for smart contract upgrade is solved by defining permanent storage agent, owner permanent storage agent and permanent storage module. And in the whole process, the method uses hash value for proofreading to ensure the user's information security, the security of smart contract and the integrity of data. It should be noted that all data structures and data modules already exist when the logical smart contract is first deployed, and updating through permanent storage agent mode cannot bring about changes in data structure.
[0073] In addition, the solution of the present invention also provides a new idea for the related research and application of hot update of smart contracts, and provides a reference for other related issues in the same field. It can be used as a basis for expansion, extension and in-depth research, and has a very broad application prospect.
[0074] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit and essential features of the present invention. Therefore, the embodiments should be considered exemplary and non-restrictive in all respects, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims be included in the present invention.
[0075] Finally, it should be understood that although this specification is described according to implementation methods, not every implementation method contains only one independent technical solution. This narrative method of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment can also be appropriately combined to form other implementation methods that can be understood by those skilled in the art.
Claims
1. A method for dynamically upgrading a smart contract based on an agent contract in a blockchain, which is completed under a blockchain architecture. The architecture includes a user end, a permanent storage agent, a logic smart contract, an owner's permanent storage agent, and a permanent storage module. The user end, the permanent storage agent, and the logic smart contract are connected by two-way signals. The permanent storage agent is also connected by signals to the owner's permanent storage agent and the permanent storage module respectively, and the logic smart contract is also connected by signals to the permanent storage module; It is characterized in that The method comprises the following steps: S1, the permanent storage agent receives the message from the user end and retrieves the data from it; S2, the permanent storage agent returns data to the logic smart contract; S3. The logic smart contract completes the online hot update; S4. The user terminal calls the updated logic smart contract; Among them, S1 specifically includes the following steps: S11, initialize the permanent agent; S12, the owner permanent storage agent sends a data request to the permanent storage agent; S13, the permanent storage agent receives the data from the owner's permanent storage agent and decrypts the data; S14, decrypting the updated content; S15, after the decryption is completed, the data information is checked, and the data in the permanent storage module is called to determine whether the data structures of the two are consistent. If they are consistent, the message is decrypted continuously, otherwise an error prompt is returned and the process ends; S16. The permanent storage agent completes decryption of the data and sends the data to the logical smart contract. S2 specifically includes the following steps: S21, forward the data to the logical smart contract through the delegatecall opcode; S22, during the data transmission process, the permanent storage agent uses the delegatecall operation code to store all data in the permanent storage module; S3 specifically includes the following steps: S31. After receiving the update request, the logic smart contract calls the permanent storage module to compare the data and function status to ensure that the updated data structure is consistent with the structure defined in the initial version of the logic smart contract. If not, an error message is returned and the process ends. S32, the logic smart contract receives an update request from the permanent storage agent, and then the logic smart contract sends a request to the permanent storage module, and the permanent storage module directly transmits the data to the logic smart contract to complete the update process; S33. During the update process of the logical smart contract, a new hash check value will be generated for hash comparison when the user updates; S4 specifically includes the following steps: S41. The user sends a call request to the logical smart contract and performs a hash check at the same time. When the logical smart contract is updated, the permanent storage agent sends a status code update request to all user terminals that call the logical smart contract. S42, status code update request actively requests the user end to update; S43. The user end updates and calls the updated logic smart contract normally, and then ends the process.
2. According to claim 1, a method for dynamically upgrading smart contracts based on proxy contracts in a blockchain is characterized in that: S11 specifically includes the following steps: S111. Deploy a permanent storage proxy contract in the blockchain architecture; S112. Deploy the initial version of the logic smart contract in the blockchain architecture. The deployment of the logic smart contract is completed using the solidity language; S113. Call the permanent storage proxy contract and register the address of the initial version of the logical smart contract into the proxy contract.
Citation Information
Patent Citations
Intelligent contract separation method and device, contract processing method and device, equipment and medium
CN110955448A
Method for facilitating rapid upgrading of Ethereum smart contract based on user-defined structure data
CN112118133A
Cited By
Systems and methods for verified upgrade validation of executable contracts on a distributed ledger platform
US12777102B1