Conflux Sponsorship Mechanism

Introduction to Sponsorship Mechanism

The vast majority of public chains have a mechanism called gas (or “gas fee”) that is used for a variety of purposes, such as countering DoS attacks, avoiding downtime of smart contracts, and incentivizing miners. But the gas mechanism also raises the bar for users to interact with smart contracts – having the mechanism of gas means that having native tokens of the blockchain is a prerequisite for interacting with smart contracts.

Besides mining, users can only get the blockchain tokens off-chain from other users (including DEX). Currently, both mining and off-chain transactions are not easy for the users. In addition, interacting with a contract means that a user has to spend gas every time. There is a cost for each operation, thus users may weigh whether it is worth paying so much gas before trading. Ethereum, where direct operations on the main chain require high gas costs, is a typical example of this phenomenon, although the problem can be mitigated by some layer2 technologies.

The Sponsorship Mechanism in Conflux, in short, allows sponsors to pay the gas fee for smart contract interactors (storage staking fees can also be sponsored in Conflux, but here we won’t talk about it further). The user who is “sponsored” does not have to spend the gas when creating a transaction. With the sponsorship enabled, an account with a zero balance can also interact with the contract. This significantly lowers the bar for users to interact with the contract.

Setting up a Sponsorship

As the name “Sponsorship” suggests, that an account with a zero balance can interact with a contract is not because that the fees are waived, but because someone else has paid for them. Conflux’s built-in contract, SponsorWhitelistControl, is responsible for managing the sponsorship mechanism. The sponsor only needs to pay CFX to SponsorWhitelistControl and specify the contract address that will be sponsored.

If you don’t want to consider any of the details of the sponsorship and just want to set up a sponsorship for a contract that doesn’t already have one, you can follow the steps below to interact with it. Some details will be omitted here to make sure that this setup applies to almost all the contracts. The screenshot below uses Conflux Studio’s graphical interface to interact with the SponsorWhitelistControl contract (see Conflux Development Tutorial | Hands-on guide to developing DApps using the IDE for how to use Conflux Studio). 1000 CFX can be retrieved from the testnet faucet. The following example sets up a 500 CFX sponsorship of gas and storage staking respectively. All of the following actions can be done by accessing the faucet once. The setup of the sponsorship amount in real-world cases depends on the actual scenario.

In the testnet, CFX tokens can be obtained from the testnet faucet (there are portals in Conflux Studio or testing network faucet DApp). In the main network (in Conflux Tethys), in addition to setting up your own sponsorship, you can also apply to the Conflux Foundation on the Contracts Sponsoring page of Conflux Scan and have the Conflux Foundation pay for the contract.

  1. Deploy a contract. You can create and deploy a contract using the ERC20 template provided in Conflux Studio.

  2. The contract’s admin (or the contract itself) sets up a whitelist of sponsors in SponsorWhitelistControl. The admin of the contract is the creator of the contract by default. For a more detailed description of the admin, you can refer to the AdminControl section in the Introduction to Conflux Internal Contract Features.

    1. Interact with the SponsorWhitelistControl contract (address 0x0888000000000000000000000000000000000001). Select the addPrivilegeByAdmin method.
    2. In the parameter contractAddr, set the address of the contract for which you want to set up the sponsorship.
    3. Add element cfxtest:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa6f0vrcsw (the zero address in cfxtestnet) in addresses parameter.
    4. In signer, set the admin of the contract.
    5. Execute it after estimating the gas and storage fees.

  1. Set up Gas sponsorship.
    1. Still, interact with the SponsorWhitelistControl contract. Select the setSponsorForGas method.
    2. Set CFX to Send parameter to 500.
    3. Set contractAddr to the address of the contract you want to set up the sponsorship.
    4. upperBound is set to 10000000000 (10G).
    5. signer can be set into anything, as long as it has enough CFX (more than the CFX to Send parameter).
    6. As before, estimate and execute.

  1. Set up collateral sponsorship
    1. Interact with the SponsorWhitelistControl contract. Select the setSponsorForCollateral method.
    2. Set CFX to Send parameter to 500.
    3. Set contractAddr to the address of the contract you want to set up the sponsorship.
    4. signer can be set into anything, as long as it has enough CFX.
    5. As before, estimate and execute.

