paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.com/
1.89k stars 696 forks source link

Limit the amount of memory a contract can use #5725

Open athei opened 2 months ago

athei commented 2 months ago

So far we only limit the size of the contract blob. However, the contract can declare static memory that is not included in the blob (zero initialized sections). The contract can also use sbrk to allocate more memory dynamically.

We need to limit both of those angles to make sure a contract can't drive the runtime oom.

Because the way how memory allocation will change in the future within PolkaVM we will go for this approach

### Tasks
- [ ] https://github.com/paritytech/polkadot-sdk/pull/5726
- [ ] https://github.com/koute/polkavm/issues/167

cc @koute We need a config knob in PolkaVM to disable sbrk. Trapping on this instruction should be fine.