Scaling FIL+ Allocation Mechanism #708
Replies: 5 comments 5 replies
-
Thanks @nikkolasg this sounds great. I think the changes to the verified registry actor to support this would be fairly straightforward. There are some policy decisions to work out about how to treat partial claims, loss of one part of a claim etc, but I don't think they need be too complicated. A sketch of these is in this earlier design for FIP-0045. This will all work great from the verified registry side. Actually realising it is blocked by the built-in storage market actor's privileged position as mediator of all sector content. At present, everything to do with sector content must go through the built-in market actor, which is not prepared to handle deals that are larger than a sector. My opinion is that the built-in storage market actor should be removed from this privileged position, and the associated API changes would then open this scalable FIL+ allocation mechanism directly to clients and SPs, or to user-programmed contracts as mediators. See #298, "Free CommD", and this glimpse of miner protocol change dependencies. |
Beta Was this translation helpful? Give feedback.
-
Update: added estimated graph cost comparison |
Beta Was this translation helpful? Give feedback.
-
@nikkolasg - thanks for putting this together. there's definitely concern right now on the costs of announcing/publishing verified deals to the network, and with FIP 0045 already implemented, this should reduce some of the cost. are you able to join us at the next Fil+ Notary Governance call to present this to the Fil+ community on Jun 6 1500 UTC? filecoin-project/notary-governance#885 for details, cc @Kevin-FF-USA as FYI |
Beta Was this translation helpful? Give feedback.
-
Would "anyone" be able to associate C with the content of the data in a way that CID can? Is it relatively straightforward to map C to CID of the content? |
Beta Was this translation helpful? Give feedback.
-
Updated discussion with raw gas cost improvements for the claiming allocation process. |
Beta Was this translation helpful? Give feedback.
-
TLDR: This new mechanism could reduce between 34% and 50% of the gas cost associated to the claiming allocation process.
Problem
The FIL+ allocation strategy is slow, costly and does not scale onchain.
Let’s think as the datacap as a non-transferable token for simplicity. Currently, on a high level the FIL+ allocation looks like the following:
Each allocation is for only one sector at a time.
Note that all of these operations can be done in batch, but there is still per-sector overhead for each allocation and claim.
Goal
We want to change the process so that clients can create a single allocation for data that will span multiple sectors.
The primary goal is to reduce the workload/cost on the client (the second step mentioned in the above section). This proposal also enables to reduce the workload/cost on the SP as well by claiming multiple allocations at once but it is not required.
Proposal
We propose the client use a commitment to represent a set of Piece CIDs (CommPs) that the client wishes to put on Filecoin.
The client can then do a single allocation for this set of CommPs.
The SP can claim set of commPs either incrementally (one by one) or by batches.
A proposed workflow for the allocation is as follow:
Once that is done, the claims process works in the following way:
Commitment
We propose to use a simple commitment called KZG commitment. It is an algebraic commitment enabling to create a constant size proof of opening (80B).
These commitments are becoming more and more used, and library support is already present. For example, danksharding or the new state trie in Eth2 will be using KZG commitments all over the place.
Why KZG commitment ?
Constant size proofs is one major advantage, regardless of the number of allocation the SP is claiming, because it supports batch opening.
This is not the case with Merkle Tree for example.
Another reason is that having algebraic commitment in Filecoin opens the door to much better scalability and interoperability perspective. In particular, these commitment are cheaply aggregatable and verifiable.
Why not using a Merkle Tree?
A Merkle Tree would be cheaper on execution from the client perspective but it will be using more non indexed storage. In other word, the gas usage will be higher.
Gas Cost Reduction with current method
The following graph shows the reduction in gas cost between the current method and what it could be using the KZG batched method (raw spreadsheet)
One concrete number: between 34% and 50% gas reduction when doing 64 claims at once
Commitment Comparison:
This table shows an example for an opening proof representing 64 commP between using a Merkle Tree and a KZG commitment scheme:
As you can see, it’s a trade-off between onchain footprint and verification cost. We believe that for small sizes like this, onchain verification cost is still reasonable and bring the best trade-offs.
Gas Comparison This is a rough estimations of gas cost for both methods (Merkle Tree vs KZG) according to the number of openings one is doing (spreadsheet):
KZG is cheaper onchain as soon as one makes 20-32 batch openings.
This estimation is taking a pessismitic number for KZG. For example, the gas for KZG should hover around 10M, but this estimation takes it to 12M to account for unexpected costs.
Assumptions taken to compute the cost:
* Overall cost for syscall - 10gas/ns is the translation factor - 20k overhead per syscall - 0.6gas per byte - Overall cost for storage - 1300 gas / byte (non indexed storage), 3400 / byte indexed - KZG cost (syscall): approx 10M - pairing 1ms computation → 10M gas - scalar mul 373microseconds → 373k gas - KZG takes 48 bytes proofs + indices + values - X * 32 * 2 * 0.6, 2k for 64 opening - KZG Cost storage: 48B - Merkle Tree cost for 1 opening: - 320B * 1300 = 416k - Merkle Tree cost for 64 opening: - 320*64*1300 = 26M - NOT taking into account the storage of the actual comP values and indices, since that is the same in both caseImplementation
A KZG commitment would require a precompile to cheaply verify it onchain. This precompile would use blst as the backend which already provides many of the building block to verify kzg commitment (+ many other libraries building on DankSharding on Eth2 are popping up with their KZG implementation). More work is needed to explore the space of libraries and decide if we want to integrate or use our own implementation (a whole impl. fits in < 500 lines).
Note that we could also decide to use another curve, bn254, which is faster than bls12-381 and more importantly, is available on any EVM chains ! However, this curve have less implementations out there.
Discussion
Checking commitment between client and SP
There is an alterntive process we describe here for completeness which essentially make sure the client and SP agree on C offchain first.
Because the client and SP have an incentive to work together, it might be better to make them check the commitment C off-chain first. This is up for discussion.
Interoperability with other chains
Because this proposal does not use any specific encoding (IPLD etc), a client can create his commitment on another chain or IPC subnets, as long as the precompile is enabled there.
Given we are “creating a new state” in some sort, the ability to use KZG commitment scheme (with known curves) would allow us to use it and refer to it in a different context than Filecoin. For example, it would be “possible” to create these commitments on any Ethereum-related chains (when this EIP is included or if we use BN254, already available today).
Different Poreps
In the case Porep changes, this proposal would still be compatible as it does not interpret the commP in anyway (i.e. we could change it to using blake3 for example).
If the size of the sector changes, for example with smaller sector sizes, this proposal can work as well on a larger set of commPs (e.g. pass from 1024 commP to 2048 smaller commP). In sector sizes grow larger, this proposal would work on a smaller set of commPs (e.g. pass from 1024 to 512 set size of commP).
Thanks to @Kubuxu for the initial idea and long discussions and @anorth for feedback and reviews!.
Beta Was this translation helpful? Give feedback.
All reactions