Then, the set-up of the contract’s sponsorship is completed.

Explanation of Details in Sponsorship Mechanism

This section will explain some of the parameters mentioned above. for more details, you can refer to Introduction to Conflux internal contract features, which provide a detailed introduction to all aspects of the sponsorship mechanism.

The Whitelist in Contract Payments

A Whitelist mechanism is used in the contract sponsorship. In the SponsorWhitelistControl contract, a whitelist is maintained for each contract address: only users in the whitelist can be sponsored. In default, this whitelist is empty, which indicates that the sponsorship is not enabled.

The list is set by calling addPrivilegeByAdmin from the contract’s admin, or the addPrivilege method in the SponsorWhitelistControl contract from the contract itself. If there is a zero address in the whitelist, then any user who interacts with the contract can be sponsored. Also, the contract is able to call the corresponding interface (remove) to remove users from the whitelist.

Usually, adding a zero address to this list is enough for us.

The upperBound in the Gas Sponsorship

// ------------------------------------------------------------------------
// Someone will sponsor the gas cost for contract `contractAddr` with an
// `upper_bound` for a single transaction.
// ------------------------------------------------------------------------
function setSponsorForGas(address contractAddr, uint upperBound) public payable {}

In setSponsorForGas, in addition to the number of CFX that needs to be sent (as required by the payable keyword) and the contract address, the parameter upperBound needs to be set as well. This parameter represents the upper limit of gas (in Drip, i.e. 10e-18 CFX) that can be spent per sponsored transaction. i.e. the sponsored transaction needs to satisfy the prerequisite of gasUsed * gasPrice <= upperBound. If the transaction requires more gas than upperBound, the gas fee will not be paid by the sponsor but the user who creates the transaction. Conflux’s tps is very high. In general, setting the gasPrice of a transaction to 1 is enough to meet the demand. Conflux Foundation will set this value to 10G when making a payment. It will cover basically all transactions.

It should also be noted that there is a constraint between the parameter upperBound and the CFX sent. The latter needs to be no less than 1000 times the former. For CFX sent in Conflux Studio, note that the units do not match, the numerical comparison between them should be upperBound ≤ CFX_to_send * 10**15. In other words, the CFX you sent for sponsorship needs to be enough for at least 1000 transactions’ gas fee assuming each transaction will use gas to the upper limit.

Storage Collateral Sponsorships

In Conflux, when a user stores 1 KB data in a smart contract, it needs to stake 1 CFX as the deposit. The deposit is not spent and will be refunded when certain conditions are met. The miner will also be compensated for the data stored. A detailed description of storage collateral can be found in Conflux Storage Deposit Mechanism.

While the storage space is in use, the deposit accrues an annual interest of 4.08%, which is distributed directly to the miners to compensate for the cost of storage. The storage deposit is locked in at 1 CFX/KB, for example, if there are currently 100 GB data to be stored, the total storage deposit would be approximately 100 million CFX and the average interest generated per block would be approximately 0.06 CFX.

Checking the Sponsorship Balance

After setting up a sponsorship, the CFX will be transferred from the sponsor to the SponsorWhitelistControl contract. When a sponsoring occurs, the corresponding amount in the SponsorWhitelistControl will be spent (or staked if it is used in storage). Details can be queried via the SponsorWhitelistControl’s getSponsoredBalanceForCollateral and getSponsoredBalanceForGas methods.

/**
* @dev get collateral sponsor address
* @param contractAddr The address of the sponsored contract
*/
function getSponsorForCollateral(address contractAddr) public view returns (address) {}

/**
* @dev get current Sponsored Balance for collateral
* @param contractAddr The address of the sponsored contract
*/
function getSponsoredBalanceForCollateral(address contractAddr) public view returns (uint) {}

Discussion of the Design of Sponsorship

DDoS Attacks

Naturally, the purpose of the sponsorship mechanism conflicts with the gas mechanism. The existence of gas raises the threshold for conducting transactions, and it also applies to the attackers. When it disappears, the door for attackers is opened. For example, attackers can construct and initiate massive network congestion using sponsored contracts.

