|
| 1 | +``` |
| 2 | +tip: 156 |
| 3 | +title: Freeze instructions in TVM |
| 4 | +author: taihao.fu@gmail.com |
| 5 | +status: Draft |
| 6 | +type: Standards Track |
| 7 | +category : Core |
| 8 | +created: 2020-06-03 |
| 9 | +
|
| 10 | +``` |
| 11 | + |
| 12 | +## Simple Summary |
| 13 | + |
| 14 | +To provide freeze related operations in TVM. |
| 15 | + |
| 16 | +## Abstract |
| 17 | + |
| 18 | +Freeze & Unfreeze operation in system contract are introduced, smart contract can freeze and get resource from the system. |
| 19 | + |
| 20 | +## Motivation |
| 21 | + |
| 22 | +Common user can freeze TRX to get resource, such as TRON power, bandwidth, energy. However, none privatekey accounts, like smart contracts, can't get al 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. |
| 23 | + |
| 24 | +## Specification |
| 25 | + |
| 26 | +The following instructions are introduced: |
| 27 | + |
| 28 | +### `0xd5`: `FREEZE` |
| 29 | + |
| 30 | +The `FREEZE` takes 4 operands pop up from stack: |
| 31 | +`delegatedAddress`: the target address to delegate frozen TRX generated resource to. |
| 32 | +`freezeAmount`: TRX amount to freeze in SUN. |
| 33 | +`day`: time duration willing to freeze TRX in day. |
| 34 | +`resourceType`: 0 as bandwidth, 1 as energy. |
| 35 | + |
| 36 | +Execute freeze function and push 0 to stack if fail, push 1 otherwize. |
| 37 | + |
| 38 | +### `0xd6`: `UNFREEZE` |
| 39 | + |
| 40 | +The `UNFREEZE` takes 2 operands from stack. |
| 41 | +`delegatedAddress`: the target address to delegate frozen TRX generated resource to. |
| 42 | +`resourceType`: 0 as bandwidth, 1 as energy. |
| 43 | + |
| 44 | +Execute UNFREEZE function and push 0 to stack if fail, push 1 otherwise. |
| 45 | + |
| 46 | +### `0xd7`: `BANDWIDTHVAlUE` |
| 47 | + |
| 48 | +The `BANDWIDTHVAlUE` takes 1 operand from stack. |
| 49 | +`accountAddress`: target account address. |
| 50 | + |
| 51 | +Push current frozen generated bandwidth value of the target address to stack. |
| 52 | + |
| 53 | +### `0xd8`: `ENERGYVALUE` |
| 54 | + |
| 55 | +The `ENERGYVALUE` takes 1 operand from stack. |
| 56 | +`accountAddress`: target account address. |
| 57 | + |
| 58 | +Push current frozen generated energy value of the target address to stack. |
| 59 | + |
| 60 | +## Rationale |
| 61 | + |
| 62 | +### Tier |
| 63 | + |
| 64 | +`FREEZE` tier.ExtTier |
| 65 | +`UNFREEZE` tier.ExtTier |
| 66 | +`BANDWIDTHVAlUE` tier.ExtTier |
| 67 | +`ENERGYVALUE` tier.ExtTier |
| 68 | + |
| 69 | +### Selfdestruct |
| 70 | + |
| 71 | +When selfdestruct is executed, 2 cases need to be considered: |
| 72 | + |
| 73 | +1. Any type of account A delegates its resource to contract B and B selfdestruct itself to address C. |
| 74 | +Now, C should preserve the delegated resource from A. |
| 75 | + |
| 76 | +2. Contract A delegates its resource to any type of account B and A selfdestruct itself to address C. |
| 77 | +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,. |
0 commit comments