-
Notifications
You must be signed in to change notification settings - Fork 2.7k
seal: Storage rent for code #6596
Description
Currently, no rent is collected for code that is stored on-chain. Only the state of the individual contracts is subject to rent payments. This is because code is deployed independently of a contract and can then be used by any contract without further costs. There is also no way (apart from governance) to remove code stored on the chain.
This opens up the chain to DoS because anyone can clutter the storage with code with only a one time cost that covers the computation costs of uploading the code.
For that reason, we propose that contracts should pay for the code they use. To incentives code sharing the costs are also shared between all users of a code blob. We change the rent formula that is calculated on contract access or claim_surcharge to:
rent = storage_rent + (code_size / num_code_users)
The costs for code storage converge against zero with more users using it. Due to integer arithmetic is reaches zero once num_code_users > code_size.
One issue is that the rent is not collected every block but only when the contract is accessed or claim_surcharge is called. The num_code_users can change in between blocks making the calculation inaccurate. However, we argue despite the inaccuracy we cannot come up with an attack that turns this into a DoS vector.
Steps that are necessary for implementation:
- Count the number of users per code hash and delete the code hash once the counter reaches zero
- The
set_codedispatchable is replaced withinstantiate_with_codebecause every code_hash needs at least one user. Theseal_instantiatecontract callable function stays untouched. Contracts cannot deploy code. - Change the rent formula of contracts to also account for the code size.