tip: 157
title: Freeze instructions in TVM
author: taihao.fu@gmail.com
status: Draft
type: Standards Track
category : Core
created: 2020-06-03
To provide freeze related operations in TVM.
Freeze & Unfreeze operation in system contract are introduced, smart contract can freeze and get resource from the system.
Common user can freeze TRX to get resource, such as TRON power, bandwidth, energy. However, none privatekey accounts, like smart contracts, can't get resources from the staking mechanism. This TIP provide instructions to get resource, so that smart contracts can provide tron power for voting and aslo provide resource delegation to others.
The following instructions are introduced:
The FREEZE takes 4 operands pop up from stack:
delegatedAddress: the target address to delegate frozen TRX generated resource to.
freezeAmount: TRX amount to freeze in SUN.
day: time duration willing to freeze TRX in day.
resourceType: 0 as bandwidth, 1 as energy.
Execute freeze function and push 0 to stack if fail, push 1 otherwize.
The UNFREEZE takes 2 operands from stack.
delegatedAddress: the target address to delegate frozen TRX generated resource to.
resourceType: 0 as bandwidth, 1 as energy.
Execute UNFREEZE function and push 0 to stack if fail, push 1 otherwise.
The BANDWIDTH takes 1 operand from stack.
accountAddress: target account address.
Push current frozen generated bandwidth value of the target address to stack.
The ENERGY takes 1 operand from stack.
accountAddress: target account address.
Push current current energy left in the target address to stack.
As introduced in TIP156, a system log structure for freeze & unfreeze can be defined as below:
message SystemLog {
enum operationType {
VOTE = 1;
WITHDRAWREWARD = 2;
FREEZE = 3;
UNFREEZE = 4;
}
bytes address = 1; // user address or contract address
repeated bytes params = 2;
// FREEZE contains 4 parameters: FREEZE(delegatedAddress, freezeAmount, frozenDay, resourceType);
// WITHDRAWREWARD contains 2 parameters: UNFREEZE(delegatedAddress, resourceType);
operationType type = 3;
}
Freeze and Unfreeze infomation will be record in the SystemLog field in transactionInfo.
FREEZE tier.ExtTier
UNFREEZE tier.ExtTier
BANDWIDTH tier.ExtTier
ENERGY tier.ExtTier
When selfdestruct is executed, 2 cases need to be considered:
-
Any type of account A delegates its resource to contract B and B selfdestruct itself to address C. Now, C should preserve the delegated resource from A.
-
Contract A delegates its resource to any type of account B and A selfdestruct itself to address C. Now, C should preserve the privilege that delegate resource to B. C can't unfreeze its delegation with B until frozen time exceed to the expiration date,.