paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.network/
1.8k stars 652 forks source link

Add immutables to contract metadata #5611

Open xermicus opened 3 weeks ago

xermicus commented 3 weeks ago

In YUL there are two opcodes to load and store immutables. Immutables are indexed so we can store them just as a byte array. Storing is only allowed in the constructor (in EVM they are constants in the runtime code). We'd instead store them tied to the contract before returning from the constructor; the contract can then load them lazily on the first access. Delegate calls prevent us from storing them in regular contract storage.

To make it work for upgradable contracts using set_code_hash we must require that the new code was uploaded and instantiated, otherwise the immutables are missing.