tronprotocol / tips

TRON Improvement Proposals
219 stars 187 forks source link

TIP-653: Adjust energy cost of SUICIDE and VOTEWITNESS opcodes in TVM #653

Closed yanghang8612 closed 2 months ago

yanghang8612 commented 4 months ago
tip: 653
title: Adjust energy cost of SUICIDE and VOTEWITNESS opcodes in TVM
author: yanghang8612@163.com
status: Final
type: Standards Track
category: VM
created: 2024-04-30

Simple Summary

This TIP aims to adjust the energy cost of TVM opcodes based on actual resource consumption.

Abstract

Adjust the energy cost for several opcodes (such as SUICIDE and VOTEWITNESS) in TVM to better reflect the actual resource consumption of opcode execution and to ensure that the costs are reasonable.

Motivation

The SUICIDE opcode is used to destroy smart contracts and release related resources. The VOTEWITNESS opcode is a TRON-specific opcode that allows a contract account to perform voting operations on certain SRs just like an EOA account.

However, the current energy cost mechanism may have some deficiencies, failing to effectively reflect the resources and time costs required for the execution of SUICIDE and VOTEWITNESS opcodes, potentially leading to unreasonable costs.

  1. Adjustment of Energy Cost: The current energy cost for the SUICIDE and VOTEWITNESS opcodea may be comparatively low compared to other opcodes, failing to adequately consider the resources and time costs required for execution. It is proposed to adjust the energy cost for the SUICIDE and VOTEWITNESS opcodes appropriately to better reflect the actual costs.

  2. Consideration of Execution Time: The execution of the SUICIDE and VOTEWITNESS opcodes may involve complex operations and require a certain amount of time to complete. Therefore, the impact of opcode execution time on energy cost should be considered to ensure that the cost is proportional to the execution time.

  3. Reasonability: When adjusting energy costs, it should be ensured that the costs reflect the consumption of resources by the opcodes to avoid the possibility of potential DDoS attacks.

Specification

After the getAllowEnergyAdjustment(81th) proposal takes effect, the SUICIDE opcode will charge an additional 25,000 energy cost, if the recipient does not exist. Also, the VOTEWITNESS opcode will be charged a memory expansion energy cost of at least 32 bytes (array length) for its dynamic array parameters.

Rationale

The rationale behind proposing an adjustment to the energy cost for the SUICIDE and VOTEWITNESS opcodes in TVM stems from several key considerations:

Backwards Compatibility

These energy cost increases may potentially break contracts that depend on fixed energy costs.

CooperDepp commented 4 months ago

The SUICIDE opcode is executed when destroying a contract, hope the energy consumption of other opcodes remains the same, so that the cost of ordinary transactions would not increase.

WalterBrooks commented 4 months ago

Energy is designed to reflect the computing resource, this TIP indicates the resource should also take execution time into consideration, because time reflect the occupied resource. It seems reasonable, if it could control the influence to most existing contracts.

KrisdiaPaul commented 4 months ago

Better to estimate the amount of contracts that depend on fixed energy costs and find a way to help them adapt to this change, if necessary.

MannGates commented 3 months ago

It is not very clear why the current energy cost of suicide opcode is not reasonable compared to others. And specification part should be supplemented and discussed.

andreiRogov96 commented 2 months ago

Hello,

Regarding to VOTEWITNESScode

To be clear, this improvement doesn't mean that votewitnessaccount transactions will start to consume Energy. It's just about calls to vote from smart contracts?

yanghang8612 commented 2 months ago

@andreiRogov96 Yeah, that's for sure. The VOTEWITNESS referred to in this TIP are opcode in TVM, not votewitnessaccount interface as you say.