Introduction of the new TVM instructions “freeze/unfreeze”

The limitation of the existing resource model

The new TVM instructions

0xd5: FREEZE- Description:Freeze TRX in the contract account to obtain resources
- Parameters description:
- "receiverAddress": The address for receiving resource
- "freezeAmount": amount to freeze in SUN.
- "resourceType": 0 means bandwidth, 1 means energy
- Return value: push 1 to stack if the operation succeeds, otherwise push 0 to stack.
0xd6: UNFREEZE- Description: Unfreeze the TRX that has ended the freeze period
- Parameters description:
- "receiverAddress": The address which received resource
- "resourceType": 0 means bandwidth, 1 means energy
- Return value:push 1 to stack if the operation succeeds, otherwise push 0 to stack.
0xd7: FREEZEEXPIRETIME- Description:Query the time when the 'unfreeze' can be executed.
- Parameters description:
- "targetAddress": The address which received resource
- "resourceType": 0 means bandwidth, 1 means energy
- Return value: Return the time in seconds when the 'unfreeze' can be executed.
  • freeze and unfreeze instructions are new TVM instructions and will not affect existing contracts.
  • The TRON Nile test network has enabled TIP-157 on April 27, 2021, and supports the freeze/unfreeze instructions. For details, please refer to https://nile.tronscan.org/#/proposal/8191, all interested developers are welcome to the Nile to Experience the brand-new TVM instructions.

Contract sample code:

contract TestFreeze {function freeze(address payable receiver, uint amount, uint res) external returns(uint) {
receiver.freeze(amount, res);
return this.getExpireTime(receiver, res) - now;
}

function unfreeze(address payable receiver, uint res) external returns(uint) {
receiver.unfreeze(res);
return 1;
}

function getExpireTime(address payable target, uint res) external view returns(uint) {
return target.freezeExpireTime(res);
}
}

The difference between TVM freeze instructions and system contract freeze instructions

  • The TVM freeze instruction can obtain bandwidth and energy. For TRON POWER, it can be obtained and used after the TVM supports the voting instruction.
  • For the freeze instruction, the number of freezing TRX must be greater than or equal to 1 TRX = 10e6 SUN.
  • For the TVM freeze/unfreeze instructions, if receiverAddress != contractAddress , the receiverAddress must not be a contract address type.
  • When the freeze instruction is executed, if the target address is a non-existent account, it will automatically activate the target address and deduct an additional 25,000 energy as the account activation cost.
  • When there are freezing TRXs in the contract account and the resource receiver is the other account, executing selfdestruct will cause a REVERTexception.
  • When there are freezing TRXs in the contract account and the resource receiver is the contract account itself, executing the selfdestruct will automatically unfreeze the freezing TRX and transferred it to the target account specified in the selfdestruct instruction.

The positive impact of TIP-157

Summary

References

For more information

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

FHIR for Developers: Part 1

Terraform state locking using DynamoDB

How to apply Shared Element Transitions in Android

Excel Witbal Function (Enhancing Fuzzy Match)

Programmers Get Burnout Syndrome

How To Fix Micromax Bolt A82 Not Charging [Troubleshooting Guide]

Consume DynomoDB streams from AWS Lambda.

Reflection API

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
TRON Core Devs

TRON Core Devs

More from Medium

Given X, what do we know about Y?

Incantation.

Blacksmith: How to craft equipment in Metarrior