-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
We should maximize uploaded metadata size #63
Comments
Should also sanitize all inputs on-chain if possible. E.g. padded |
Generic data vs sanity checksThere's a trade-off here that needs thought:
The easiest way to be as generic as possible when it comes to on-chain stored data is uploading everything encoded as a byte vector If we allow updating structured data, it is first encoded when submitting the transaction, then it is decoded in the pallet, introducing a potentially expensive "deserialization" step on-chain. On the flip side, we gain the ability to perform sanity checks on the uploaded data (checking for duplicates, asserting the number of roles in a guild do not exceed the allowed max, etc). The other problem with this approach is that the uploaded data may contain a vector of different types that have a common trait implemented:
where the Maybe we could utilize |
Another important aspect to take into account is #43 because if we store only serialized guild metadata on-chain, it would be very painful to implement functions that allow guild owners to update roles. Alternatively, if we store data in a structured way, allowing small updates by guild owners would be easier and we could add more sanity checks. |
Add as much structure as possible and serialize individual requirements only, which can be submitted in an
We should also add an |
Add |
Intermezzo on storageStoring stuff on-chain, under consensus is not very effective and may incur large costs on the runtime. Thankfully, substrate has the option to consistently store large amounts of data in the offchain local storage of the nodes using offchain indexing. The great thing about offchain indexing is that the runtime can write transaction data to the local storage without invoking any offchain worker. It is ensured that off-chain data is consistent among nodes running with the Implementing this requires a bit of thought, because off-chain storage only allows writing to it and clearing data. Thus, the runtime cannot read from the off-chain storage. Furthermore, writing to the off-chain storage from runtime is only available through a limited api, i.e. setting a key-value pair. Intermezzo on requirement typesStatic requirements
This distinction would allow the following requirement setups:
Dynamic requirementsAs for dynamic requirements, they have the following structure:
A
Thus, a dynamic requirement is satisfied if the respective Allowlists in storageAllowlists are special in the sense that their size can be much larger than other requirements, because they may contain 50k+ addresses which (if we consider a 20 byte Ethereum address) results in data in the size of Megabytes. It is important that the Wasm runtime has an upper limit of 32 MB for allocated memory. After testing the runtime, it accepted 100k entries in an allowlist, but rejected one with 200k entries. Nevertheless, if we can at least store allowlists in the off-chain storage as a merkle tree and store only it's hash on-chain, we wouldn't have to worry about bloating consensus data. However, on-chain allowlist-verification would be impossible (because the runtime cannot read from the off-chain storage) and modifying the allowlist would be tricky. If we store a merkle root of an allowlist merkle tree, however, we could ask for a merkle proof provided by the user and maybe verify that on-chain using the merkle root only. |
Description
In order to avoid uploading large datasets (maliciously) we should sanitize the input size of dynamic types (vectors). Even though we can limit the number of requirements/identities in the frontend, anybody can send transactions from a custom cli client, thus sending extremely long binary vectors when invoking create guild, etc.
Solution
Maybe it would be a good idea to serialize stuff on-chain instead of sending already serialized data. That way we can set and check against an upper bound of requirements/identities on-chain.
The text was updated successfully, but these errors were encountered: