AleoNet / snarkVM

A Virtual Machine for Zero-Knowledge Executions
https://snarkvm.org
Apache License 2.0
1.08k stars 1.5k forks source link

Fairly price storage costs for transactions #2456

Closed iamalwaysuncomfortable closed 5 months ago

iamalwaysuncomfortable commented 6 months ago

Motivation

Transactions are currently limited to being 128kb or less in size.

Most execution transactions are small (for instance, transfer_public is 2880 bytes in size). However, transaction size can be greatly increased if the function being executed has very large inputs or very large outputs in the form of nested structs or arrays.

SnarkOS nodes must allocate enough memory to verify all transactions and carry out speculate operations on them. If many executions near the 128kb limit are sent to a network in a short timeframe, it can lead to a large amount of memory growth, long block times, long sync times and fast ledger growth.

Below is an example of memory growth on a validator observed from sending 3 TPS of 124kb transactions over 2 hours.

Screen Shot 2024-05-10 at 3 38 13 PM

Currently a 128kb transaction would only cost .128 credits to execute, which makes it relatively cheap to flood the network with them. Given the deleterious effects of large transactions to network health, it makes sense to impose higher storage costs on larger transactions to ensure users of them are paying the appropriate costs for the effort it takes to process them.

This PR proposes that the storage cost of execution transactions above 5kb in size be penalized with a quadratic function.

\text{fee\_microcredits} =
\begin{cases}
\text{num\_bytes} & \text{if } 0 < \text{num\_bytes} \leq 5 \\
\frac{{num\_bytes}^2}{5000} & \text{otherwise} & \text{if } \text{num\_bytes} > 5 \\
\end{cases}

An exact function to price storage remains open for debate, and alternatives can certainly be proposed, but it is strongly encouraged storage costs be increased to properly pay for the extra effort the network must perform verify and store them.

NOTE: This would be a breaking change for Testnet, so this should be a pre-mainnet change and integrated into mainnet-staging.

raychu86 commented 6 months ago

When a decision is made, can you post the before and after fees amounts for the credits.aleo functions?

iamalwaysuncomfortable commented 6 months ago

When a decision is made, can you post the before and after fees amounts for the credits.aleo functions?

The decision on the function has been made and posted above on the PR description:

The costs of major credits.aleo functions are as follows:

bond_public: 306229 (storage: 1519, finalize: 304710)
join: 2087 (storage: 2087, finalize: 0)
split: 2131 (storage: 2131, finalize: 0)
transfer_private: 2242 (storage: 2242, finalize: 0)
transfer_private_to_public: 26961 (storage: 2141, finalize: 24820)
transfer_public: 51060 (storage: 1420, finalize: 49640)
transfer_public_to_private: 26439 (storage: 1619, finalize: 24820)
unbond_public: 325149 (storage: 1309, finalize: 323840)

There haven't been any changes in storage costs in credits.aleo functions under this pricing model.