This may also be the reason for having the whitelist mechanism. It is a common confusion when users are learning about the sponsorship mechanism: since the sponsorship is created to lower the requirement of use, then why should there be a whitelist mechanism to restrict it? From the perspective of preventing DDoS attacks, perhaps the reason is that it acts as potential protection to prevent the misuse of sponsorship by only allowing eligible users to enable it through the whitelist.

Malicious Consumption of Sponsorship

On the other hand, it is possible for a sponsorship to be maliciously used. Intuitively, an attacker can quickly spend sponsoredGas by simply constructing a small number of transactions with a sky-high gasPrice. Miners can profit directly from such an attack. When the sponsorship amount is depleted, the contract whose sponsorship was depleted needs to reset the sponsorship. This may affect the normal usage of the user during this period. Therefore, this might be the purpose of the parameter upperBound: by setting the right upperBound, we can slow down the rate of sponsoredGas consumption. 10G upperBound set by the Conflux Foundation may seem high but is only equivalent to 10**-8 CFX, which is enough to support a large number of transactions.

But in contrast, storage staking sponsorship can be more easily occupied. Compared to gas consumption, storage staking is much more expensive. For every 1 KB storage occupied, 1 CFX is locked. If there is a real attacker who intends to make an attack, the amount of storage sponsorship can be easily depleted. Whether miners can profit in this action may need further discussion (miners get the interest in storage staking, but they spent the storage space for it; each miner pays the same amount of storage space but does not receive equal rewards). Since the attackers pay a very small cost, such attacks can still happen.

Example of malicious storage depletion: In the ERC20 contracts, a malicious user can easily deplete storage by randomly sending 10e-18 ERC20 tokens to a random address

Potential Drawbacks and Benefits

In the context of the above discussion and the overall environment, Conflux’s restrictions on sponsorship seem to aim more at the honest users rather than the malicious users. But to take a step back, even if an attack occurs, the damage is not as big as one predicts – this means that the source of the problem is not the sponsorship itself. In the case of DDoS attacks, if an attacker wishes to carry out a DDoS attack, the cost of not using a sponsorship is still very low at the current Conflux network. It makes little difference whether they use the sponsorship or not. In terms of malicious consumption of sponsorship amount, the gas and storage staking in the contract is just a return to normal, i.e. the model without sponsorship. It is no worse than the situation which does not have the sponsorship at the beginning.

However, the threshold for interacting with the contract is significantly lowered with the sponsorship, which is undoubtedly a great help for fledgling projects (and in some senses, Conflux itself). The potential drawbacks of the sponsorship may not be such a big deal at this stage compared to the benefits it brings.

Ways of Application

Currently, there are two paths to go to the application page to submit a sponsor application to the Foundation.

Path one

  1. Go to the ConfluxScan official website (confluxscan.io)
  2. Click on “Token” - select the token contract you want to check and enter the contract interface
  3. Click on “Apply for Sponsorship” under “More”
  4. Click “Apply”



Path two

  1. Go to the ConfluxScan official website (confluxscan.io)
  2. Click on “Blockchain”, select “Sponsorship Contracts” under “Contracts” column and enter the sponsorship contract interface
  3. Fill in the search field with the address of the contract you want to apply for sponsorship, click “Search”
  4. Click on “Apply”


Rules of Sponsorship

Undifferentiated storage collateral sponsorship: 1 * 10 cfx.
Undifferentiated gas sponsorship: 5 * 1 Gdrip, upper bound 500,000 drip (roughly Gas with price 1 and Gas limit of no more than 500,000)

Applications for sponsorship require individual negotiation for each project specifically (currently self-service is not open), project groups are requested to complete the following two steps and wait for review.
Complete the contract verification on Confluxscan, fix the warning messages in the project, and set the built-in contract Admin (note: not the admin in contract management)to zero address.
After completing item 1, contract [email protected] with the following details:
Project Name.
Purpose (gas sponsorship/storage sponsorship).
Contract Address.
Contact information.

Usually, the result will be returned within 7 business days. Please note that the submission does not mean the sponsorship application is approved. Therefore, please pay attention to the reply to the email and the contact information filled in the application.