0xPolygonMiden/miden-base

Implement `estimate_size` for individual deltas

Closed this issue · 5 comments

From @bobbinth:

Ideally, we don't care about limits on individual deltas as long as the whole account delta is within some reasonable limit. One approach could be to remove all individual delta limits and have something like estimate_size() on each individual delta. Then we can estimate the size of the whole account delta and impose a limit on that.

Notes from the call 23rd September:

This issue concerns computing the size of the AccountDelta in a serialized state. Then, we put a limit in place.

Here is where we serialize the AccountDelta

impl Serializable for AccountUpdateDetails {

Just quickly writing down my plan for this for tomorrow.

I would implement fn get_size_hint(&self) -> usize) on the Serializable trait impl for the AccountDelta and recursively for any contained type. I think that makes the most sense. If not, a dedicated size function with the same approach.

And then the limit needs to be defined somewhere. I guess there is a config somewhere where this would fit in, which I'll try to find, otherwise a constant.

I'm not sure where the best place is to enforce the limit though, any pointers are appreciated :)

@PhilippGackstatter we already have get_size_hint method in Serializable (default implementation returns zero), so I think implementing it would be the best solution. We define limits in constants module of miden-objects. And we can check the limits in validate method of AccountDelta (we had such method before, but removed it once we had removed all validations from it, but now it's high time to return it back).

I guess one question is what the limit should be. I don't have a good way to arrive at that yet (and not sure if other projects enforce anything like this) - but it probably should be something between 1KB and 100KB. Maybe we go with something like 32KB - but I'm open to other suggestions.

Closed by #895.