6

What is the consequence if I implement MaxEncodedLen lower than the actual max length of the type? Will the bytes which are above the length just not be written to storage?

1 Answer 1

4

MaxEncodedLen is used for weight estimation, so the problem you face here will be the same as if you "under-weigh" your extrinsics.

When producing a block, the weight stuff ensures that your block is not "too big". If you put a MaxEncodedLen smaller than the actual encoded length, you may produce blocks which are bigger than allowed, and thus will be rejected by the Relay Chain. If these blocks can be generated by users, then a user could attack your network by filling your chain full of under-length extrinsics, and basically force all the nodes on your network to waste a bunch of computation building blocks which are invalid.

Will the bytes which are above the length just not be written to storage?

No, the storage will still be written, and we don't check MaxEncodedLen when writing to storage. For some types like BoundedVec, there is special decoding logic which will return an error decoding storage where the vector is bigger than the expected bound, but this is programmed specifically for this type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.