Skip to content

Discussion: Enable Energy Sponsorship for Contracts Deployed by Contracts #782

@kongchi-ken

Description

@kongchi-ken

Simple Summary

This is a discussion on enabling the energy sponsorship for contracts deployed by contracts.

Motivation

TRON network has a contract energy sharing mechanism that allows the contract deployer to share some of the energy consumption of contract execution, thus provides energy sponsorship for the contract users. But this mechanism currently cannot handle the case where a contract is created by a contract.

With the continuous enrichment of smart contract application scenarios on TRON network, there are more and more cases of deploying contracts (CREATE, CREATE2) through factory contracts. Some contract developers and projects have to deploy additional contracts as transaction entry points to provide energy sponsorship for these contracts, leading to additional costs and certain inconveniences.

Extending the contract energy sharing mechanism to contracts deployed by contracts will improve the flexibility of contracts, and make it easier for developers and projects to build more complex contract systems.

Specification

I can think of two approaches to enable the energy sponsorship for contracts deployed by contracts.

  1. Enable TVM to edit consume_user_resource_percent and origin_energy_limit

Because the consume_user_resource_percent and origin_energy_limit fields of a contract created by a contract are 100 and 0, indicating that 100% of the contract's execution energy consumption is borne by the user and that the contract deployer provides an upper limit of 0 energy for a single transaction.
Currently, TVM does not provide relevant commands for contracts to adjust this field.

By introducing opcodes to modify the consume_user_resource_percent and origin_energy_limit fields of a contract in TVM, factory contracts can modify these configs for child contracts, and provide energy sponsorship for child contracts.

This approach extends the TRON contract energy sharing mechanism to support the origin (deployer) of a contract is other contract, without changing the main energy share and consume logic.

  1. Allow TVM execution to use the energy of the contract itself.

Another approach is to change the energy sharing mechanism from using the energy of the origin (deployer) to the contract itself.

It also may require the TVM to support the contract to change some of the new share settings.

Both approaches require allowing delegating resource to contracts.

Discussion

Any opinion on energy sharing mechanism or improvement of the mechanism is welcome, thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions