Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pallet-revive] immutable data storage #5861

Merged
merged 42 commits into from
Oct 5, 2024
Merged

[pallet-revive] immutable data storage #5861

merged 42 commits into from
Oct 5, 2024

Conversation

xermicus
Copy link
Member

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 and others added 16 commits September 25, 2024 19:09
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: xermicus <cyrill@parity.io>
@xermicus xermicus added R0-silent Changes should not be mentioned in any release notes T7-smart_contracts This PR/Issue is related to smart contracts. labels Sep 27, 2024
Signed-off-by: xermicus <cyrill@parity.io>
@xermicus
Copy link
Member Author

bot fmt

@command-bot
Copy link

command-bot bot commented Sep 27, 2024

@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
Copy link

command-bot bot commented Sep 27, 2024

@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.

Copy link
Member

@athei athei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

substrate/frame/revive/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/revive/src/storage.rs Outdated Show resolved Hide resolved
substrate/frame/revive/uapi/src/host/riscv32.rs Outdated Show resolved Hide resolved
substrate/frame/revive/src/exec.rs Show resolved Hide resolved
substrate/frame/revive/src/storage.rs Outdated Show resolved Hide resolved
substrate/frame/revive/src/storage.rs Outdated Show resolved Hide resolved
substrate/frame/revive/src/wasm/runtime.rs Outdated Show resolved Hide resolved
substrate/frame/revive/src/tests.rs Show resolved Hide resolved
xermicus and others added 2 commits October 3, 2024 07:35
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
@command-bot
Copy link

command-bot bot commented Oct 4, 2024

@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.

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
@xermicus
Copy link
Member Author

xermicus commented Oct 4, 2024

bot fmt

@command-bot
Copy link

command-bot bot commented Oct 4, 2024

@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
Copy link

command-bot bot commented Oct 4, 2024

@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
Copy link
Member Author

xermicus commented Oct 4, 2024

bot bench substrate-pallet --pallet=pallet_revive

@command-bot
Copy link

command-bot bot commented Oct 4, 2024

@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.

…=dev --target_dir=substrate --features=riscv --pallet=pallet_revive
@command-bot
Copy link

command-bot bot commented Oct 4, 2024

@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.

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
@command-bot
Copy link

command-bot bot commented Oct 4, 2024

@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.

@xermicus xermicus added this pull request to the merge queue Oct 4, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 4, 2024
@xermicus xermicus added this pull request to the merge queue Oct 5, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 5, 2024
@xermicus xermicus added this pull request to the merge queue Oct 5, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 5, 2024
@xermicus xermicus added this pull request to the merge queue Oct 5, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 5, 2024
@xermicus xermicus added this pull request to the merge queue Oct 5, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 5, 2024
@xermicus xermicus added this pull request to the merge queue Oct 5, 2024
Merged via the queue into master with commit a8ebe9a Oct 5, 2024
206 checks passed
@xermicus xermicus deleted the cl/immutables branch October 5, 2024 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes T7-smart_contracts This PR/Issue is related to smart contracts.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants