paritytech / polkadot-sdk

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

[pallet-revive] immutable data storage #5861

Closed xermicus closed 1 month ago

xermicus commented 1 month ago

This PR introduces the concept of immutable storage data, used for Solidity immutable variables.

This is a minimal implementation. Immutable data is attached to a contract; to keep ContractInfo fixed in size, we only store the length there, and store the immutable data in a dedicated storage map instead. Which comes at the cost of requiring an additional storage read (costly) for contracts using this feature.

We discussed more optimal solutions not requiring any additional storage accesses internally, but they turned out to be non-trivial to implement. Another optimization benefiting multiple calls to the same contract in a single call stack would be to cache the immutable data in Stack. However, this potential creates a DOS vulnerability (the attack vector is to call into as many contracts in a single stack as possible, where they all have maximum immutable data to fill the cache as efficiently as possible). So this either has to be guaranteed to be a non-issue by limits, or, more likely, to have some logic to bound the cache. Eventually, we should think about introducing the concept of warm and cold storage reads (akin to EVM). Since immutable variables are commonly used in contracts, this change is blocking our initial launch and we should only optimize it properly in follow-ups.

This PR also disables the set_code_hash API (which isn't usable for Solidity contracts without pre-compiles anyways). With immutable storage attached to contracts, we now want to run the constructor of the new code hash to collect the immutable data during set_code_hash. This will be implemented in a follow up PR.

xermicus commented 1 month ago

bot fmt

command-bot[bot] commented 1 month ago

@xermicus https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7457393 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 3-00b383a4-2df6-4f13-884d-24631d5a4793 to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 month ago

@xermicus Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7457393 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7457393/artifacts/download.

xermicus commented 1 month ago

bot fmt

command-bot[bot] commented 1 month ago

@xermicus https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7494314 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 12-0aadee30-72f5-4b03-bfcf-f143be07c04f to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 month ago

@xermicus Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7494314 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7494314/artifacts/download.

xermicus commented 1 month ago

Your editor seems to be adding ; to return statements. It adds some noise and rustfmt doesn't seem to care. Can you disable?

Yeah I reverted them to remove the noise. The formatter just gets invoked on save - I guess those were a recent addition and the CI hasn't updated the toolchain for a while

xermicus commented 1 month ago

/cmd --help

github-actions[bot] commented 1 month ago
Command help: ``` usage: /cmd [--help] [--continue-on-fail] [--quiet] [--clean] [--image IMAGE] {bench,fmt,update-ui,prdoc} ... A command runner for polkadot-sdk repo positional arguments: {bench,fmt,update-ui,prdoc} a command to run bench Runs benchmarks fmt Formats code (cargo +nightly-VERSION fmt) and configs (taplo format) update-ui Updates UI tests prdoc Generates PR documentation options: --help help for help if you need some help --continue-on-fail Won't exit(1) on failed command and continue with next steps. --quiet Won't print start/end/failed messages in PR --clean Clean up the previous bot's & author's comments in PR --image IMAGE Override docker image '--image docker.io/paritytech/ci-unified:latest' ### Command 'bench' usage: /cmd bench [-h] [--continue-on-fail] [--quiet] [--clean] [--image IMAGE] [--runtime [{dev,westend,rococo,asset-hub-westend,asset-hub-rococo,bridge-hub-rococo,bridge-hub-westend,collectives-westend,contracts-rococo,coretime-rococo,coretime-westend,glutton-westend,people-rococo,people-westend} ...]] [--pallet [PALLET ...]] options: -h, --help show this help message and exit --continue-on-fail Won't exit(1) on failed command and continue with next steps. --quiet Won't print start/end/failed messages in PR --clean Clean up the previous bot's & author's comments in PR --image IMAGE Override docker image '--image docker.io/paritytech/ci-unified:latest' --runtime [{dev,westend,rococo,asset-hub-westend,asset-hub-rococo,bridge-hub-rococo,bridge-hub-westend,collectives-westend,contracts-rococo,coretime-rococo,coretime-westend,glutton-westend,people-rococo,people-westend} ...] Runtime(s) space separated --pallet [PALLET ...] Pallet(s) space separated **Examples**: Runs all benchmarks /cmd bench Runs benchmarks for pallet_balances and pallet_multisig for all runtimes which have these pallets. **--quiet** makes it to output nothing to PR but reactions /cmd bench --pallet pallet_balances pallet_xcm_benchmarks::generic --quiet Runs bench for all pallets for westend runtime and continues even if some benchmarks fail /cmd bench --runtime westend --continue-on-fail Does not output anything and cleans up the previous bot's & author command triggering comments in PR /cmd bench --runtime westend rococo --pallet pallet_balances pallet_multisig --quiet --clean ### Command 'fmt' usage: /cmd fmt [-h] [--continue-on-fail] [--quiet] [--clean] [--image IMAGE] options: -h, --help show this help message and exit --continue-on-fail Won't exit(1) on failed command and continue with next steps. --quiet Won't print start/end/failed messages in PR --clean Clean up the previous bot's & author's comments in PR --image IMAGE Override docker image '--image docker.io/paritytech/ci- unified:latest' ### Command 'update-ui' usage: /cmd update-ui [-h] [--continue-on-fail] [--quiet] [--clean] [--image IMAGE] options: -h, --help show this help message and exit --continue-on-fail Won't exit(1) on failed command and continue with next steps. --quiet Won't print start/end/failed messages in PR --clean Clean up the previous bot's & author's comments in PR --image IMAGE Override docker image '--image docker.io/paritytech/ci- unified:latest' ### Command 'prdoc' usage: /cmd prdoc [-h] --pr PR [--audience AUDIENCE] [--bump BUMP] [--force FORCE] options: -h, --help show this help message and exit --pr PR The PR number to generate the PrDoc for. --audience AUDIENCE The audience of whom the changes may concern. --bump BUMP A default bump level for all crates. --force FORCE Whether to overwrite any existing PrDoc. ```
athei commented 1 month ago

The /cmd benchmarks do not work, yet. Cause it uses the omni bencher. Use the bench bot for now like this: https://github.com/paritytech/polkadot-sdk/pull/5845#issuecomment-2387186013

xermicus commented 1 month ago

bot bench substrate-pallet --pallet=pallet_revive

command-bot[bot] commented 1 month ago

@xermicus https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7507078 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --features=riscv --pallet=pallet_revive. Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 14-da218fe6-fbe0-4ff0-a3cc-45b201e6d2f7 to cancel this command or bot cancel to cancel all commands in this pull request.

xermicus commented 1 month ago

The /cmd benchmarks do not work, yet. Cause it uses the omni bencher. Use the bench bot for now like this: #5845 (comment)

Ah, was unsure of the status, thanks!

xermicus commented 1 month ago

bot fmt

command-bot[bot] commented 1 month ago

@xermicus https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7507172 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 15-3dc65ad4-f628-47a7-bc82-81af52413e55 to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 month ago

@xermicus Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7507172 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7507172/artifacts/download.

xermicus commented 1 month ago

bot bench substrate-pallet --pallet=pallet_revive

command-bot[bot] commented 1 month ago

@xermicus https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7507745 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --features=riscv --pallet=pallet_revive. Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 16-27b31215-eab9-4429-b2ae-e96fe080a203 to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 month ago

@xermicus Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --features=riscv --pallet=pallet_revive has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7507078 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7507078/artifacts/download.

xermicus commented 1 month ago

bot bench substrate-pallet --pallet=pallet_revive

command-bot[bot] commented 1 month ago

@xermicus https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7508035 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --features=riscv --pallet=pallet_revive. Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 17-5dece634-fb55-44a2-b477-897c58349b96 to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 month ago

@xermicus Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --features=riscv --pallet=pallet_revive has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7507745 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7507745/artifacts/download.

xermicus commented 1 month ago

bot fmt

command-bot[bot] commented 1 month ago

@xermicus https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7508500 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 18-21acba8f-a66a-4c54-92b2-f2a8479866bf to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 month ago

@xermicus Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7508500 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7508500/artifacts/download.

xermicus commented 1 month ago

bot bench substrate-pallet --pallet=pallet_revive

command-bot[bot] commented 1 month ago

@xermicus https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7508687 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --features=riscv --pallet=pallet_revive. Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 19-50a5cc30-d1c8-42cf-9b44-b433235831ab to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 month ago

@xermicus Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --features=riscv --pallet=pallet_revive has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7508035 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7508035/artifacts/download.

command-bot[bot] commented 1 month ago

@xermicus Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --features=riscv --pallet=pallet_revive has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7508687 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7508687/artifacts/download.