Introduction to payment
Most of the public chains have gas (or called "gas fee"), which has rich functions, such as resisting denial of service attacks, avoiding the shutdown problem of smart contracts, Incentivize miners, etc. But gas mechanism also will bring a problem that raised the bar for the user to interact with the smart contract - gas means having a block chain tokens are native to interact with the smart contract premise .
As far as the acquisition method of native tokens is concerned, in addition to mining, users can only obtain them from other users (including exchanges) through off-chain methods. In the current environment, whether it is mining or off-chain transactions, it means a very high threshold. In addition, every time the user interacts with the contract, it means spending gas, and there is a cost for each operation. The user may weigh whether it is worth paying so much gas before the transaction. This is very obvious on Ethereum, directly in the main Chain operations require a high amount of gas (but the problem of high gas fees can be alleviated by some layer2 technologies).
The payment mechanism in Conflux, in short, is to allow other users to pay the gas fee for the interactor of a smart contract (in Conflux, the storage mortgage fee 161ea21bddb4a0 can also be paid on behalf of Users who are "paid on behalf of" do not have to bear the gas cost when initiating transactions. After the payment is enabled, an account with a balance of 0 can also interact with the contract, which greatly reduces the threshold for users to interact with the contract.
Set up payment
As the name "payment" expresses, an account with a balance of 0 can interact with a contract not because the corresponding fee is waived, but because someone else pays the corresponding fee. Conflux's built-in contract SponsorWhitelistControl
is responsible for managing the payment mechanism. The person who provides the payment funds can SponsorWhitelistControl
and specify the contract address for the payment.
If you don't want to consider any details of the payment, but just want to set the payment for a contract that has not yet set the payment, you can follow the steps below to interact. We will omit some details here, and try to ensure that this setting is common to almost all contracts. Screenshot below using Conflux Studio
graphical interface with SponsorWhitelistControl
contracts interaction ( Conflux Studio
use can refer https://forum.conflux.fun/t/topic/1680 ). You can get 1000 CFX at a time in the testnet faucet. The following example will set up 400 CFX payment for gas and storage mortgage respectively. All of the following can be done with a single tap. How to set the payment amount in the actual environment depends on the specific scenario.
<!-- The corresponding javascript script js-conflux-sdk
will also be provided at the end of the article. -->
In the testnet environment, CFX tokens can be obtained through the testnet faucet (there are entrances in Conflux Studio, and you can also use the faucet DApp to obtain it). (in Conflux Tethys), in addition to setting up payment by yourself, you can also apply to the Conflux Foundation on the 161ea21bddb55d sponsorship contract page page of Conflux Scan, and the Conflux Foundation will pay for the contract.
- Deploy a contract. You can use
Conflux Studio
create ERC20 templates provided and deployment contracts, concrete steps are omitted here. The admin of the contract (or the contract itself) sets up a
SponsorWhitelistControl
Admin contracts default to contract creator , a more detailed explanation about the admin can refer Conflux built-contract Features inAdminControl
section.- Interact with the
SponsorWhitelistControl
contract (address0x0888000000000000000000000000000000000001
). Select theaddPrivilegeByAdmin
method. - In the parameters,
contractAddr
set to the contract address where you want to set the payment. - Add element
cfxtest:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa6f0vrcsw
(0 address in cfxtestnet) to theaddresses
signer
Select the admin of the contract.Execute after Estimate, no errors can be made.
- Interact with the
Set up gas payment.
- Still interacting with the
SponsorWhitelistControl
contract. Select thesetSponsorForGas
method. - Set
CFX to Send
. Fill in400
. contractAddr
set to the contract address where you want to set up payment.upperBound
set to10000000000
(10G)signer
can be set to any setting, as long as it has enough CFX (greater than the set 500)- As before estimate and execute
- Still interacting with the
Set up mortgage payment.
- Interact with the
SponsorWhitelistControl
contract. Select thesetSponsorForCollateral
method. - Set
CFX to Send
. Fill in400
. contractAddr
set to the contract address where you want to set up payment.signer
can be set to any setting, as long as it has enough CFX (greater than set 500)- As before estimate and execute
- Interact with the
At this point, the contract payment setup is complete.
Some details in the payment
This part will explain some of the parameters mentioned above. For detailed instructions, please refer to Conflux built-in contract function introduction . This article has done a very detailed introduction to all aspects of payment.
Contract whitelist list for payment on behalf of
The contract payment adopts a whitelist mechanism. In the SponsorWhitelistControl
contract, a user whitelist list is maintained for each contract address: only users in the whitelist can be paid. By default, the whitelist is empty, which means that proxy payment is not enabled.
The list is set by the contract's admin calling addPrivilegeByAdmin
, or the contract itself calls the addPrivilege method of the SponsorWhitelistControl
If there are 0 addresses in the whitelist, then any user who interacts with the contract can be paid on behalf of. At the same time, the contract can also call the corresponding interface (remove) to remove users in the whitelist.
Normally, adding 0 addresses to this list would satisfy our requirements.
upperBound in gas payment settings
// ------------------------------------------------------------------------
// 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 the Gas payment setting setSponsorForGas
, in addition to the number of CFX to be sent (required by the paybale keyword) and the contract address, the parameter upperBound also needs to be set. This parameter means the upper limit of Gas (unit: Drip, 10e-18 CFX) that can be consumed by each paid transaction, that is, this parameter means that the paid transaction needs to meet upperBound ≤ gasUsed * gasPrice
. If the gas required for the transaction exceeds the upperBound, the gas fee will not be paid on behalf of the user, but will be paid by the user who initiated the transaction. The tps of Conflux is very high. Generally speaking, the gasPrice of the transaction is set to 1 to meet the demand. The Conflux Foundation will set this value to 10G when making payment, which can cover basically all transactions.
In addition, it should be noted that there is a constraint relationship between the parameter upperBound and the sent CFX, and the latter needs to be no less than 1000 times the former. In the CFX sent in Conflux Studio, notice that the two units are inconsistent, just comparing the numbers means upperBound>= CFX_to_send * 10**15
.
Deposit and mortgage payment
In Conflux, when a user stores 1 KB of data in a smart contract, he needs to mortgage 1 CFX as a deposit. The deposit is not consumed and will be refunded when certain conditions are met. Miners are also compensated for storing data. For a detailed introduction to storage collateral, please refer to Conflux Research Institute | Storage Deposit Mechanism :
During the use of the storage space, the deposit will generate an annualized 4.08% interest, which will be directly distributed to the miners to compensate the miners for their storage costs. During the use of the storage space, the deposit will generate an annualized 4.08% interest. These interests will be distributed directly to miners to compensate miners for their storage costs. The price of the storage deposit is locked at 1 CFX/KB. For example, if there is currently a total of 100 GB of data to be stored, the total amount of storage deposit is about 100 million CFX, and the average interest generated per block is about 0.06 CFX
Inquiry about payment balance
After setting up payment, CFX will be transferred from the SponsorWhitelistControl
to the 061ea21bddba0f contract. When the payment occurs, the SponsorWhitelistControl
will be consumed (the corresponding storage is mortgaged), which can be SponsorWhitelistControl
through getSponsoredBalanceForCollateral
and getSponsoredBalanceForGas
.
/**
* @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) {}
A discussion on the design of payment on behalf of others
DDoS attack
Naturally, the purpose of the payment mechanism is in contradiction with the gas mechanism itself - the existence of gas raises the threshold for transactions, but it is also the threshold for malicious attackers. When this threshold disappears, it also opens the door of convenience for attackers. For example, an attacker can use a contract with proxy payment to construct and initiate a large number of transactions to congest the network.
This may also be the reason for the existence of the whitelist mechanism. When you first learn about the agency payment mechanism, it is easy to wonder: since the main purpose of agency payment is to lower the threshold for use, why do you need a whitelist mechanism to restrict agency payment? From this point of view, it may be used as a potential insurance, by setting a whitelist to enable proxy payment only for eligible users to prevent the abuse of proxy payment.
Malicious consumption and payment
On the other hand, sponsored payments may also be consumed maliciously. Intuitively, malicious attackers can quickly consume sponsoredGas by simply constructing a small number of transactions by setting a very high gasPrice for ordinary transactions. Miners are able to profit directly from this attack. When the doctor is exhausted, the contract that is consumed on behalf of the payment needs to be reset, which may affect the normal use of the user. This may also be one of the meanings of the upperBound parameter - by setting a suitable upperBound, the speed at which sponsoredGas is consumed can be slowed down. The 10G upperBound set by the Conflux Foundation looks high, but it is only equivalent to 10**-8 CFX
, which is enough to support a very large number of transactions.
But in contrast, the payment for storage mortgage can be occupied more easily, and the cost of mortgage occupancy is much higher than that of gas consumption. For every 1 KB of storage space occupied, 1 CFX is locked. If there is a deliberate attack by an attacker, the payment for storage collateral can easily be exhausted. Whether miners can profit in this way may require careful discussion (miners can earn interest on storage mortgages, but also pay for storage space; each miner pays the same storage space, but the profit is not uniform). However, such an attack is still possible due to the very small cost to the attacker.
Examples of malicious consumption of storage: such as ERC20 contracts, users can easily consume storage by randomly sending 10e-18 ERC20 tokens to random addresses
Potential pitfalls and benefits
As far as the above discussion and the overall environment are concerned, Conflux's restrictions on payment on behalf of others are still an attitude of "preventing gentlemen but not villains". But taking a step back, even if the corresponding attack occurs, the harm is not as great as imagined - or the source of the problem is not the payment itself. As far as DDoS attacks are concerned, if an attacker wishes to carry out DDoS attacks, according to the current rate standard of the Conflux network, the cost of not using proxy payment is also very low, and there is no big difference between using proxy payment or not. In terms of malicious consumption and payment, the gas and mortgage storage in the contract are only "return to normal", that is, the mode without payment is no worse than the situation without payment.
But correspondingly, with the payment, the threshold for interacting with the contract is greatly reduced, which is undoubtedly of great help to the project just started (in a sense, including Conflux itself). Compared with the benefits brought by the agency payment, the potential defects in the agency payment may not be critical at this stage.
How to apply
At present, there are two ways to enter the application page and submit a payment application to the foundation:
Path 1:
- Enter ConfluxScan official website (confluxscan.io)
- Click "Token" - select the token contract you want to query, enter the contract interface
- Click "Apply for Sponsorship" in
- Click "Apply"
Path two:
- Enter ConfluxScan official website (confluxscan.io)
", select "Sponsorship Contract" in the contract column, and enter the sponsorship contract interface 161ea21bddbc46- Fill in the address of the contract you want to apply for sponsorship in the search bar, click "Search"
- Click "Apply"
Payment Rules
Undifferentiated storage payment: 1 * 10 cfx;
Undifferentiated gas payment: 5 * 1 Gdrip, upper bound 500,000 drip (probably the Gas price is 1, and the Gas limit does not exceed 500,000)
The project application for payment needs to be discussed on a case-by-case basis (self-service application is not open for the time being). Please complete the following two steps and wait for manual review:
1. The contract needs to be verified: Confluxscan needs to solve the warning message in the project information for contract verification.
The built-in contract Admin is set to 0 address (Note: it is not the Admin of contract management)
2. After 1 is completed, contact email scan@confluxnetwork.org with the following information:
project name:
Purpose: (gas payment/storage payment)
Contract address:
Contact information:
Usually, the application will respond to the result within 7 working days. Please note that submission does not mean that the payment application is approved. Please pay attention to the reply in the email and the contact information in 2.
Reference article
- Conflux built-in contract function introduction: Conflux official introduction to Conflux's built-in contract, the information is very detailed. 【 point me to check the details 】
- Introduction to Conflux Studio: An introduction to the operation method of Conflux Studio. It is worth mentioning that there is also a web version that can use https://conflux.ide.black/ (it may be slower to load) [ click for details ]
- How to efficiently start a new project? Learn about the Conflux payment mechanism: Conflux's official introduction to the payment mechanism. 【 click me to view the details 】
- Conflux Research Institute | Storage Deposit Mechanism: An Introduction to Storage Mortgage 【 I check the details 】
Original link: Payment and discussion in Conflux: https://github.com/conflux-fans/crypto-knowledge/blob/main/blogs/conflux-sponsor.md
database:
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。