🎉 The #CandyDrop Futures Challenge is live — join now to share a 6 BTC prize pool!
📢 Post your futures trading experience on Gate Square with the event hashtag — $25 × 20 rewards are waiting!
🎁 $500 in futures trial vouchers up for grabs — 20 standout posts will win!
📅 Event Period: August 1, 2025, 15:00 – August 15, 2025, 19:00 (UTC+8)
👉 Event Link: https://www.gate.com/candy-drop/detail/BTC-98
Dare to trade. Dare to win.
Detailed Explanation of Rust Smart Contract Upgrades: Best Practices from Ethereum to NEAR
Detailed Explanation of Rust Smart Contracts Upgrade Methods
Smart contracts, as a type of program, inevitably have defects and vulnerabilities. Even after extensive testing and auditing, problems may still arise. Once a vulnerability is exploited by an attacker, it can lead to serious consequences such as the loss of user assets. Therefore, the upgradability of contracts is very important, and this article will introduce the upgrade methods for Rust contracts.
Upgrade Methods for Ethereum Smart Contracts
Smart contracts on Ethereum are immutable and cannot be directly modified after deployment. Upgrades are usually done in the following ways:
Deploy a new contract and modify the contract address in the DApp. The downside is that it requires migrating the state data of the old contract.
Data and logic separation architecture. Store data in state contracts while implementing logic in another contract. When upgrading, only update the logic contract.
Use proxy contracts. Proxy contracts store data and call logic contracts through delegatecall; when upgrading, only the logic contract address needs to be updated.
NEAR Contract Upgrade Method
Taking the StatusMessage project as an example, this article introduces the upgrade method for NEAR smart contracts:
1. The contract data structure has not been modified.
If only the contract logic is modified without involving changes to the data structure, you can directly use the near deploy command to redeploy the new code. The original data will be retained.
2. The contract data structure has been modified.
If the data structure is modified, redeploying directly will cause a mismatch between the old and new data structures, making it impossible to read the data properly.
3. Use the Migrate method to upgrade
NEAR provides the Migrate method to assist with upgrades:
Smart Contracts Upgrade Security Considerations
By reasonably designing the upgrade plan, the upgradability of the contract can be achieved while ensuring security, thus improving the long-term maintainability of the project.